Skip to content

Commit 27cd5be

Browse files
committed
add runtime detection for aes-ni
1 parent 536013b commit 27cd5be

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

coresimd/src/runtime/x86.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use super::bit;
2929
#[macro_export]
3030
#[doc(hidden)]
3131
macro_rules! __unstable_detect_feature {
32+
("aes", $unstable_detect_feature:path) => {
33+
$unstable_detect_feature(
34+
$crate::__vendor_runtime::__Feature::aes{}) };
3235
("mmx", $unstable_detect_feature:path) => {
3336
$unstable_detect_feature(
3437
$crate::__vendor_runtime::__Feature::mmx{}) };
@@ -168,6 +171,8 @@ macro_rules! __unstable_detect_feature {
168171
#[allow(non_camel_case_types)]
169172
#[repr(u8)]
170173
pub enum __Feature {
174+
/// AES (Advanced Encryption Standard New Instructions AES-NI)
175+
aes,
171176
/// MMX
172177
mmx,
173178
/// SSE (Streaming SIMD Extensions)
@@ -339,6 +344,7 @@ pub fn detect_features() -> usize {
339344
enable(proc_info_ecx, 19, __Feature::sse4_1);
340345
enable(proc_info_ecx, 20, __Feature::sse4_2);
341346
enable(proc_info_ecx, 23, __Feature::popcnt);
347+
enable(proc_info_ecx, 25, __Feature::aes);
342348
enable(proc_info_edx, 24, __Feature::fxsr);
343349
enable(proc_info_edx, 23, __Feature::mmx);
344350
enable(proc_info_edx, 25, __Feature::sse);
@@ -449,6 +455,7 @@ mod tests {
449455

450456
#[test]
451457
fn dump() {
458+
println!("aes: {:?}", cfg_feature_enabled!("aes"));
452459
println!("sse: {:?}", cfg_feature_enabled!("sse"));
453460
println!("sse2: {:?}", cfg_feature_enabled!("sse2"));
454461
println!("sse3: {:?}", cfg_feature_enabled!("sse3"));
@@ -488,6 +495,7 @@ mod tests {
488495
#[test]
489496
fn compare_with_cupid() {
490497
let information = cupid::master().unwrap();
498+
assert_eq!(cfg_feature_enabled!("aes"), information.aesni());
491499
assert_eq!(cfg_feature_enabled!("sse"), information.sse());
492500
assert_eq!(cfg_feature_enabled!("sse2"), information.sse2());
493501
assert_eq!(cfg_feature_enabled!("sse3"), information.sse3());

0 commit comments

Comments
 (0)