20 #ifndef GALOIS_ENDIAN_H
21 #define GALOIS_ENDIAN_H
25 #include "galois/config.h"
29 static inline uint32_t bswap32(uint32_t x) {
30 #if defined(__GNUC__) || defined(__clang__)
31 return __builtin_bswap32(x);
33 return ((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) |
34 ((x >> 8) & 0x0000ff00) | ((x >> 24) & 0x000000ff);
38 static inline uint64_t bswap64(uint64_t x) {
39 #if defined(__GNUC__) || defined(__clang__)
40 return __builtin_bswap64(x);
42 return ((x << 56) & 0xff00000000000000UL) |
43 ((x << 40) & 0x00ff000000000000UL) |
44 ((x << 24) & 0x0000ff0000000000UL) |
45 ((x << 8) & 0x000000ff00000000UL) | ((x >> 8) & 0x00000000ff000000UL) |
46 ((x >> 24) & 0x0000000000ff0000UL) |
47 ((x >> 40) & 0x000000000000ff00UL) |
48 ((x >> 56) & 0x00000000000000ffUL);
55 static inline uint64_t convert_le64toh(uint64_t x) {
56 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
63 static inline uint32_t convert_le32toh(uint32_t x) {
64 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
71 static inline uint64_t convert_htobe64(uint64_t x) {
72 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
79 static inline uint32_t convert_htobe32(uint32_t x) {
80 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
87 static inline uint64_t convert_htole64(uint64_t x) {
88 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
95 static inline uint32_t convert_htole32(uint32_t x) {
96 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__