30 #ifndef BYTE_ORDER_HXX
31 #define BYTE_ORDER_HXX
37 #if defined(__i386__) || defined(__x86_64__) || defined(__ARMEL__)
39 # define IS_LITTLE_ENDIAN true
40 # define IS_BIG_ENDIAN false
41 #elif defined(__MIPSEB__)
43 # define IS_LITTLE_ENDIAN false
44 # define IS_BIG_ENDIAN true
45 #elif defined(__APPLE__) || defined(__NetBSD__)
47 # include <machine/endian.h>
48 # if BYTE_ORDER == LITTLE_ENDIAN
49 # define IS_LITTLE_ENDIAN true
50 # define IS_BIG_ENDIAN false
52 # define IS_LITTLE_ENDIAN false
53 # define IS_BIG_ENDIAN true
55 #elif defined(__BYTE_ORDER__)
57 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
58 # define IS_LITTLE_ENDIAN true
59 # define IS_BIG_ENDIAN false
61 # define IS_LITTLE_ENDIAN false
62 # define IS_BIG_ENDIAN true
67 # if __BYTE_ORDER == __LITTLE_ENDIAN
68 # define IS_LITTLE_ENDIAN true
69 # define IS_BIG_ENDIAN false
71 # define IS_LITTLE_ENDIAN false
72 # define IS_BIG_ENDIAN true
76 static inline constexpr
bool
82 static inline constexpr
bool
88 static inline constexpr uint16_t
91 return (value >> 8) | (value << 8);
94 static inline constexpr uint32_t
97 return (value >> 24) | ((value >> 8) & 0x0000ff00) |
98 ((value << 8) & 0x00ff0000) | (value << 24);
101 static inline constexpr uint64_t
108 static inline constexpr uint16_t
111 #if CLANG_OR_GCC_VERSION(4,8)
112 return __builtin_bswap16(value);
118 static inline constexpr uint32_t
121 #if CLANG_OR_GCC_VERSION(4,3)
122 return __builtin_bswap32(value);
128 static inline constexpr uint64_t
131 #if CLANG_OR_GCC_VERSION(4,3)
132 return __builtin_bswap64(value);
141 static inline constexpr uint16_t
150 static inline constexpr uint32_t
159 static inline constexpr uint64_t
168 static inline constexpr uint16_t
177 static inline constexpr uint32_t
186 static inline constexpr uint64_t
195 static inline constexpr uint16_t
204 static inline constexpr uint32_t
213 static inline constexpr uint64_t
222 static inline constexpr uint16_t
231 static inline constexpr uint32_t
240 static inline constexpr uint64_t
static constexpr uint32_t GenericByteSwap32(uint32_t value)
static constexpr uint32_t ToBE32(uint32_t value)
Converts a 32bit value from the system's byte order to big endian.
static constexpr uint32_t FromLE32(uint32_t value)
Converts a 32bit value from little endian to the system's byte order.
static constexpr uint16_t ByteSwap16(uint16_t value)
static constexpr uint64_t FromLE64(uint64_t value)
Converts a 64bit value from little endian to the system's byte order.
static constexpr bool IsLittleEndian()
static constexpr uint16_t ToBE16(uint16_t value)
Converts a 16bit value from the system's byte order to big endian.
static constexpr uint32_t ToLE32(uint32_t value)
Converts a 32bit value from the system's byte order to little endian.
static constexpr uint16_t ToLE16(uint16_t value)
Converts a 16bit value from the system's byte order to little endian.
static constexpr uint32_t ByteSwap32(uint32_t value)
static constexpr uint64_t ToLE64(uint64_t value)
Converts a 64bit value from the system's byte order to little endian.
static constexpr uint64_t ToBE64(uint64_t value)
Converts a 64bit value from the system's byte order to big endian.
static constexpr uint64_t GenericByteSwap64(uint64_t value)
static constexpr bool IsBigEndian()
static constexpr uint16_t FromLE16(uint16_t value)
Converts a 16bit value from little endian to the system's byte order.
static constexpr uint16_t GenericByteSwap16(uint16_t value)
static constexpr uint16_t FromBE16(uint16_t value)
Converts a 16bit value from big endian to the system's byte order.
static constexpr uint32_t FromBE32(uint32_t value)
Converts a 32bit value from big endian to the system's byte order.
static constexpr uint64_t ByteSwap64(uint64_t value)
static constexpr uint64_t FromBE64(uint64_t value)
Converts a 64bit value from big endian to the system's byte order.