From 0534873e8d3c063c5054e6231dfd4bd4e4eacd2d Mon Sep 17 00:00:00 2001 From: sayantn Date: Mon, 1 Jul 2024 21:24:11 +0530 Subject: [PATCH] Implemented runtime detection of `xop` target-feature --- crates/std_detect/src/detect/arch/x86.rs | 2 ++ crates/std_detect/src/detect/os/x86.rs | 1 + crates/std_detect/tests/cpu-detection.rs | 3 ++- crates/std_detect/tests/x86-specific.rs | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/std_detect/src/detect/arch/x86.rs b/crates/std_detect/src/detect/arch/x86.rs index ef7091ec7b..2890c7ee2f 100644 --- a/crates/std_detect/src/detect/arch/x86.rs +++ b/crates/std_detect/src/detect/arch/x86.rs @@ -245,4 +245,6 @@ features! { /// MOVBE (Move Data After Swapping Bytes) @FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] ermsb: "ermsb"; /// ERMSB, Enhanced REP MOVSB and STOSB + @FEATURE: #[unstable(feature = "xop_target_feature", issue = "127208")] xop: "xop"; + /// XOP: eXtended Operations (AMD) } diff --git a/crates/std_detect/src/detect/os/x86.rs b/crates/std_detect/src/detect/os/x86.rs index 4a0e2c9b18..979fd9ca1f 100644 --- a/crates/std_detect/src/detect/os/x86.rs +++ b/crates/std_detect/src/detect/os/x86.rs @@ -279,6 +279,7 @@ pub(crate) fn detect_features() -> cache::Initializer { // These features are available on AMD arch CPUs: enable(extended_proc_info_ecx, 6, Feature::sse4a); enable(extended_proc_info_ecx, 21, Feature::tbm); + enable(extended_proc_info_ecx, 11, Feature::xop); } } diff --git a/crates/std_detect/tests/cpu-detection.rs b/crates/std_detect/tests/cpu-detection.rs index 47bb499dee..615268e876 100644 --- a/crates/std_detect/tests/cpu-detection.rs +++ b/crates/std_detect/tests/cpu-detection.rs @@ -5,7 +5,7 @@ #![cfg_attr(target_arch = "powerpc64", feature(stdarch_powerpc_feature_detection))] #![cfg_attr( any(target_arch = "x86", target_arch = "x86_64"), - feature(sha512_sm_x86, x86_amx_intrinsics) + feature(sha512_sm_x86, x86_amx_intrinsics, xop_target_feature) )] #![allow(clippy::unwrap_used, clippy::use_debug, clippy::print_stdout)] @@ -264,6 +264,7 @@ fn x86_all() { println!("amx-int8: {:?}", is_x86_feature_detected!("amx-int8")); println!("amx-fp16: {:?}", is_x86_feature_detected!("amx-fp16")); println!("amx-complex: {:?}", is_x86_feature_detected!("amx-complex")); + println!("xop: {:?}", is_x86_feature_detected!("xop")); } #[test] diff --git a/crates/std_detect/tests/x86-specific.rs b/crates/std_detect/tests/x86-specific.rs index 611e41c941..60b6756f86 100644 --- a/crates/std_detect/tests/x86-specific.rs +++ b/crates/std_detect/tests/x86-specific.rs @@ -4,7 +4,8 @@ stdarch_internal, avx512_target_feature, sha512_sm_x86, - x86_amx_intrinsics + x86_amx_intrinsics, + xop_target_feature )] extern crate cupid; @@ -92,6 +93,7 @@ fn dump() { println!("amx-int8: {:?}", is_x86_feature_detected!("amx-int8")); println!("amx-fp16: {:?}", is_x86_feature_detected!("amx-fp16")); println!("amx-complex: {:?}", is_x86_feature_detected!("amx-complex")); + println!("xop: {:?}", is_x86_feature_detected!("xop")); } #[cfg(feature = "std_detect_env_override")]