Add runtime feature detection for F16C

This commit is contained in:
gnzlbg
2019-04-23 10:10:41 +02:00
committed by gnzlbg
parent 0da68477f9
commit d31cc0b09e
5 changed files with 14 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
//! F16C intrinsics: //! [F16C intrinsics].
//! https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=fp16&expand=1769 //!
//! [F16C intrinsics]: https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=fp16&expand=1769
use crate::{ use crate::{
core_arch::{simd::*, x86::*}, core_arch::{simd::*, x86::*},

View File

@@ -31,6 +31,7 @@ fn x86_all() {
"avx512_vpopcntdq {:?}", "avx512_vpopcntdq {:?}",
is_x86_feature_detected!("avx512vpopcntdq") is_x86_feature_detected!("avx512vpopcntdq")
); );
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
println!("fma: {:?}", is_x86_feature_detected!("fma")); println!("fma: {:?}", is_x86_feature_detected!("fma"));
println!("abm: {:?}", is_x86_feature_detected!("abm")); println!("abm: {:?}", is_x86_feature_detected!("abm"));
println!("bmi: {:?}", is_x86_feature_detected!("bmi1")); println!("bmi: {:?}", is_x86_feature_detected!("bmi1"));

View File

@@ -62,6 +62,7 @@
/// * `"avx512ifma"` /// * `"avx512ifma"`
/// * `"avx512vbmi"` /// * `"avx512vbmi"`
/// * `"avx512vpopcntdq"` /// * `"avx512vpopcntdq"`
/// * `"f16c"`
/// * `"fma"` /// * `"fma"`
/// * `"bmi1"` /// * `"bmi1"`
/// * `"bmi2"` /// * `"bmi2"`
@@ -179,6 +180,10 @@ macro_rules! is_x86_feature_detected {
cfg!(target_feature = "avx512vpopcntdq") || $crate::detect::check_for( cfg!(target_feature = "avx512vpopcntdq") || $crate::detect::check_for(
$crate::detect::Feature::avx512_vpopcntdq) $crate::detect::Feature::avx512_vpopcntdq)
}; };
("f16c") => {
cfg!(target_feature = "avx512f") || $crate::detect::check_for(
$crate::detect::Feature::f16c)
};
("fma") => { ("fma") => {
cfg!(target_feature = "fma") || $crate::detect::check_for( cfg!(target_feature = "fma") || $crate::detect::check_for(
$crate::detect::Feature::fma) $crate::detect::Feature::fma)
@@ -309,6 +314,8 @@ pub enum Feature {
/// AVX-512 VPOPCNTDQ (Vector Population Count Doubleword and /// AVX-512 VPOPCNTDQ (Vector Population Count Doubleword and
/// Quadword) /// Quadword)
avx512_vpopcntdq, avx512_vpopcntdq,
/// F16C (Conversions between IEEE-754 `binary16` and `binary32` formats)
f16c,
/// FMA (Fused Multiply Add) /// FMA (Fused Multiply Add)
fma, fma,
/// BMI1 (Bit Manipulation Instructions 1) /// BMI1 (Bit Manipulation Instructions 1)

View File

@@ -113,13 +113,14 @@ fn detect_features() -> cache::Initializer {
}; };
enable(proc_info_ecx, 0, Feature::sse3); enable(proc_info_ecx, 0, Feature::sse3);
enable(proc_info_ecx, 1, Feature::pclmulqdq);
enable(proc_info_ecx, 9, Feature::ssse3); enable(proc_info_ecx, 9, Feature::ssse3);
enable(proc_info_ecx, 13, Feature::cmpxchg16b); enable(proc_info_ecx, 13, Feature::cmpxchg16b);
enable(proc_info_ecx, 19, Feature::sse4_1); enable(proc_info_ecx, 19, Feature::sse4_1);
enable(proc_info_ecx, 20, Feature::sse4_2); enable(proc_info_ecx, 20, Feature::sse4_2);
enable(proc_info_ecx, 23, Feature::popcnt); enable(proc_info_ecx, 23, Feature::popcnt);
enable(proc_info_ecx, 25, Feature::aes); enable(proc_info_ecx, 25, Feature::aes);
enable(proc_info_ecx, 1, Feature::pclmulqdq); enable(proc_info_ecx, 29, Feature::f16c);
enable(proc_info_ecx, 30, Feature::rdrand); enable(proc_info_ecx, 30, Feature::rdrand);
enable(extended_features_ebx, 18, Feature::rdseed); enable(extended_features_ebx, 18, Feature::rdseed);
enable(extended_features_ebx, 19, Feature::adx); enable(extended_features_ebx, 19, Feature::adx);

View File

@@ -87,6 +87,7 @@ fn x86_all() {
"avx512_vpopcntdq {:?}", "avx512_vpopcntdq {:?}",
is_x86_feature_detected!("avx512vpopcntdq") is_x86_feature_detected!("avx512vpopcntdq")
); );
println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
println!("fma: {:?}", is_x86_feature_detected!("fma")); println!("fma: {:?}", is_x86_feature_detected!("fma"));
println!("bmi1: {:?}", is_x86_feature_detected!("bmi1")); println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));
println!("bmi2: {:?}", is_x86_feature_detected!("bmi2")); println!("bmi2: {:?}", is_x86_feature_detected!("bmi2"));