00001
00023 #ifndef GALOIS_ENDIAN_H
00024 #define GALOIS_ENDIAN_H
00025
00026 #include "Galois/config.h"
00027 #include <stdint.h>
00028
00029 #define USE_NAIVE_BYTE_SWAP
00030
00031 #ifdef HAVE_ENDIAN_H
00032 # include <endian.h>
00033 #endif
00034
00035 namespace Galois {
00036
00037
00038
00039
00040 static inline uint64_t convert_le64(uint64_t x) {
00041 #if !defined(HAVE_BIG_ENDIAN)
00042 return x;
00043 #elif defined(USE_NAIVE_BYTE_SWAP) || !defined(HAVE_LE64TOH)
00044 return ((x<<56) & 0xFF00000000000000) |
00045 ((x<<40) & 0x00FF000000000000) |
00046 ((x<<24) & 0x0000FF0000000000) |
00047 ((x<<8 ) & 0x000000FF00000000) |
00048 ((x>>8 ) & 0x00000000FF000000) |
00049 ((x>>24) & 0x0000000000FF0000) |
00050 ((x>>40) & 0x000000000000FF00) |
00051 ((x>>56) & 0x00000000000000FF);
00052 #else
00053 return le64toh(x);
00054 #endif
00055 }
00056
00057 static inline uint32_t convert_le32(uint32_t x) {
00058 #if !defined(HAVE_BIG_ENDIAN)
00059 return x;
00060 #elif defined(USE_NAIVE_BYTE_SWAP) || !defined(HAVE_LE64TOH)
00061 return ((x<<24) & 0xFF000000) |
00062 ((x<<8 ) & 0x00FF0000) |
00063 ((x>>8 ) & 0x0000FF00) |
00064 ((x>>24) & 0x000000FF);
00065 #else
00066 return le32toh(x);
00067 #endif
00068 }
00069
00070 }
00071 #endif