diff --git a/src/specfun/fpmath.h b/src/specfun/fpmath.h index 3b06b7e56b001..505d89f033a1d 100644 --- a/src/specfun/fpmath.h +++ b/src/specfun/fpmath.h @@ -38,51 +38,69 @@ #endif #endif -#ifdef __linux -#include -#include -#define _LITTLE_ENDIAN __LITTLE_ENDIAN -#define _BIG_ENDIAN __BIG_ENDIAN -#define _PDP_ENDIAN __PDP_ENDIAN -#define _BYTE_ORDER __BYTE_ORDER -#endif - -#ifdef __APPLE__ -#include -#define _LITTLE_ENDIAN LITTLE_ENDIAN -#define _BIG_ENDIAN BIG_ENDIAN -#define _PDP_ENDIAN PDP_ENDIAN -#define _BYTE_ORDER BYTE_ORDER -#endif - -#ifdef __FreeBSD__ -#include -#endif +// We need to find out the byte ordering of the system. +// +// This will be stored in the following macros: +// _FPMATH_LITTLE_ENDIAN: An arbitrary constant +// _FPMATH_BIG_ENDIAN: An arbitrary constant +// _FPMATH_BYTE_ORDER: Either _FPMATH_LITTLE_ENDIAN or _FPMATH_BIG_ENDIAN -#ifdef _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 +// The GNU preprocessor defines a few things by itself +// See http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html#Common-Predefined-Macros +#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__) +# define _FPMATH_BIG_ENDIAN __ORDER_BIG_ENDIAN__ +# define _FPMATH_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +# define _FPMATH_BYTE_ORDER __BYTE_ORDER__ +// If not defined by the preprocessor, let us try to do it ourselves. +// Linux +#elif defined(__linux) +# include +# include +# define _FPMATH_LITTLE_ENDIAN __LITTLE_ENDIAN +# define _FPMATH_BIG_ENDIAN __BIG_ENDIAN +# define _FPMATH_BYTE_ORDER __BYTE_ORDER +// OSX +#elif defined(__APPLE__) +# include +# define _FPMATH_LITTLE_ENDIAN LITTLE_ENDIAN +# define _FPMATH_BIG_ENDIAN BIG_ENDIAN +# define _FPMATH_BYTE_ORDER BYTE_ORDER +// FreeBSD +#elif defined(__FreeBSD__) +# include +# define _FPMATH_LITTLE_ENDIAN _LITTLE_ENDIAN +# define _FPMATH_BIG_ENDIAN _BIG_ENDIAN +# define _FPMATH_BYTE_ORDER _BYTE_ORDER +// Windows +#elif defined(_WIN32) +# define _FPMATH_LITTLE_ENDIAN 1234 +# define _FPMATH_BIG_ENDIAN 4321 +# define _FPMATH_BYTE_ORDER _FPMATH_LITTLE_ENDIAN +// Solaris +#elif defined(__sun) +# define _FPMATH_LITTLE_ENDIAN 1234 +# define _FPMATH_BIG_ENDIAN 4321 +# include +# ifdef _LITTLE_ENDIAN +# define _FPMATH_BYTE_ORDER _FPMATH_LITTLE_ENDIAN +# endif +# ifdef _BIG_ENDIAN +# define _FPMATH_BYTE_ORDER _FPMATH_BIG_ENDIAN +# endif #endif #ifndef _IEEE_WORD_ORDER -#define _IEEE_WORD_ORDER _BYTE_ORDER +#define _IEEE_WORD_ORDER _FPMATH_BYTE_ORDER #endif union IEEEf2bits { float f; struct { -#if _BYTE_ORDER == _LITTLE_ENDIAN +#if _FPMATH_BYTE_ORDER == _FPMATH_LITTLE_ENDIAN unsigned int man :23; unsigned int exp :8; unsigned int sign :1; -#else /* _BIG_ENDIAN */ +#else /* _FPMATH_BIG_ENDIAN */ unsigned int sign :1; unsigned int exp :8; unsigned int man :23; @@ -96,17 +114,17 @@ union IEEEf2bits { union IEEEd2bits { double d; struct { -#if _BYTE_ORDER == _LITTLE_ENDIAN -#if _IEEE_WORD_ORDER == _LITTLE_ENDIAN +#if _FPMATH_BYTE_ORDER == _FPMATH_LITTLE_ENDIAN +#if _IEEE_WORD_ORDER == _FPMATH_LITTLE_ENDIAN unsigned int manl :32; #endif unsigned int manh :20; unsigned int exp :11; unsigned int sign :1; -#if _IEEE_WORD_ORDER == _BIG_ENDIAN +#if _IEEE_WORD_ORDER == _FPMATH_BIG_ENDIAN unsigned int manl :32; #endif -#else /* _BIG_ENDIAN */ +#else /* _FPMATH_BIG_ENDIAN */ unsigned int sign :1; unsigned int exp :11; unsigned int manh :20;