From 298e6cc4958d04237e726e3e4286545d24fcc278 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Mon, 8 Jan 2024 14:05:59 +0000 Subject: [PATCH] Improve endianness check Update the `hsa.h` header to use the gcc / clang `__BYTE_ORDER__` macros where available to more accurately autodetect endianness for the target. Change-Id: I7312f3badcba9287a30eb14882b91e2a247acc5f [ROCm/ROCR-Runtime commit: 49711505762baa01bb3d89981c728e391786fe21] --- projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h index 6ff5dd70d9..9520bd870c 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h @@ -79,8 +79,12 @@ // Try to detect CPU endianness #if !defined(LITTLEENDIAN_CPU) && !defined(BIGENDIAN_CPU) -#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ - defined(_M_X64) || defined(__loongarch64) || defined(__riscv) +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define LITTLEENDIAN_CPU +#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define BIGENDIAN_CPU +#elif defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ + defined(_M_X64) || defined(__loongarch64) || defined(__riscv) #define LITTLEENDIAN_CPU #endif #endif