From 00cff79f7f76a8e3fe3c2a41c78f4d5dd0ebe6ba Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 16 Aug 2019 22:51:17 +0200 Subject: [PATCH] simd: Check whether the OS supports FMA, AVX, ... Signed-off-by: Stefan Weil --- src/arch/simddetect.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/arch/simddetect.cpp b/src/arch/simddetect.cpp index 64e5bd63d..1fdf8505f 100644 --- a/src/arch/simddetect.cpp +++ b/src/arch/simddetect.cpp @@ -120,18 +120,19 @@ SIMDDetect::SIMDDetect() { __cpuid(cpuInfo, 0); max_function_id = cpuInfo[0]; if (max_function_id >= 1) { + bool xmm_ymm_state_enabled = (_xgetbv(0) & 6) == 6; __cpuid(cpuInfo, 1); #if defined(SSE4_1) sse_available_ = (cpuInfo[2] & 0x00080000) != 0; #endif #if defined(FMA) - fma_available_ = (cpuInfo[2] & 0x00001000) != 0; + fma_available_ = xmm_ymm_state_enabled && (cpuInfo[2] & 0x00001000) != 0; #endif #if defined(AVX) avx_available_ = (cpuInfo[2] & 0x10000000) != 0; #endif #if defined(AVX2) - if (max_function_id >= 7) { + if (max_function_id >= 7 && xmm_ymm_state_enabled) { __cpuid(cpuInfo, 7); avx2_available_ = (cpuInfo[1] & 0x00000020) != 0; avx512F_available_ = (cpuInfo[1] & 0x00010000) != 0;