14 # define LEGACY_REGS "=Q"
16 # define LEGACY_REGS "=q"
19 #if defined(ARCH_X86) || defined(ARCH_X86_64)
20 static always_inline
uint16_t bswap_16(uint16_t x
)
28 static always_inline
uint32_t bswap_32(uint32_t x
)
34 __asm("xchgb %b0,%h0\n"
43 static inline uint64_t bswap_64(uint64_t x
)
58 r
.l
.h
= bswap_32 (x
>>32);
63 #elif defined(ARCH_SH4)
65 static always_inline
uint16_t bswap_16(uint16_t x
) {
66 __asm__("swap.b %0,%0":"=r"(x
):"0"(x
));
70 static always_inline
uint32_t bswap_32(uint32_t x
) {
79 static inline uint64_t bswap_64(uint64_t x
)
88 r
.l
.h
= bswap_32 (x
>>32);
93 static always_inline
uint16_t bswap_16(uint16_t x
){
94 return (x
>>8) | (x
<<8);
98 static always_inline
uint32_t bswap_32(uint32_t x
){
101 "eor %1, %0, %0, ror #16 \n\t"
102 "bic %1, %1, #0xFF0000 \n\t"
103 "mov %0, %0, ror #8 \n\t"
104 "eor %0, %0, %1, lsr #8 \n\t"
109 static always_inline
uint32_t bswap_32(uint32_t x
){
110 x
= ((x
<<8)&0xFF00FF00) | ((x
>>8)&0x00FF00FF);
111 return (x
>>16) | (x
<<16);
115 static inline uint64_t bswap_64(uint64_t x
)
118 x
= ((x
<< 8)&0xFF00FF00FF00FF00ULL
) | ((x
>> 8)&0x00FF00FF00FF00FFULL
);
119 x
= ((x
<<16)&0xFFFF0000FFFF0000ULL
) | ((x
>>16)&0x0000FFFF0000FFFFULL
);
120 return (x
>>32) | (x
<<32);
127 r
.l
[0] = bswap_32 (w
.l
[1]);
128 r
.l
[1] = bswap_32 (w
.l
[0]);
132 #endif /* !ARCH_X86 */
134 #endif /* !HAVE_BYTESWAP_H */
136 // be2me ... BigEndian to MachineEndian
137 // le2me ... LittleEndian to MachineEndian
139 #ifdef WORDS_BIGENDIAN
140 #define be2me_16(x) (x)
141 #define be2me_32(x) (x)
142 #define be2me_64(x) (x)
143 #define le2me_16(x) bswap_16(x)
144 #define le2me_32(x) bswap_32(x)
145 #define le2me_64(x) bswap_64(x)
147 #define be2me_16(x) bswap_16(x)
148 #define be2me_32(x) bswap_32(x)
149 #define be2me_64(x) bswap_64(x)
150 #define le2me_16(x) (x)
151 #define le2me_32(x) (x)
152 #define le2me_64(x) (x)
155 #endif /* __BSWAP_H__ */