Skip to content

Commit

Permalink
check_cpu: Windows 10 doesn't enable AVX2 immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
maharmstone committed Oct 23, 2020
1 parent 80b831f commit 0fe35d6
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5909,7 +5909,7 @@ static void check_cpu() {

#ifndef _MSC_VER
{
uint32_t eax, ebx, ecx, edx, xcr0;
uint32_t eax, ebx, ecx, edx;

__cpuid(1, eax, ebx, ecx, edx);

Expand All @@ -5921,10 +5921,17 @@ static void check_cpu() {
if (__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx))
have_avx2 = ebx & bit_AVX2;

if (have_avx2) { // check if supported by OS
__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "edx" );
if (have_avx2) {
// check Windows has enabled AVX2 - Windows 10 doesn't immediately

if (__readcr4() & (1 << 18)) {
uint32_t xcr0;

__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "edx" );

if ((xcr0 & 6) != 6)
if ((xcr0 & 6) != 6)
have_avx2 = false;
} else
have_avx2 = false;
}
}
Expand All @@ -5940,9 +5947,14 @@ static void check_cpu() {
have_avx2 = cpu_info[1] & (1 << 5);

if (have_avx2) {
uint32_t xcr0 = (uint32_t)_xgetbv(0);
// check Windows has enabled AVX2 - Windows 10 doesn't immediately

if (__readcr4() & (1 << 18)) {
uint32_t xcr0 = (uint32_t)_xgetbv(0);

if ((xcr0 & 6) != 6)
if ((xcr0 & 6) != 6)
have_avx2 = false;
} else
have_avx2 = false;
}
}
Expand Down

0 comments on commit 0fe35d6

Please sign in to comment.