Skip to content

Commit

Permalink
feat: std_detect avx512fp16
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi authored and Amanieu committed Feb 24, 2024
1 parent 56087ea commit b8c54ec
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions crates/std_detect/src/detect/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ features! {
/// * `"avx512bitalg"`
/// * `"avx512bf16"`
/// * `"avx512vp2intersect"`
/// * `"avx512fp16"`
/// * `"f16c"`
/// * `"fma"`
/// * `"bmi1"`
Expand Down Expand Up @@ -169,6 +170,8 @@ features! {
/// AVX-512 BF16 (BFLOAT16 instructions)
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] avx512vp2intersect: "avx512vp2intersect";
/// AVX-512 P2INTERSECT
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] avx512fp16: "avx512fp16";
/// AVX-512 FP16 (FLOAT16 instructions)
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] f16c: "f16c";
/// F16C (Conversions between IEEE-754 `binary16` and `binary32` formats)
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] fma: "fma";
Expand Down
14 changes: 8 additions & 6 deletions crates/std_detect/src/detect/os/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ pub(crate) fn detect_features() -> cache::Initializer {

// EAX = 7, ECX = 0: Queries "Extended Features";
// Contains information about bmi,bmi2, and avx2 support.
let (extended_features_ebx, extended_features_ecx) = if max_basic_leaf >= 7 {
let CpuidResult { ebx, ecx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
(ebx, ecx)
} else {
(0, 0) // CPUID does not support "Extended Features"
};
let (extended_features_ebx, extended_features_ecx, extended_features_edx) =
if max_basic_leaf >= 7 {
let CpuidResult { ebx, ecx, edx, .. } = unsafe { __cpuid(0x0000_0007_u32) };
(ebx, ecx, edx)
} else {
(0, 0, 0) // CPUID does not support "Extended Features"
};

// EAX = 0x8000_0000, ECX = 0: Get Highest Extended Function Supported
// - EAX returns the max leaf value for extended information, that is,
Expand Down Expand Up @@ -217,6 +218,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
enable(extended_features_ecx, 11, Feature::avx512vnni);
enable(extended_features_ecx, 12, Feature::avx512bitalg);
enable(extended_features_ecx, 14, Feature::avx512vpopcntdq);
enable(extended_features_edx, 23, Feature::avx512fp16);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/std_detect/tests/cpu-detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ fn x86_all() {
"avx512vp2intersect {:?}",
is_x86_feature_detected!("avx512vp2intersect")
);
println!("avx512fp16 {:?}", is_x86_feature_detected!("avx512fp16"));
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
println!("fma: {:?}", is_x86_feature_detected!("fma"));
println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));
Expand Down
1 change: 1 addition & 0 deletions crates/std_detect/tests/x86-specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn dump() {
"avx512vp2intersect {:?}",
is_x86_feature_detected!("avx512vp2intersect")
);
println!("avx512fp16 {:?}", is_x86_feature_detected!("avx512fp16"));
println!("fma: {:?}", is_x86_feature_detected!("fma"));
println!("abm: {:?}", is_x86_feature_detected!("abm"));
println!("bmi: {:?}", is_x86_feature_detected!("bmi1"));
Expand Down

0 comments on commit b8c54ec

Please sign in to comment.