about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsayantn <sayantn05@gmail.com>2025-02-06 00:14:16 +0530
committerAmanieu d'Antras <amanieu@gmail.com>2025-02-13 10:54:53 +0000
commit2a6953d38a99e0e626b5663f8b39f644fed5b546 (patch)
tree382366b7b1fc48b7dc71c7846046f342334be1e8
parente977f72f709b5bee366d7ee85e89e497044648c8 (diff)
downloadrust-2a6953d38a99e0e626b5663f8b39f644fed5b546.tar.gz
rust-2a6953d38a99e0e626b5663f8b39f644fed5b546.zip
Add runtime feature detection for keylocker
-rw-r--r--library/stdarch/crates/std_detect/src/detect/arch/x86.rs6
-rw-r--r--library/stdarch/crates/std_detect/src/detect/os/x86.rs7
-rw-r--r--library/stdarch/crates/std_detect/tests/x86-specific.rs5
3 files changed, 17 insertions, 1 deletions
diff --git a/library/stdarch/crates/std_detect/src/detect/arch/x86.rs b/library/stdarch/crates/std_detect/src/detect/arch/x86.rs
index 891fc427db9..38d7ebc7d34 100644
--- a/library/stdarch/crates/std_detect/src/detect/arch/x86.rs
+++ b/library/stdarch/crates/std_detect/src/detect/arch/x86.rs
@@ -103,6 +103,8 @@ features! {
     /// * `"xsaves"`
     /// * `"xsavec"`
     /// * `"cmpxchg16b"`
+    /// * `"kl"`
+    /// * `"widekl"`
     /// * `"adx"`
     /// * `"rtm"`
     /// * `"movbe"`
@@ -241,6 +243,10 @@ features! {
     /// XSAVEC (Save Processor Extended States Compacted)
     @FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] cmpxchg16b: "cmpxchg16b";
     /// CMPXCH16B (16-byte compare-and-swap instruction)
+    @FEATURE: #[unstable(feature = "keylocker_x86", issue = "134813")] kl: "kl";
+    /// Intel Key Locker
+    @FEATURE: #[unstable(feature = "keylocker_x86", issue = "134813")] widekl: "widekl";
+    /// Intel Key Locker Wide
     @FEATURE: #[stable(feature = "simd_x86_adx", since = "1.33.0")] adx: "adx";
     /// ADX, Intel ADX (Multi-Precision Add-Carry Instruction Extensions)
     @FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] rtm: "rtm";
diff --git a/library/stdarch/crates/std_detect/src/detect/os/x86.rs b/library/stdarch/crates/std_detect/src/detect/os/x86.rs
index c28f20baabc..bb6a44b6438 100644
--- a/library/stdarch/crates/std_detect/src/detect/os/x86.rs
+++ b/library/stdarch/crates/std_detect/src/detect/os/x86.rs
@@ -141,6 +141,13 @@ pub(crate) fn detect_features() -> cache::Initializer {
 
         enable(extended_features_ebx, 9, Feature::ermsb);
 
+        // Detect if CPUID.19h available
+        if bit::test(extended_features_ecx as usize, 23) {
+            let CpuidResult { ebx, .. } = unsafe { __cpuid(0x19) };
+            enable(ebx, 0, Feature::kl);
+            enable(ebx, 2, Feature::widekl);
+        }
+
         // `XSAVE` and `AVX` support:
         let cpu_xsave = bit::test(proc_info_ecx as usize, 26);
         if cpu_xsave {
diff --git a/library/stdarch/crates/std_detect/tests/x86-specific.rs b/library/stdarch/crates/std_detect/tests/x86-specific.rs
index 349bba86358..5f4441f1015 100644
--- a/library/stdarch/crates/std_detect/tests/x86-specific.rs
+++ b/library/stdarch/crates/std_detect/tests/x86-specific.rs
@@ -5,7 +5,8 @@
     avx512_target_feature,
     sha512_sm_x86,
     x86_amx_intrinsics,
-    xop_target_feature
+    xop_target_feature,
+    keylocker_x86
 )]
 
 extern crate cupid;
@@ -94,6 +95,8 @@ fn dump() {
     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"));
+    println!("kl: {:?}", is_x86_feature_detected!("kl"));
+    println!("widekl: {:?}", is_x86_feature_detected!("widekl"));
 }
 
 #[cfg(feature = "std_detect_env_override")]