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
58 # if __BYTE_ORDER == __LITTLE_ENDIAN
59 # define IS_LITTLE_ENDIAN true
60 # define IS_BIG_ENDIAN false
62 # define IS_LITTLE_ENDIAN false
63 # define IS_BIG_ENDIAN true
67 static inline constexpr
bool
73 static inline constexpr
bool
79 static inline constexpr uint16_t
82 return (value >> 8) | (value << 8);
85 static inline constexpr uint32_t
88 return (value >> 24) | ((value >> 8) & 0x0000ff00) |
89 ((value << 8) & 0x00ff0000) | (value << 24);
92 static inline constexpr uint64_t
99 static inline constexpr uint16_t
102 #if CLANG_OR_GCC_VERSION(4,8)
103 return __builtin_bswap16(value);
109 static inline constexpr uint32_t
112 #if CLANG_OR_GCC_VERSION(4,3)
113 return __builtin_bswap32(value);
119 static inline constexpr uint64_t
122 #if CLANG_OR_GCC_VERSION(4,3)
123 return __builtin_bswap64(value);
132 static inline constexpr uint16_t
141 static inline constexpr uint32_t
150 static inline constexpr uint64_t
159 static inline constexpr uint16_t
168 static inline constexpr uint32_t
177 static inline constexpr uint64_t
186 static inline constexpr uint16_t
195 static inline constexpr uint32_t
204 static inline constexpr uint64_t
213 static inline constexpr uint16_t
222 static inline constexpr uint32_t
231 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.