aboutsummaryrefslogtreecommitdiff
path: root/src/common/tuklib_integer.h
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-04-19 22:22:16 +0800
committerJia Tan <jiat0218@gmail.com>2023-04-19 22:22:16 +0800
commitf41df2ac2fed347d3f107f3533e76e000d29c6cb (patch)
tree2f434efad6e8672a261a31881b64d7969240b4bc /src/common/tuklib_integer.h
parenttuklib_integer: Use __builtin_clz() with Clang. (diff)
downloadxz-f41df2ac2fed347d3f107f3533e76e000d29c6cb.tar.xz
Windows: Include <intrin.h> when needed.
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.
Diffstat (limited to 'src/common/tuklib_integer.h')
-rw-r--r--src/common/tuklib_integer.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/common/tuklib_integer.h b/src/common/tuklib_integer.h
index 21256955..aee1ad0d 100644
--- a/src/common/tuklib_integer.h
+++ b/src/common/tuklib_integer.h
@@ -52,6 +52,12 @@
// 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