11 #define ENIGMA_HAVE_BUILTIN(x) __has_builtin(x)
13 #define ENIGMA_HAVE_BUILTIN(x) false
18 inline std::uint64_t
BSwap64(std::uint64_t host_int) {
19 #if defined(__GNUC__) || ENIGMA_HAVE_BUILTIN(__builtin_bswap64)
20 return __builtin_bswap64(host_int);
21 #elif defined(_MSC_VER)
22 return _byteswap_uint64(host_int);
24 return (((host_int & std::uint64_t{0xFF}) << 56) |
25 ((host_int & std::uint64_t{0xFF00}) << 40) |
26 ((host_int & std::uint64_t{0xFF0000}) << 24) |
27 ((host_int & std::uint64_t{0xFF000000}) << 8) |
28 ((host_int & std::uint64_t{0xFF00000000}) >> 8) |
29 ((host_int & std::uint64_t{0xFF0000000000}) >> 24) |
30 ((host_int & std::uint64_t{0xFF000000000000}) >> 40) |
31 ((host_int & std::uint64_t{0xFF00000000000000}) >> 56));
35 inline std::uint32_t
BSwap32(std::uint32_t host_int) {
36 #if defined(__GNUC__) || ENIGMA_HAVE_BUILTIN(__builtin_bswap32)
37 return __builtin_bswap32(host_int);
38 #elif defined(_MSC_VER)
39 return _byteswap_ulong(host_int);
41 return (((host_int & std::uint32_t{0xFF}) << 24) |
42 ((host_int & std::uint32_t{0xFF00}) << 8) |
43 ((host_int & std::uint32_t{0xFF0000}) >> 8) |
44 ((host_int & std::uint32_t{0xFF000000}) >> 24));
48 inline std::uint16_t
BSwap16(std::uint16_t host_int) {
49 #if defined(__GNUC__) || ENIGMA_HAVE_BUILTIN(__builtin_bswap16)
50 return __builtin_bswap16(host_int);
51 #elif defined(_MSC_VER)
52 return _byteswap_ushort(host_int);
54 return (((host_int & std::uint16_t{0xFF}) << 8) |
55 ((host_int & std::uint16_t{0xFF00}) >> 8));
59 namespace LittleEndian {
61 inline std::uint16_t
fromHost(std::uint16_t value) {
62 if (std::endian::native == std::endian::big) {
69 inline std::uint32_t
fromHost(std::uint32_t value) {
70 if (std::endian::native == std::endian::big) {
77 inline std::uint64_t
fromHost(std::uint64_t value) {
78 if (std::endian::native == std::endian::big) {
85 inline std::uint16_t
toHost(std::uint16_t value) {
86 if (std::endian::native == std::endian::big) {
93 inline std::uint32_t
toHost(std::uint32_t value) {
94 if (std::endian::native == std::endian::big) {
101 inline std::uint64_t
toHost(std::uint64_t value) {
102 if (std::endian::native == std::endian::big) {
112 namespace BigEndian {
114 inline std::uint16_t
fromHost(std::uint16_t value) {
115 if (std::endian::native == std::endian::big) {
120 if (std::endian::native == std::endian::big) {
127 inline std::uint32_t
fromHost(std::uint32_t value) {
128 if (std::endian::native == std::endian::big) {
135 inline std::uint64_t
fromHost(std::uint64_t value) {
136 if (std::endian::native == std::endian::big) {
143 inline std::uint16_t
toHost(std::uint16_t value) {
144 if (std::endian::native == std::endian::big) {
151 inline std::uint32_t
toHost(std::uint32_t value) {
152 if (std::endian::native == std::endian::big) {
159 inline std::uint64_t
toHost(std::uint64_t value) {
160 if (std::endian::native == std::endian::big) {
std::uint16_t toHost(std::uint16_t value)
std::uint16_t fromHost(std::uint16_t value)
std::uint16_t fromHost(std::uint16_t value)
std::uint16_t toHost(std::uint16_t value)
std::uint64_t BSwap64(std::uint64_t host_int)
std::uint32_t BSwap32(std::uint32_t host_int)
std::uint16_t BSwap16(std::uint16_t host_int)