14
static inline unsigned short ByteSwap16(unsigned short x)
16
__asm("xchgb %b0,%h0" :
21
#define bswap_16(x) ByteSwap16(x)
23
static inline unsigned int ByteSwap32(unsigned int x)
29
__asm("xchgb %b0,%h0\n"
37
#define bswap_32(x) ByteSwap32(x)
39
static inline unsigned long long int ByteSwap64(unsigned long long int x)
41
register union { __extension__ uint64_t __ll;
42
uint32_t __l[2]; } __x;
44
"=r"(__x.__l[0]),"=r"(__x.__l[1]):
45
"0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
48
#define bswap_64(x) ByteSwap64(x)
50
#elif defined(ARCH_SH4)
52
static inline uint16_t ByteSwap16(uint16_t x) {
53
__asm__("swap.b %0,%0":"=r"(x):"0"(x));
57
static inline uint32_t ByteSwap32(uint32_t x) {
66
#define bswap_16(x) ByteSwap16(x)
67
#define bswap_32(x) ByteSwap32(x)
69
static inline uint64_t ByteSwap64(uint64_t x)
78
r.l.h = bswap_32 (x>>32);
81
#define bswap_64(x) ByteSwap64(x)
85
#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
88
// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
90
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
91
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
93
static inline uint64_t ByteSwap64(uint64_t x)
100
r.l[0] = bswap_32 (w.l[1]);
101
r.l[1] = bswap_32 (w.l[0]);
104
#define bswap_64(x) ByteSwap64(x)
106
#endif /* !ARCH_X86 */
108
#endif /* !HAVE_BYTESWAP_H */
110
// be2me ... BigEndian to MachineEndian
111
// le2me ... LittleEndian to MachineEndian
113
#ifdef WORDS_BIGENDIAN
114
#define be2me_16(x) (x)
115
#define be2me_32(x) (x)
116
#define be2me_64(x) (x)
117
#define le2me_16(x) bswap_16(x)
118
#define le2me_32(x) bswap_32(x)
119
#define le2me_64(x) bswap_64(x)
121
#define be2me_16(x) bswap_16(x)
122
#define be2me_32(x) bswap_32(x)
123
#define be2me_64(x) bswap_64(x)
124
#define le2me_16(x) (x)
125
#define le2me_32(x) (x)
126
#define le2me_64(x) (x)
129
#endif /* __BSWAP_H__ */