11 # define LEGACY_REGS "=Q"
13 # define LEGACY_REGS "=q"
16 #if defined(ARCH_X86) || defined(ARCH_X86_64)
17 static inline uint16_t ByteSwap16(uint16_t x
)
19 __asm("xchgb %b0,%h0" :
24 #define bswap_16(x) ByteSwap16(x)
26 static inline uint32_t ByteSwap32(uint32_t x
)
32 __asm("xchgb %b0,%h0\n"
40 #define bswap_32(x) ByteSwap32(x)
42 static inline uint64_t ByteSwap64(uint64_t x
)
50 register union { __extension__
uint64_t __ll
;
51 uint32_t __l
[2]; } __x
;
53 "=r"(__x
.__l
[0]),"=r"(__x
.__l
[1]):
54 "0"(bswap_32((unsigned long)x
)),"1"(bswap_32((unsigned long)(x
>>32))));
58 #define bswap_64(x) ByteSwap64(x)
60 #elif defined(ARCH_SH4)
62 static inline uint16_t ByteSwap16(uint16_t x
) {
63 __asm__("swap.b %0,%0":"=r"(x
):"0"(x
));
67 static inline uint32_t ByteSwap32(uint32_t x
) {
76 #define bswap_16(x) ByteSwap16(x)
77 #define bswap_32(x) ByteSwap32(x)
79 static inline uint64_t ByteSwap64(uint64_t x
)
88 r
.l
.h
= bswap_32 (x
>>32);
91 #define bswap_64(x) ByteSwap64(x)
95 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
98 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
100 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
101 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
103 static inline uint64_t ByteSwap64(uint64_t x
)
110 r
.l
[0] = bswap_32 (w
.l
[1]);
111 r
.l
[1] = bswap_32 (w
.l
[0]);
114 #define bswap_64(x) ByteSwap64(x)
116 #endif /* !ARCH_X86 */
118 #endif /* !HAVE_BYTESWAP_H */
120 static inline float bswap_flt(float x
) {
121 union {uint32_t i
; float f
;} u
;
127 static inline double bswap_dbl(double x
) {
128 union {uint64_t i
; double d
;} u
;
134 static inline long double bswap_ldbl(long double x
) {
135 union {char d
[10]; long double ld
;} uin
;
136 union {char d
[10]; long double ld
;} uout
;
138 uout
.d
[0] = uin
.d
[9];
139 uout
.d
[1] = uin
.d
[8];
140 uout
.d
[2] = uin
.d
[7];
141 uout
.d
[3] = uin
.d
[6];
142 uout
.d
[4] = uin
.d
[5];
143 uout
.d
[5] = uin
.d
[4];
144 uout
.d
[6] = uin
.d
[3];
145 uout
.d
[7] = uin
.d
[2];
146 uout
.d
[8] = uin
.d
[1];
147 uout
.d
[9] = uin
.d
[0];
151 // be2me ... BigEndian to MachineEndian
152 // le2me ... LittleEndian to MachineEndian
154 #ifdef WORDS_BIGENDIAN
155 #define be2me_16(x) (x)
156 #define be2me_32(x) (x)
157 #define be2me_64(x) (x)
158 #define le2me_16(x) bswap_16(x)
159 #define le2me_32(x) bswap_32(x)
160 #define le2me_64(x) bswap_64(x)
161 #define be2me_flt(x) (x)
162 #define be2me_dbl(x) (x)
163 #define be2me_ldbl(x) (x)
164 #define le2me_flt(x) bswap_flt(x)
165 #define le2me_dbl(x) bswap_dbl(x)
166 #define le2me_ldbl(x) bswap_ldbl(x)
168 #define be2me_16(x) bswap_16(x)
169 #define be2me_32(x) bswap_32(x)
170 #define be2me_64(x) bswap_64(x)
171 #define le2me_16(x) (x)
172 #define le2me_32(x) (x)
173 #define le2me_64(x) (x)
174 #define be2me_flt(x) bswap_flt(x)
175 #define be2me_dbl(x) bswap_dbl(x)
176 #define be2me_ldbl(x) bswap_ldbl(x)
177 #define le2me_flt(x) (x)
178 #define le2me_dbl(x) (x)
179 #define le2me_ldbl(x) (x)
182 #endif /* __BSWAP_H__ */