From 38bf38e835d968ac306800b6f46f4d63a04346bb Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 13 Apr 2024 17:50:11 +0300 Subject: [PATCH] Use _xgetbv intrinsic on Windows for AVX2 detection. The intrinsic is supported since VS2010 SP1, which is below our minimum supported MSVC version. The intrinsic is the proper way to detect support for AVX register state by the OS instead of the undocumented GetEnabledExtendedFeatures WinAPI function. --- src/dump.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index 812687931..5bdba7c8c 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -18,8 +18,8 @@ #include #include #if defined(_MSC_VER) && (defined(BOOST_LOG_USE_SSSE3) || defined(BOOST_LOG_USE_AVX2)) -#include #include // __cpuid +#include // _xgetbv #endif #include @@ -180,19 +180,8 @@ struct function_pointer_initializer : "c" (0) ); mmstate = (eax & 6u) == 6u; -#elif defined(BOOST_WINDOWS) - // MSVC does not have an intrinsic for xgetbv, we have to query OS - boost::winapi::HMODULE_ hKernel32 = boost::winapi::GetModuleHandleW(L"kernel32.dll"); - if (hKernel32) - { - typedef uint64_t (BOOST_WINAPI_WINAPI_CC* get_enabled_extended_features_t)(uint64_t); - get_enabled_extended_features_t get_enabled_extended_features = (get_enabled_extended_features_t)boost::winapi::get_proc_address(hKernel32, "GetEnabledExtendedFeatures"); - if (get_enabled_extended_features) - { - // XSTATE_MASK_LEGACY_SSE | XSTATE_MASK_GSSE == 6 - mmstate = get_enabled_extended_features(6u) == 6u; - } - } +#elif defined(_MSC_VER) + mmstate = (_xgetbv(_XCR_XFEATURE_ENABLED_MASK) & 6u) == 6u; #endif if (mmstate)