From cbe1bf0b291e27dc6ec95763b3a567d2ec0842cc Mon Sep 17 00:00:00 2001 From: mhandb Date: Mon, 22 Dec 2025 12:45:47 +0100 Subject: [PATCH] Fix default values for AVX and AVX512 OS state enabled flags AVX and AVX512 strictly require the OS to enable OXSAVE otherwise we can face "illegal instruction" depending on the context state --- include/xsimd/config/xsimd_cpuid.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/xsimd/config/xsimd_cpuid.hpp b/include/xsimd/config/xsimd_cpuid.hpp index 8fdae0e51..9805bf087 100644 --- a/include/xsimd/config/xsimd_cpuid.hpp +++ b/include/xsimd/config/xsimd_cpuid.hpp @@ -197,8 +197,11 @@ namespace xsimd // https://docs.kernel.org/admin-guide/hw-vuln/gather_data_sampling.html unsigned sse_state_os_enabled = 1; - unsigned avx_state_os_enabled = 1; - unsigned avx512_state_os_enabled = 1; + // AVX and AVX512 strictly require OSXSAVE to be enabled by the OS. + // If OSXSAVE is disabled (e.g., via bcdedit /set xsavedisable 1), + // AVX state won't be preserved across context switches, so AVX cannot be used. + unsigned avx_state_os_enabled = 0; + unsigned avx512_state_os_enabled = 0; // OSXSAVE: A value of 1 indicates that the OS has set CR4.OSXSAVE[bit // 18] to enable XSETBV/XGETBV instructions to access XCR0 and