Skip to content

Commit 88ef07e

Browse files
committed
Test whether OS supports AVX512
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 0daf18c commit 88ef07e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/arch/simddetect.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ SIMDDetect::SIMDDetect() {
171171
// be used inside an if.
172172
__cpuid_count(7, 0, eax, ebx, ecx, edx);
173173
avx2_available_ = (ebx & 0x00000020) != 0;
174-
avx512F_available_ = (ebx & 0x00010000) != 0;
175-
avx512BW_available_ = (ebx & 0x40000000) != 0;
176-
avx512VNNI_available_ = (ecx & 0x00000800) != 0;
174+
if ((xgetbv() & 0xe0) == 0xe0) {
175+
// OS supports AVX512.
176+
avx512F_available_ = (ebx & 0x00010000) != 0;
177+
avx512BW_available_ = (ebx & 0x40000000) != 0;
178+
avx512VNNI_available_ = (ecx & 0x00000800) != 0;
179+
}
177180
}
178181
# endif
179182
}
@@ -202,9 +205,12 @@ SIMDDetect::SIMDDetect() {
202205
if (max_function_id >= 7) {
203206
__cpuid(cpuInfo, 7);
204207
avx2_available_ = (cpuInfo[1] & 0x00000020) != 0;
205-
avx512F_available_ = (cpuInfo[1] & 0x00010000) != 0;
206-
avx512BW_available_ = (cpuInfo[1] & 0x40000000) != 0;
207-
avx512VNNI_available_ = (cpuInfo[2] & 0x00000800) != 0;
208+
if ((_xgetbv(0) & 0xe0) == 0xe0) {
209+
// OS supports AVX512.
210+
avx512F_available_ = (cpuInfo[1] & 0x00010000) != 0;
211+
avx512BW_available_ = (cpuInfo[1] & 0x40000000) != 0;
212+
avx512VNNI_available_ = (cpuInfo[2] & 0x00000800) != 0;
213+
}
208214
}
209215
# endif
210216
}

0 commit comments

Comments
 (0)