1 #ifndef _COMPAT_BSWAP_H_
2 #define _COMPAT_BSWAP_H_
5 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
6 #define __HAS_BUILTIN_BSWAP16
8 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
9 #define __HAS_BUILTIN_BSWAP32
10 #define __HAS_BUILTIN_BSWAP64
14 #if defined(__clang__)
15 #if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 2))
16 #define __HAS_BUILTIN_BSWAP16
18 #if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 0))
19 #define __HAS_BUILTIN_BSWAP32
20 #define __HAS_BUILTIN_BSWAP64
24 #ifdef __HAS_BUILTIN_BSWAP16
25 #define bswap16(x) __builtin_bswap16(x)
28 static inline uint16_t bswap16(uint16_t x
)
30 return x
<< 8 | x
>> 8;
34 #ifdef __HAS_BUILTIN_BSWAP32
35 #define bswap32(x) __builtin_bswap32(x)
38 static inline uint32_t bswap32(uint32_t x
)
40 return x
>> 24 | (x
>> 8 & 0xff00) | (x
<< 8 & 0xff0000) | x
<< 24;
44 #ifdef __HAS_BUILTIN_BSWAP64
45 #define bswap64(x) __builtin_bswap64(x)
48 static inline uint64_t bswap64(uint64_t x
)
50 return ((uint64_t)bswap32(x
)) << 32 | bswap32(x
>> 32);