From: Mika T. Lindqvist Date: Mon, 12 Feb 2024 10:43:33 +0000 (+0200) Subject: Fix xsave intrinsic test for clang, and gcc 8.2 or later, and icc. X-Git-Tag: 2.2.0~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d945f0d716f3124ad7f40d37279649164eebee9;p=thirdparty%2Fzlib-ng.git Fix xsave intrinsic test for clang, and gcc 8.2 or later, and icc. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bbd144c5..b55a7f9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/arch/x86/x86_features.c b/arch/x86/x86_features.c index 583fc35a..450429cb 100644 --- a/arch/x86/x86_features.c +++ b/arch/x86/x86_features.c @@ -15,6 +15,13 @@ #else // Newer versions of GCC and clang come with cpuid.h # include +# ifdef X86_HAVE_XSAVE_INTRIN +# if __GNUC__ == 8 +# include +# else +# include +# endif +# endif #endif #include @@ -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; diff --git a/cmake/detect-intrinsics.cmake b/cmake/detect-intrinsics.cmake index c0d442cf..a06f7312 100644 --- a/cmake/detect-intrinsics.cmake +++ b/cmake/detect-intrinsics.cmake @@ -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 + #elif __GNUC__ == 8 && __GNUC_MINOR__ > 1 + # include #else - # include + # include #endif unsigned int f(unsigned int a) { return (int) _xgetbv(a); } int main(void) { return 0; }" diff --git a/configure b/configure index 810f4ed4..566cdb34 100755 --- a/configure +++ b/configure @@ -1238,8 +1238,10 @@ check_xsave_intrinsics() { cat > $test.c << EOF #ifdef _MSC_VER # include +#elif __GNUC__ == 8 && __GNUC_MINOR__ > 1 +# include #else -# include +# include #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