Skip to content

Commit 02485e9

Browse files
committed
feat: std_detect avx512fp16
Signed-off-by: usamoi <usamoi@outlook.com>
1 parent eeb0ebd commit 02485e9

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ features! {
7575
/// * `"avx512bitalg"`
7676
/// * `"avx512bf16"`
7777
/// * `"avx512vp2intersect"`
78+
/// * `"avx512fp16"`
7879
/// * `"f16c"`
7980
/// * `"fma"`
8081
/// * `"bmi1"`
@@ -169,6 +170,8 @@ features! {
169170
/// AVX-512 BF16 (BFLOAT16 instructions)
170171
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] avx512vp2intersect: "avx512vp2intersect";
171172
/// AVX-512 P2INTERSECT
173+
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] avx512fp16: "avx512fp16";
174+
/// AVX-512 FP16 (FLOAT16 instructions)
172175
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] f16c: "f16c";
173176
/// F16C (Conversions between IEEE-754 `binary16` and `binary32` formats)
174177
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] fma: "fma";

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ 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) = if max_basic_leaf >= 7 {
73-
let CpuidResult { ebx, ecx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
74-
(ebx, ecx)
75-
} else {
76-
(0, 0) // CPUID does not support "Extended Features"
77-
};
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+
};
7879

7980
// EAX = 0x8000_0000, ECX = 0: Get Highest Extended Function Supported
8081
// - EAX returns the max leaf value for extended information, that is,
@@ -217,6 +218,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
217218
enable(extended_features_ecx, 11, Feature::avx512vnni);
218219
enable(extended_features_ecx, 12, Feature::avx512bitalg);
219220
enable(extended_features_ecx, 14, Feature::avx512vpopcntdq);
221+
enable(extended_features_edx, 23, Feature::avx512fp16);
220222
}
221223
}
222224
}

crates/std_detect/tests/cpu-detection.rs

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ fn x86_all() {
201201
"avx512vp2intersect {:?}",
202202
is_x86_feature_detected!("avx512vp2intersect")
203203
);
204+
println!("avx512fp16 {:?}", is_x86_feature_detected!("avx512fp16"));
204205
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
205206
println!("fma: {:?}", is_x86_feature_detected!("fma"));
206207
println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));

crates/std_detect/tests/x86-specific.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ fn dump() {
4949
"avx512vp2intersect {:?}",
5050
is_x86_feature_detected!("avx512vp2intersect")
5151
);
52+
println!("avx512fp16 {:?}", is_x86_feature_detected!("avx512fp16"));
5253
println!("fma: {:?}", is_x86_feature_detected!("fma"));
5354
println!("abm: {:?}", is_x86_feature_detected!("abm"));
5455
println!("bmi: {:?}", is_x86_feature_detected!("bmi1"));

0 commit comments

Comments
 (0)