Remove support in configure for unsupported architectures
[glibc.git] / sysdeps / ia64 / bits / byteswap.h
blob29d0e37d12a4331dfa43a0bfa6b9caf6bb5b4799
1 /* Macros to swap the order of bytes in integer values.
2 Copyright (C) 1997,1998,2000,2002,2003,2008,2011
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #if !defined _BYTESWAP_H && !defined _NETINET_IN_H && !defined _ENDIAN_H
22 # error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
23 #endif
25 #ifndef _BITS_BYTESWAP_H
26 #define _BITS_BYTESWAP_H 1
28 /* Swap bytes in 16 bit value. */
29 #define __bswap_constant_16(x) \
30 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
32 #if defined __GNUC__ && __GNUC__ >= 2
33 # define __bswap_16(x) \
34 (__extension__ \
35 ({ register unsigned short int __v, __x = (x); \
36 if (__builtin_constant_p (x)) \
37 __v = __bswap_constant_16 (__x); \
38 else \
39 __asm__ __volatile__ ("shl %0 = %1, 48 ;;" \
40 "mux1 %0 = %0, @rev ;;" \
41 : "=r" (__v) \
42 : "r" ((unsigned short int) (__x))); \
43 __v; }))
44 #else
45 /* This is better than nothing. */
46 static __inline unsigned short int
47 __bswap_16 (unsigned short int __bsx)
49 return __bswap_constant_16 (__bsx);
51 #endif
54 /* Swap bytes in 32 bit value. */
55 #define __bswap_constant_32(x) \
56 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
57 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
59 #if defined __GNUC__ && __GNUC__ >= 2
60 # define __bswap_32(x) \
61 (__extension__ \
62 ({ register unsigned int __v, __x = (x); \
63 if (__builtin_constant_p (x)) \
64 __v = __bswap_constant_32 (__x); \
65 else \
66 __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \
67 "mux1 %0 = %0, @rev ;;" \
68 : "=r" (__v) \
69 : "r" ((unsigned int) (__x))); \
70 __v; }))
71 #else
72 static __inline unsigned int
73 __bswap_32 (unsigned int __bsx)
75 return __bswap_constant_32 (__bsx);
77 #endif
80 /* Swap bytes in 64 bit value. */
81 #if defined __GNUC__ && __GNUC__ >= 2
82 # define __bswap_constant_64(x) \
83 (__extension__ ((((x) & 0xff00000000000000ul) >> 56) \
84 | (((x) & 0x00ff000000000000ul) >> 40) \
85 | (((x) & 0x0000ff0000000000ul) >> 24) \
86 | (((x) & 0x000000ff00000000ul) >> 8) \
87 | (((x) & 0x00000000ff000000ul) << 8) \
88 | (((x) & 0x0000000000ff0000ul) << 24) \
89 | (((x) & 0x000000000000ff00ul) << 40) \
90 | (((x) & 0x00000000000000fful) << 56)))
92 # define __bswap_64(x) \
93 (__extension__ \
94 ({ register unsigned long int __v, __x = (x); \
95 if (__builtin_constant_p (x)) \
96 __v = __bswap_constant_64 (__x); \
97 else \
98 __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
99 : "=r" (__v) \
100 : "r" ((unsigned long int) (__x))); \
101 __v; }))
103 #else
104 # define __bswap_constant_64(x) \
105 ((((x) & 0xff00000000000000ul) >> 56) \
106 | (((x) & 0x00ff000000000000ul) >> 40) \
107 | (((x) & 0x0000ff0000000000ul) >> 24) \
108 | (((x) & 0x000000ff00000000ul) >> 8) \
109 | (((x) & 0x00000000ff000000ul) << 8) \
110 | (((x) & 0x0000000000ff0000ul) << 24) \
111 | (((x) & 0x000000000000ff00ul) << 40) \
112 | (((x) & 0x00000000000000fful) << 56))
114 static __inline unsigned long int
115 __bswap_64 (unsigned long int __bsx)
117 return __bswap_constant_64 (__bsx);
119 #endif
121 #endif /* _BITS_BYTESWAP_H */