]> 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>
Sun, 18 Feb 2024 09:10:45 +0000 (10:10 +0100)
CMakeLists.txt
arch/x86/x86_features.c
cmake/detect-intrinsics.cmake
configure

index bbd144c5f7d20a509144494b627d77c74cb7a72c..b55a7f9fa8d552c5b3e41cf5267b0d9bfbad7a91 100644 (file)
@@ -814,6 +814,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()
         if(WITH_SSE2)
             check_sse2_intrinsics()
index 583fc35a9289560ca4ba1613b6d9fb6b9b8e3111..450429cb9283780d5792599e1f9ae391ac532737 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 c0d442cff0c9802c5a2eddc4810d345853a0956b..a06f7312b7c74b7077345847b5a80a94fc8c0d96 100644 (file)
@@ -546,15 +546,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 810f4ed4484791a938950585bc56b29380e223cc..566cdb348ab6b47171ffe33b99f175729f1b2cc8 100755 (executable)
--- a/configure
+++ b/configure
@@ -1238,8 +1238,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; }
@@ -1466,7 +1468,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