Skip to content

Commit

Permalink
fix aes acceleration on aarch64 (#116)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brayniac committed May 19, 2022
1 parent cc927da commit 4c340f5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/hash_quality_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/random_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -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::*;

Expand Down
27 changes: 23 additions & 4 deletions tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ 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<H: Hash>(b: &H) -> u64 {
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
H::get_hash(b, &build_hasher)
}
#[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<H: Hash>(_b: &H) -> u64 {
panic!("aes must be enabled")
}

#[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<H: Hash>(b: &H) -> u64 {
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
H::get_hash(b, &build_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 fallbackhash<H: Hash>(_b: &H) -> u64 {
panic!("aes must be disabled")
Expand Down Expand Up @@ -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))));
Expand All @@ -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))));
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4c340f5

Please sign in to comment.