diff --git a/c/dtypes.h b/c/dtypes.h index 6d81908..f8fb701 100644 --- a/c/dtypes.h +++ b/c/dtypes.h @@ -60,33 +60,6 @@ #define DLLEXPORT __attribute__((visibility("default"))) #endif -#if defined(LINUX) -#include -#include -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER -#elif defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) -#include -#define __LITTLE_ENDIAN LITTLE_ENDIAN -#define __BIG_ENDIAN BIG_ENDIAN -#define __PDP_ENDIAN PDP_ENDIAN -#define __BYTE_ORDER BYTE_ORDER -#elif defined(WIN32) -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 -#define __BYTE_ORDER __LITTLE_ENDIAN -#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER -#else -#error "unknown platform" -#endif - #define LLT_ALLOC(n) malloc(n) #define LLT_REALLOC(p, n) realloc((p), (n)) #define LLT_FREE(x) free(x) diff --git a/c/flisp.c b/c/flisp.c index 474b1ed..f46c2c6 100644 --- a/c/flisp.c +++ b/c/flisp.c @@ -924,18 +924,21 @@ no_kw: return nargs; } -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define GET_INT32(a) \ ((int32_t)((((int32_t)a[0]) << 0) | (((int32_t)a[1]) << 8) | \ (((int32_t)a[2]) << 16) | (((int32_t)a[3]) << 24))) #define GET_INT16(a) \ ((int16_t)((((int16_t)a[0]) << 0) | (((int16_t)a[1]) << 8))) #define PUT_INT32(a, i) (*(int32_t *)(a) = bswap_32((int32_t)(i))) -#else +#endif + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define GET_INT32(a) (*(int32_t *)a) #define GET_INT16(a) (*(int16_t *)a) #define PUT_INT32(a, i) (*(int32_t *)(a) = (int32_t)(i)) #endif + #define SWAP_INT32(a) (*(int32_t *)(a) = bswap_32(*(int32_t *)(a))) #define SWAP_INT16(a) (*(int16_t *)(a) = bswap_16(*(int16_t *)(a))) @@ -2243,7 +2246,7 @@ static value_t fl_function(value_t *args, uint32_t nargs) for (i = 0; i < sz; i++) data[i] -= 48; } else { -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ swap = 1; #endif } diff --git a/c/hashing.c b/c/hashing.c index 0511256..f8ad26b 100644 --- a/c/hashing.c +++ b/c/hashing.c @@ -2,18 +2,6 @@ Hashing */ -#ifndef WIN32 -#include /* attempt to define endianness */ -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -#endif - -#ifdef LINUX -#include /* attempt to define endianness */ -#endif - #include #include #include diff --git a/c/ieee754.h b/c/ieee754.h index 2d9be50..67275bb 100644 --- a/c/ieee754.h +++ b/c/ieee754.h @@ -2,12 +2,12 @@ union ieee754_float { float f; struct { -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned int negative : 1; unsigned int exponent : 8; unsigned int mantissa : 23; #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ unsigned int mantissa : 23; unsigned int exponent : 8; unsigned int negative : 1; @@ -21,13 +21,13 @@ union ieee754_double { double d; struct { -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned int negative : 1; unsigned int exponent : 11; unsigned int mantissa0 : 20; unsigned int mantissa1 : 32; #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ unsigned int mantissa1 : 32; unsigned int mantissa0 : 20; unsigned int exponent : 11; @@ -42,14 +42,14 @@ union ieee854_long_double { long double d; struct { -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned int negative : 1; unsigned int exponent : 15; unsigned int empty : 16; unsigned int mantissa0 : 32; unsigned int mantissa1 : 32; #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ unsigned int mantissa1 : 32; unsigned int mantissa0 : 32; unsigned int exponent : 15; diff --git a/c/lookup3.h b/c/lookup3.h index 3f3eb44..8ed6124 100644 --- a/c/lookup3.h +++ b/c/lookup3.h @@ -35,24 +35,14 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. */ //#define SELF_TEST 1 -/* - * My best guess at if you are big-endian or little-endian. This may - * need adjustment. - */ -#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ - __BYTE_ORDER == __LITTLE_ENDIAN) || \ -(defined(i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) -#define HASH_LITTLE_ENDIAN 1 -#define HASH_BIG_ENDIAN 0 -#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ - __BYTE_ORDER == __BIG_ENDIAN) || \ -(defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) -#define HASH_LITTLE_ENDIAN 0 +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define HASH_BIG_ENDIAN 1 -#else #define HASH_LITTLE_ENDIAN 0 +#endif + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define HASH_BIG_ENDIAN 0 +#define HASH_LITTLE_ENDIAN 1 #endif #define hashsize(n) ((uint32_t)1 << (n))