Skip to content

Commit 3dec358

Browse files
committed
Add runtime feature detection for F16C
1 parent ddc49a0 commit 3dec358

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

crates/core_arch/src/x86/f16c.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! F16C intrinsics:
2-
//! https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=fp16&expand=1769
1+
//! [F16C intrinsics].
2+
//!
3+
//! [F16C intrinsics]: https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=fp16&expand=1769
34
45
use crate::{
56
core_arch::{simd::*, x86::*},

crates/core_arch/tests/cpu-detection.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn x86_all() {
3131
"avx512_vpopcntdq {:?}",
3232
is_x86_feature_detected!("avx512vpopcntdq")
3333
);
34+
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
3435
println!("fma: {:?}", is_x86_feature_detected!("fma"));
3536
println!("abm: {:?}", is_x86_feature_detected!("abm"));
3637
println!("bmi: {:?}", is_x86_feature_detected!("bmi1"));

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

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
/// * `"avx512ifma"`
6363
/// * `"avx512vbmi"`
6464
/// * `"avx512vpopcntdq"`
65+
/// * `"f16c"`
6566
/// * `"fma"`
6667
/// * `"bmi1"`
6768
/// * `"bmi2"`
@@ -179,6 +180,10 @@ macro_rules! is_x86_feature_detected {
179180
cfg!(target_feature = "avx512vpopcntdq") || $crate::detect::check_for(
180181
$crate::detect::Feature::avx512_vpopcntdq)
181182
};
183+
("f16c") => {
184+
cfg!(target_feature = "avx512f") || $crate::detect::check_for(
185+
$crate::detect::Feature::f16c)
186+
};
182187
("fma") => {
183188
cfg!(target_feature = "fma") || $crate::detect::check_for(
184189
$crate::detect::Feature::fma)
@@ -309,6 +314,8 @@ pub enum Feature {
309314
/// AVX-512 VPOPCNTDQ (Vector Population Count Doubleword and
310315
/// Quadword)
311316
avx512_vpopcntdq,
317+
/// F16C (Conversions between IEEE-754 `binary16` and `binary32` formats)
318+
f16c,
312319
/// FMA (Fused Multiply Add)
313320
fma,
314321
/// BMI1 (Bit Manipulation Instructions 1)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ fn detect_features() -> cache::Initializer {
113113
};
114114

115115
enable(proc_info_ecx, 0, Feature::sse3);
116+
enable(proc_info_ecx, 1, Feature::pclmulqdq);
116117
enable(proc_info_ecx, 9, Feature::ssse3);
117118
enable(proc_info_ecx, 13, Feature::cmpxchg16b);
118119
enable(proc_info_ecx, 19, Feature::sse4_1);
119120
enable(proc_info_ecx, 20, Feature::sse4_2);
120121
enable(proc_info_ecx, 23, Feature::popcnt);
121122
enable(proc_info_ecx, 25, Feature::aes);
122-
enable(proc_info_ecx, 1, Feature::pclmulqdq);
123+
enable(proc_info_ecx, 29, Feature::f16c);
123124
enable(proc_info_ecx, 30, Feature::rdrand);
124125
enable(extended_features_ebx, 18, Feature::rdseed);
125126
enable(extended_features_ebx, 19, Feature::adx);

crates/std_detect/tests/cpu-detection.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn x86_all() {
8787
"avx512_vpopcntdq {:?}",
8888
is_x86_feature_detected!("avx512vpopcntdq")
8989
);
90+
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
9091
println!("fma: {:?}", is_x86_feature_detected!("fma"));
9192
println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));
9293
println!("bmi2: {:?}", is_x86_feature_detected!("bmi2"));

0 commit comments

Comments
 (0)