diff --git a/lib/codec_choose.c b/lib/codec_choose.c index 756f801..0bf8fb6 100644 --- a/lib/codec_choose.c +++ b/lib/codec_choose.c @@ -74,7 +74,16 @@ #define _XCR_XFEATURE_ENABLED_MASK 0 #endif -#define _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS 0x6 +#define bit_XMM (1 << 1) +#define bit_YMM (1 << 2) +#define bit_OPMASK (1 << 5) +#define bit_ZMM (1 << 6) +#define bit_HIGH_ZMM (1 << 7) + +#define _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS (bit_XMM | bit_YMM) + +#define _AVX_512_ENABLED_BY_OS (bit_XMM | bit_YMM | bit_OPMASK | bit_ZMM | bit bit_HIGH_ZMM) + #endif // Function declarations: @@ -210,7 +219,7 @@ codec_choose_x86 (struct codec *codec) xcr_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK); if ((xcr_mask & _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS) == _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS) { // check multiple bits at once #if HAVE_AVX512 - if (max_level >= 7) { + if (max_level >= 7 && ((xcr_mask & _AVX_512_ENABLED_BY_OS) == _AVX_512_ENABLED_BY_OS)) { __cpuid_count(7, 0, eax, ebx, ecx, edx); if ((ebx & bit_AVX512vl) && (ecx & bit_AVX512vbmi)) { codec->enc = base64_stream_encode_avx512;