Skip to content

Commit 55af6a2

Browse files
silver-ymzAmanieu
authored andcommitted
fix: invalid bit for detecting avx512 feature
Signed-off-by: Mingzhuo Yin <yinmingzhuo@gmail.com>
1 parent 93851a3 commit 55af6a2

File tree

1 file changed

+15
-9
lines changed
  • crates/std_detect/src/detect/os

1 file changed

+15
-9
lines changed

crates/std_detect/src/detect/os/x86.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,19 @@ pub(crate) fn detect_features() -> cache::Initializer {
6969

7070
// EAX = 7, ECX = 0: Queries "Extended Features";
7171
// Contains information about bmi,bmi2, and avx2 support.
72-
let (extended_features_ebx, extended_features_ecx, extended_features_edx) =
73-
if max_basic_leaf >= 7 {
74-
let CpuidResult { ebx, ecx, edx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
75-
(ebx, ecx, edx)
76-
} else {
77-
(0, 0, 0) // CPUID does not support "Extended Features"
78-
};
72+
let (
73+
extended_features_eax,
74+
extended_features_ebx,
75+
extended_features_ecx,
76+
extended_features_edx,
77+
) = if max_basic_leaf >= 7 {
78+
let CpuidResult {
79+
eax, ebx, ecx, edx, ..
80+
} = unsafe { __cpuid(0x0000_0007_u32) };
81+
(eax, ebx, ecx, edx)
82+
} else {
83+
(0, 0, 0, 0) // CPUID does not support "Extended Features"
84+
};
7985

8086
// EAX = 0x8000_0000, ECX = 0: Get Highest Extended Function Supported
8187
// - EAX returns the max leaf value for extended information, that is,
@@ -200,6 +206,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
200206
// For AVX-512 the OS also needs to support saving/restoring
201207
// the extended state, only then we enable AVX-512 support:
202208
if os_avx512_support {
209+
enable(extended_features_eax, 5, Feature::avx512bf16);
203210
enable(extended_features_ebx, 16, Feature::avx512f);
204211
enable(extended_features_ebx, 17, Feature::avx512dq);
205212
enable(extended_features_ebx, 21, Feature::avx512ifma);
@@ -209,15 +216,14 @@ pub(crate) fn detect_features() -> cache::Initializer {
209216
enable(extended_features_ebx, 30, Feature::avx512bw);
210217
enable(extended_features_ebx, 31, Feature::avx512vl);
211218
enable(extended_features_ecx, 1, Feature::avx512vbmi);
212-
enable(extended_features_ecx, 5, Feature::avx512bf16);
213219
enable(extended_features_ecx, 6, Feature::avx512vbmi2);
214220
enable(extended_features_ecx, 8, Feature::gfni);
215-
enable(extended_features_ecx, 8, Feature::avx512vp2intersect);
216221
enable(extended_features_ecx, 9, Feature::vaes);
217222
enable(extended_features_ecx, 10, Feature::vpclmulqdq);
218223
enable(extended_features_ecx, 11, Feature::avx512vnni);
219224
enable(extended_features_ecx, 12, Feature::avx512bitalg);
220225
enable(extended_features_ecx, 14, Feature::avx512vpopcntdq);
226+
enable(extended_features_edx, 8, Feature::avx512vp2intersect);
221227
enable(extended_features_edx, 23, Feature::avx512fp16);
222228
}
223229
}

0 commit comments

Comments
 (0)