14 # define LEGACY_REGS "=Q"
16 # define LEGACY_REGS "=q"
19 #if defined(ARCH_X86) || defined(ARCH_X86_64)
20 static inline uint16_t ByteSwap16(uint16_t x)
22 __asm("xchgb %b0,%h0" :
27 #define bswap_16(x) ByteSwap16(x)
29 static inline uint32_t ByteSwap32(uint32_t x)
35 __asm("xchgb %b0,%h0\n"
43 #define bswap_32(x) ByteSwap32(x)
45 static inline uint64_t ByteSwap64(uint64_t x)
53 register union { __extension__ uint64_t __ll;
54 uint32_t __l[2]; } __x;
56 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
57 "0"(bswap_32((uint32_t)x)),"1"(bswap_32((uint32_t)(x>>32))));
61 #define bswap_64(x) ByteSwap64(x)
63 #elif defined(ARCH_SH4)
65 static inline uint16_t ByteSwap16(uint16_t x) {
66 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
70 static inline uint32_t ByteSwap32(uint32_t x) {
79 #define bswap_16(x) ByteSwap16(x)
80 #define bswap_32(x) ByteSwap32(x)
82 static inline uint64_t ByteSwap64(uint64_t x)
91 r.l.h = bswap_32 (x>>32);
94 #define bswap_64(x) ByteSwap64(x)
98 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
101 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
102 #define bswap_32(x) \
103 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
104 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
106 static inline uint64_t ByteSwap64(uint64_t x)
113 r.l[0] = bswap_32 (w.l[1]);
114 r.l[1] = bswap_32 (w.l[0]);
117 #define bswap_64(x) ByteSwap64(x)
119 #endif /* !ARCH_X86 */
121 #endif /* !HAVE_BYTESWAP_H */
123 // be2me ... BigEndian to MachineEndian
124 // le2me ... LittleEndian to MachineEndian
126 #ifdef WORDS_BIGENDIAN
127 #define be2me_16(x) (x)
128 #define be2me_32(x) (x)
129 #define be2me_64(x) (x)
130 #define le2me_16(x) bswap_16(x)
131 #define le2me_32(x) bswap_32(x)
132 #define le2me_64(x) bswap_64(x)
134 #define be2me_16(x) bswap_16(x)
135 #define be2me_32(x) bswap_32(x)
136 #define be2me_64(x) bswap_64(x)
137 #define le2me_16(x) (x)
138 #define le2me_32(x) (x)
139 #define le2me_64(x) (x)
142 #endif /* __BSWAP_H__ */