From 4c340f515d3aac0986a32bd6d2cd6f185bbc30b1 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Wed, 18 May 2022 21:14:27 -0700 Subject: [PATCH] fix aes acceleration on aarch64 (#116) The target feature on aarch64 has been renamed from `crypto` to `aes` for newer versions of the rust compiler. Makes necessary changes to fix use of aes instructions on aarch64. --- src/hash_quality_test.rs | 2 +- src/lib.rs | 6 +++--- src/operations.rs | 4 ++-- src/random_state.rs | 8 ++++---- tests/bench.rs | 27 +++++++++++++++++++++++---- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/hash_quality_test.rs b/src/hash_quality_test.rs index 4cd3156..125c522 100644 --- a/src/hash_quality_test.rs +++ b/src/hash_quality_test.rs @@ -397,7 +397,7 @@ mod fallback_tests { ///Basic sanity tests of the cypto properties of aHash. #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") ))] #[cfg(test)] mod aes_tests { diff --git a/src/lib.rs b/src/lib.rs index f4ec909..a66e562 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ mod convert; all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), all( any(target_arch = "arm", target_arch = "aarch64"), - target_feature = "crypto", + any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd" ) @@ -80,7 +80,7 @@ mod specialize; all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), all( any(target_arch = "arm", target_arch = "aarch64"), - target_feature = "crypto", + any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd" ) @@ -91,7 +91,7 @@ pub use crate::aes_hash::AHasher; all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), all( any(target_arch = "arm", target_arch = "aarch64"), - target_feature = "crypto", + any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd" ) diff --git a/src/operations.rs b/src/operations.rs index 0b98d77..ab8f725 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -101,7 +101,7 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 { } } -#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd"))] +#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd"))] #[allow(unused)] #[inline(always)] pub(crate) fn aesenc(value: u128, xor: u128) -> u128 { @@ -131,7 +131,7 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 { } } -#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd"))] +#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd"))] #[allow(unused)] #[inline(always)] pub(crate) fn aesdec(value: u128, xor: u128) -> u128 { diff --git a/src/random_state.rs b/src/random_state.rs index 1fcf4cd..bfcc8bd 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -5,13 +5,13 @@ use crate::BuildHasherExt; #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") ))] pub use crate::aes_hash::*; #[cfg(not(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") )))] pub use crate::fallback_hash::*; @@ -36,12 +36,12 @@ use once_cell::race::OnceBox; #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") ))] use crate::aes_hash::*; #[cfg(not(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") )))] use crate::fallback_hash::*; diff --git a/tests/bench.rs b/tests/bench.rs index 9e6dccc..0b3594d 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -6,7 +6,7 @@ use std::hash::{Hash, Hasher}; #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") ))] fn aeshash(b: &H) -> u64 { let build_hasher = RandomState::with_seeds(1, 2, 3, 4); @@ -14,7 +14,7 @@ fn aeshash(b: &H) -> u64 { } #[cfg(not(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") )))] fn aeshash(_b: &H) -> u64 { panic!("aes must be enabled") @@ -22,7 +22,7 @@ fn aeshash(_b: &H) -> u64 { #[cfg(not(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") )))] fn fallbackhash(b: &H) -> u64 { let build_hasher = RandomState::with_seeds(1, 2, 3, 4); @@ -30,7 +30,7 @@ fn fallbackhash(b: &H) -> u64 { } #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd") + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") ))] fn fallbackhash(_b: &H) -> u64 { panic!("aes must be disabled") @@ -82,6 +82,7 @@ const U32_VALUE: u32 = 12345678; const U64_VALUE: u64 = 1234567890123456; const U128_VALUE: u128 = 12345678901234567890123456789012; +#[cfg(target_feature = "aes")] fn bench_ahash(c: &mut Criterion) { let mut group = c.benchmark_group("aeshash"); group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(aeshash(s)))); @@ -92,6 +93,7 @@ fn bench_ahash(c: &mut Criterion) { group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(aeshash(s)))); } +#[cfg(not(target_feature = "aes"))] fn bench_fallback(c: &mut Criterion) { let mut group = c.benchmark_group("fallback"); group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s)))); @@ -143,9 +145,26 @@ fn bench_sip(c: &mut Criterion) { } criterion_main!(benches); + +#[cfg(any( + all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") +))] criterion_group!( benches, bench_ahash, + bench_fx, + bench_fnv, + bench_sea, + bench_sip +); + +#[cfg(not(any( + all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), + all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") +)))] +criterion_group!( + benches, bench_fallback, bench_fx, bench_fnv,