]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix xsave intrinsic test for clang, and gcc 8.2 or later, and icc.
authorMika T. Lindqvist <postmaster@raasu.org>
Mon, 12 Feb 2024 10:43:33 +0000 (12:43 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 19 Jun 2024 12:15:54 +0000 (14:15 +0200)
CMakeLists.txt
arch/x86/x86_features.c
cmake/detect-intrinsics.cmake
configure

index 50497846ca20973f58cb2eb366293cec77ef65f9..828eb128d2c011060b37db51846734fe4a25ec1f 100644 (file)
@@ -920,6 +920,9 @@ if(WITH_OPTIM)
         if(HAVE_XSAVE_INTRIN)
             add_feature_info(XSAVE 1 "Support XSAVE intrinsics using \"${XSAVEFLAG}\"")
             set_property(SOURCE ${ARCHDIR}/x86_features.c PROPERTY COMPILE_FLAGS "${XSAVEFLAG}")
+            if(NOT (CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 8.2))
+                add_definitions(-DX86_HAVE_XSAVE_INTRIN)
+            endif()
         endif()
     endif()
 endif()
index e261b70fe8a738bc55642700dcfa652f6f5bd5b2..3f37e7f205a45b2b56ceac4a0fae095f71f2191b 100644 (file)
 #else
 // Newer versions of GCC and clang come with cpuid.h
 #  include <cpuid.h>
+#  ifdef X86_HAVE_XSAVE_INTRIN
+#    if __GNUC__ == 8
+#      include <xsaveintrin.h>
+#    else
+#      include <immintrin.h>
+#    endif
+#  endif
 #endif
 
 #include <string.h>
@@ -50,7 +57,7 @@ static inline void cpuidex(int info, int subinfo, unsigned* eax, unsigned* ebx,
 }
 
 static inline uint64_t xgetbv(unsigned int xcr) {
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(X86_HAVE_XSAVE_INTRIN)
     return _xgetbv(xcr);
 #else
     uint32_t eax, edx;
index 1d417c5bfbd291550efa273896e908197a0f1e7a..295f735d7520458ef4426e5ef548ebdff6efb057 100644 (file)
@@ -556,15 +556,17 @@ macro(check_vgfma_intrinsics)
 endmacro()
 
 macro(check_xsave_intrinsics)
-    if(NOT NATIVEFLAG AND NOT MSVC)
+    if(NOT NATIVEFLAG AND NOT MSVC AND NOT CMAKE_C_COMPILER_ID MATCHES "Intel")
         set(XSAVEFLAG "-mxsave")
     endif()
     set(CMAKE_REQUIRED_FLAGS "${XSAVEFLAG} ${NATIVEFLAG} ${ZNOLTOFLAG}")
     check_c_source_compiles(
         "#ifdef _MSC_VER
         #  include <intrin.h>
+        #elif __GNUC__ == 8 && __GNUC_MINOR__ > 1
+        #  include <xsaveintrin.h>
         #else
-        #  include <x86gprintrin.h>
+        #  include <immintrin.h>
         #endif
         unsigned int f(unsigned int a) { return (int) _xgetbv(a); }
         int main(void) { return 0; }"
index 1c7f551887aae5e5369cedc2f3a5e4e3209ef9b1..9211dcb990f3c2a1cc93dde934c8fd5f15ae02af 100755 (executable)
--- a/configure
+++ b/configure
@@ -1254,8 +1254,10 @@ check_xsave_intrinsics() {
    cat > $test.c << EOF
 #ifdef _MSC_VER
 #  include <intrin.h>
+#elif __GNUC__ == 8 && __GNUC_MINOR__ > 1
+#  include <xsaveintrin.h>
 #else
-#  include <x86gprintrin.h>
+#  include <immintrin.h>
 #endif
 unsigned int f(unsigned int a) { return (int) _xgetbv(a); }
 int main(void) { return 0; }
@@ -1580,7 +1582,10 @@ case "${ARCH}" in
 
             check_xsave_intrinsics
 
-            if test ${HAVE_XSAVE_INTRIN} -eq 0; then
+            if test ${HAVE_XSAVE_INTRIN} -eq 1; then
+                CFLAGS="${CFLAGS} -DX86_HAVE_XSAVE_INTRIN"
+                SFLAGS="${SFLAGS} -DX86_HAVE_XSAVE_INTRIN"
+            else
                 xsaveflag=""
             fi
         fi