From 37b797e05aa9d46b620ff4d4253dbf993f121fb3 Mon Sep 17 00:00:00 2001
From: LekKit <50500857+LekKit@users.noreply.github.com>
Date: Mon, 4 Mar 2024 16:49:09 +0200
Subject: [PATCH] compiler: Refactor endianness detection
---
src/compiler.h | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/src/compiler.h b/src/compiler.h
index cc48425b9..cafad3a70 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -94,29 +94,16 @@ along with this program. If not, see .
#define MSAN_SUPPRESS
#endif
-#ifdef GNU_EXTS
-
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define HOST_LITTLE_ENDIAN 1
-#else
-#define HOST_BIG_ENDIAN 1
-#endif
-
-#else
-
// Guess endianness based on arch/common macros
// Able to detect big-endian MIPS, ARM, PowerPC, PA-RISC, s390
-#if defined(__MIPSEB__) || defined(__ARMEB__) || \
- defined(__hppa__) || defined(__hppa64__) || defined(__s390__) || \
- (defined(__ppc__) || defined(__ppc64__)) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || defined(__MIPSEB__) || \
+ defined(__ARMEB__) || defined(__hppa__) || defined(__hppa64__) || defined(__s390__)
#define HOST_BIG_ENDIAN 1
-#else
+#elif !defined(GNU_EXTS) || (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define HOST_LITTLE_ENDIAN 1
#endif
-#endif
-
-#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64)
+#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64) || defined(__aarch64__)
#define HOST_MISALIGN_SUPPORT 1
#else
// Not sure about other arches, misaligns may be very slow
@@ -128,6 +115,8 @@ along with this program. If not, see .
#if UINTPTR_MAX == UINT64_MAX
#define HOST_64BIT 1
+#elif UINTPTR_MAX == UINT32_MAX
+#define HOST_32BIT 1
#endif
// Unwrap a token or a token value into a string literal