1
0
Fork 0

Better cross platform compatibility.

This commit is contained in:
ehofman 2005-09-21 09:43:32 +00:00
parent 7d0daddfcc
commit 278b7d7544

View file

@ -56,14 +56,16 @@ inline uint32_t bswap_32(unsigned int b) {
return x;
}
inline uint64_t bswap_64(unsigned long long b) {
#if __WORDSIZE == 64
#if (SIZEOF_LONG_INT == 8)
inline uint64_t bswap_64(unsigned long int b) {
uint64_t x = b;
x = ((x >> 8) & 0x00FF00FF00FF00FFLL) | ((x << 8) & 0xFF00FF00FF00FF00LL);
x = ((x >> 16) & 0x0000FFFF0000FFFFLL) | ((x << 16) & 0xFFFF0000FFFF0000LL);
x = (x >> 32) | (x << 32);
return x;
}
#else
inline uint64_t bswap_64(unsigned long long int b) {
union {
uint64_t ll;
uint32_t l[2];
@ -72,8 +74,8 @@ inline uint64_t bswap_64(unsigned long long b) {
r.l[0] = bswap_32 (w.l[1]);
r.l[1] = bswap_32 (w.l[0]);
return r.ll;
#endif
}
#endif
#if BYTE_ORDER == BIG_ENDIAN
# define SWAP32(arg) arg