Skip to content

Commit eceee8c

Browse files
committed
Add runtime feature detection for F16C
1 parent 7c26e0d commit eceee8c

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

crates/core_arch/src/x86/f16c.rs

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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"`
@@ -177,6 +178,10 @@ macro_rules! is_x86_feature_detected {
177178
cfg!(target_feature = "avx512vpopcntdq") || $crate::detect::check_for(
178179
$crate::detect::Feature::avx512_vpopcntdq)
179180
};
181+
("f16c") => {
182+
cfg!(target_feature = "avx512f") || $crate::detect::check_for(
183+
$crate::detect::Feature::f16c)
184+
};
180185
("fma") => {
181186
cfg!(target_feature = "fma") || $crate::detect::check_for(
182187
$crate::detect::Feature::fma)
@@ -303,6 +308,8 @@ pub enum Feature {
303308
/// AVX-512 VPOPCNTDQ (Vector Population Count Doubleword and
304309
/// Quadword)
305310
avx512_vpopcntdq,
311+
/// F16C (Conversions between IEEE-754 `binary16` and `binary32` formats)
312+
f16c,
306313
/// FMA (Fused Multiply Add)
307314
fma,
308315
/// BMI1 (Bit Manipulation Instructions 1)

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)