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()
#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>
}
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;
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; }"
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; }
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