Skip to content

Commit a91e007

Browse files
mkannwischerhanno-becker
authored andcommitted
sys.h: Detect little endian when compiling with MSVC
This commit adds detection for endianness with MSVC - MSVC does not define __BYTE_ORDER__, and, hence our current detection does not capture it. MSVC currently supports 3 platforms: x86, x86_64, and AArch64 (AArch32 was recently removed in VS 2026 18.0) See https://learn.microsoft.com/en-us/cpp/overview/supported-platforms-visual-cpp x86 and x86_64 are always little endian. AArch64 can be either little endian or big endian, but MSVC/Windows only supports little endian: https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions For AArch32, I can't find explicit statements that MSVC was always limited to little endian, so I've commited that. See https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros Resolves #620 Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent b3f5140 commit a91e007

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mldsa/src/sys.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
#error "__BYTE_ORDER__ defined, but don't recognize value."
2323
#endif
2424
#endif /* __BYTE_ORDER__ */
25+
26+
/* MSVC does not define __BYTE_ORDER__. However, MSVC only supports
27+
* little endian x86, x86_64, and AArch64. It is, hence, safe to assume
28+
* little endian. */
29+
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || \
30+
defined(_M_IX86) || defined(_M_ARM64))
31+
#define MLD_SYS_LITTLE_ENDIAN
32+
#endif
33+
2534
#endif /* !MLD_SYS_LITTLE_ENDIAN && !MLD_SYS_BIG_ENDIAN */
2635

2736
/* Check if we're running on an AArch64 little endian system. _M_ARM64 is set by

0 commit comments

Comments
 (0)