Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to use AVX512 without OS support #566

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cbits/measure_off.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@
bool has_avx512_vl_bw() {
#if (__GNUC__ >= 7 || __GNUC__ == 6 && __GNUC_MINOR__ >= 3) || defined(__clang_major__)
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
uint64_t xcr0;
__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
// https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features
__asm__("xgetbv\n\t" : "=a" (xcr0) : "c" (0));
const bool has_avx512_bw = ebx & (1 << 30);
const bool has_avx512_vl = ebx & (1 << 31);
// XCR0 bits 5, 6, and 7
const bool avx512_os_enabled = (xcr0 & 0xE0) == 0xE0;
// printf("cpuid=%d=cpuid\n", has_avx512_bw && has_avx512_vl);
return has_avx512_bw && has_avx512_vl;
return has_avx512_bw && has_avx512_vl && avx512_os_enabled;
#else
return false;
#endif
Expand Down
Loading