From 52de625df991126899d7f547e669a949bb85e923 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Fri, 4 Dec 2020 03:47:06 +0700 Subject: [PATCH] Fix floating point parsing on BE systems (#7256) * Fix floating point parsing on BE systems * Load the appropriate endian.h files for macOS and BSD * Add endian definition for Windows and extra check for ldshape selection * Fix endian macro definition for macOS Apparently their macros are defined without a leading __. * Define new macro for endian checking purposes This is gross and I really do not like the lack of standardization around this part, but what can I do? --- src/stage1/parse_f128.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/stage1/parse_f128.c b/src/stage1/parse_f128.c index 9b5c287a3c..59750f2129 100644 --- a/src/stage1/parse_f128.c +++ b/src/stage1/parse_f128.c @@ -10,6 +10,28 @@ #include #include +// Every OSes seem to define endianness macros in different files. +#if defined(__APPLE__) + #include + #define ZIG_BIG_ENDIAN BIG_ENDIAN + #define ZIG_LITTLE_ENDIAN LITTLE_ENDIAN + #define ZIG_BYTE_ORDER BYTE_ORDER +#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + #include + #define ZIG_BIG_ENDIAN _BIG_ENDIAN + #define ZIG_LITTLE_ENDIAN _LITTLE_ENDIAN + #define ZIG_BYTE_ORDER _BYTE_ORDER +#elif defined(_WIN32) || defined(_WIN64) + // Assume that Windows installations are always little endian. + #define ZIG_LITTLE_ENDIAN 1 + #define ZIG_BYTE_ORDER ZIG_LITTLE_ENDIAN +#else // Linux + #include + #define ZIG_BIG_ENDIAN __BIG_ENDIAN + #define ZIG_LITTLE_ENDIAN __LITTLE_ENDIAN + #define ZIG_BYTE_ORDER __BYTE_ORDER +#endif + #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) #define shlim(f, lim) __shlim((f), (lim)) #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f)) @@ -47,8 +69,7 @@ #define DECIMAL_DIG 36 - -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN union ldshape { float128_t f; struct { @@ -62,7 +83,7 @@ union ldshape { uint64_t hi; } i2; }; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN union ldshape { float128_t f; struct { @@ -76,6 +97,7 @@ union ldshape { uint64_t lo; } i2; }; +#else #error Unsupported endian #endif