16 /* rockbox' optimised inline functions */
17 #define bswap_16(x) swap16(x)
18 #define bswap_32(x) swap32(x)
20 static inline uint64_t ByteSwap64(uint64_t x
)
29 r
.l
.h
= bswap_32 (x
>>32);
32 #define bswap_64(x) ByteSwap64(x)
34 #elif defined(ARCH_X86)
35 static inline unsigned short ByteSwap16(unsigned short x
)
37 __asm("xchgb %b0,%h0" :
42 #define bswap_16(x) ByteSwap16(x)
44 static inline unsigned int ByteSwap32(unsigned int x
)
50 __asm("xchgb %b0,%h0\n"
58 #define bswap_32(x) ByteSwap32(x)
60 static inline unsigned long long int ByteSwap64(unsigned long long int x
)
62 register union { __extension__
uint64_t __ll
;
63 uint32_t __l
[2]; } __x
;
65 "=r"(__x
.__l
[0]),"=r"(__x
.__l
[1]):
66 "0"(bswap_32((unsigned long)x
)),"1"(bswap_32((unsigned long)(x
>>32))));
69 #define bswap_64(x) ByteSwap64(x)
71 #elif defined(ARCH_SH4)
73 static inline uint16_t ByteSwap16(uint16_t x
) {
74 __asm__("swap.b %0,%0":"=r"(x
):"0"(x
));
78 static inline uint32_t ByteSwap32(uint32_t x
) {
87 #define bswap_16(x) ByteSwap16(x)
88 #define bswap_32(x) ByteSwap32(x)
90 static inline uint64_t ByteSwap64(uint64_t x
)
99 r
.l
.h
= bswap_32 (x
>>32);
102 #define bswap_64(x) ByteSwap64(x)
106 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
109 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
110 #define bswap_32(x) \
111 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
112 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
114 static inline uint64_t ByteSwap64(uint64_t x
)
121 r
.l
[0] = bswap_32 (w
.l
[1]);
122 r
.l
[1] = bswap_32 (w
.l
[0]);
125 #define bswap_64(x) ByteSwap64(x)
127 #endif /* !ARCH_X86 */
129 #endif /* !HAVE_BYTESWAP_H */
131 // be2me ... BigEndian to MachineEndian
132 // le2me ... LittleEndian to MachineEndian
134 #ifdef ROCKBOX_BIG_ENDIAN
135 #define be2me_16(x) (x)
136 #define be2me_32(x) (x)
137 #define be2me_64(x) (x)
138 #define le2me_16(x) bswap_16(x)
139 #define le2me_32(x) bswap_32(x)
140 #define le2me_64(x) bswap_64(x)
142 #define be2me_16(x) bswap_16(x)
143 #define be2me_32(x) bswap_32(x)
144 #define be2me_64(x) bswap_64(x)
145 #define le2me_16(x) (x)
146 #define le2me_32(x) (x)
147 #define le2me_64(x) (x)
150 #endif /* __BSWAP_H__ */