Skip to content

Commit

Permalink
fix: Correct OS detection for AVX-512
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaudet committed Jun 12, 2024
1 parent b20a31a commit 819ac85
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/codec_choose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 819ac85

Please sign in to comment.