]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Windows: Include <intrin.h> when needed.
authorJia Tan <jiat0218@gmail.com>
Wed, 19 Apr 2023 14:22:16 +0000 (22:22 +0800)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 3 May 2023 19:33:10 +0000 (22:33 +0300)
Legacy Windows did not need to #include <intrin.h> to use the MSVC
intrinsics. Newer versions likely just issue a warning, but the MSVC
documentation says to include the header file for the intrinsics we use.

GCC and Clang can "pretend" to be MSVC on Windows, so extra checks are
needed in tuklib_integer.h to only include <intrin.h> when it will is
actually needed.

src/common/tuklib_integer.h
src/liblzma/common/memcmplen.h

index bfb8683b8c5f386427163a16e41d12c005666c7b..414c56269f048738b10d928ed65cb65cad512452 100644 (file)
 // and such functions.
 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500)
 #      include <immintrin.h>
+// Only include <intrin.h> when it is needed. GCC and Clang can both
+// use __builtin's, so we only need Windows instrincs when using MSVC.
+// GCC and Clang can set _MSC_VER on Windows, so we need to exclude these
+// cases explicitly.
+#elif defined(_MSC_VER) && !TUKLIB_GNUC_REQ(3, 4) && !defined(__clang__)
+#      include <intrin.h>
 #endif
 
 
index b76a0b6327ed27cc59a16be44751e8752ab300fc..da7c33585f0868c86fc3a2efb0542bf559c1a6e1 100644 (file)
 #      include <immintrin.h>
 #endif
 
+// Only include <intrin.h> if it is needed. The header is only needed
+// on Windows when using an MSVC compatible compiler. The Intel compiler
+// can use the intrinsics without the header file.
+#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
+               && (defined(_MSC_VER) \
+               && defined(_M_X64) \
+               && !defined(__INTEL_COMPILER))
+#      include <intrin.h>
+#endif
+
 
 /// Find out how many equal bytes the two buffers have.
 ///