remove obstack support
[uclibc-ng.git] / utils / bswap.h
blob0047e4e9824dacb71a8da9802eb1440357607e9d
1 /*
2 * Lame bswap replacements as we can't assume the host is sane and provides
3 * working versions of these.
4 */
6 #ifndef _BSWAP_H
7 #define _BSWAP_H 1
9 #ifdef __linux__
10 # include <byteswap.h>
11 #else
13 static __inline__ uint16_t bswap_16(uint16_t x)
15 return ((((x) & 0xff00) >> 8) | \
16 (((x) & 0x00ff) << 8));
18 static __inline__ uint32_t bswap_32(uint32_t x)
20 return ((((x) & 0xff000000) >> 24) | \
21 (((x) & 0x00ff0000) >> 8) | \
22 (((x) & 0x0000ff00) << 8) | \
23 (((x) & 0x000000ff) << 24));
25 static __inline__ uint64_t bswap_64(uint64_t x)
27 #define _uswap_64(x, sfx) \
28 return ((((x) & 0xff00000000000000##sfx) >> 56) | \
29 (((x) & 0x00ff000000000000##sfx) >> 40) | \
30 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
31 (((x) & 0x000000ff00000000##sfx) >> 8) | \
32 (((x) & 0x00000000ff000000##sfx) << 8) | \
33 (((x) & 0x0000000000ff0000##sfx) << 24) | \
34 (((x) & 0x000000000000ff00##sfx) << 40) | \
35 (((x) & 0x00000000000000ff##sfx) << 56));
36 #if defined(__GNUC__)
37 _uswap_64(x, ull)
38 #else
39 _uswap_64(x, )
40 #endif
41 #undef _uswap_64
43 #endif
45 #endif