diff options
Diffstat (limited to 'benches')
| -rw-r--r-- | benches/bench.rs | 162 |
1 files changed, 69 insertions, 93 deletions
diff --git a/benches/bench.rs b/benches/bench.rs index 0d73970..70be967 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -4,7 +4,7 @@ extern crate test; use arrayref::array_ref; use arrayvec::ArrayVec; -use blake3::platform::MAX_SIMD_DEGREE; +use blake3::platform::{Platform, MAX_SIMD_DEGREE}; use blake3::{BLOCK_LEN, CHUNK_LEN, OUT_LEN}; use rand::prelude::*; use test::Bencher; @@ -48,173 +48,149 @@ impl RandomInput { } } -type CompressInPlaceFn = - unsafe fn(cv: &mut [u32; 8], block: &[u8; BLOCK_LEN], block_len: u8, counter: u64, flags: u8); - -fn bench_single_compression_fn(b: &mut Bencher, f: CompressInPlaceFn) { +fn bench_single_compression_fn(b: &mut Bencher, platform: Platform) { let mut state = [1u32; 8]; let mut r = RandomInput::new(b, 64); let input = array_ref!(r.get(), 0, 64); - unsafe { - b.iter(|| f(&mut state, input, 64 as u8, 0, 0)); - } + b.iter(|| platform.compress_in_place(&mut state, input, 64 as u8, 0, 0)); } #[bench] fn bench_single_compression_portable(b: &mut Bencher) { - bench_single_compression_fn(b, blake3::portable::compress_in_place); + bench_single_compression_fn(b, Platform::portable()); } #[bench] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn bench_single_compression_sse41(b: &mut Bencher) { - if !blake3::platform::sse41_detected() { - return; + if let Some(platform) = Platform::sse41() { + bench_single_compression_fn(b, platform); } - bench_single_compression_fn(b, blake3::sse41::compress_in_place); } #[bench] -#[cfg(feature = "c_avx512")] +#[cfg(feature = "c")] fn bench_single_compression_avx512(b: &mut Bencher) { - if !blake3::platform::avx512_detected() { - return; + if let Some(platform) = Platform::avx512() { + bench_single_compression_fn(b, platform); } - bench_single_compression_fn(b, blake3::c_avx512::compress_in_place); } -type HashManyFn<A> = unsafe fn( - inputs: &[&A], - key: &[u32; 8], - counter: u64, - increment_counter: blake3::IncrementCounter, - flags: u8, - flags_start: u8, - flags_end: u8, - out: &mut [u8], -); - -fn bench_many_chunks_fn(b: &mut Bencher, f: HashManyFn<[u8; CHUNK_LEN]>, degree: usize) { +fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) { + let degree = platform.simd_degree(); let mut inputs = Vec::new(); for _ in 0..degree { inputs.push(RandomInput::new(b, CHUNK_LEN)); } - unsafe { - b.iter(|| { - let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]> = inputs - .iter_mut() - .take(degree) - .map(|i| array_ref!(i.get(), 0, CHUNK_LEN)) - .collect(); - let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN]; - f( - &input_arrays[..], - &[0; 8], - 0, - blake3::IncrementCounter::Yes, - 0, - 0, - 0, - &mut out, - ); - }); - } + b.iter(|| { + let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]> = inputs + .iter_mut() + .take(degree) + .map(|i| array_ref!(i.get(), 0, CHUNK_LEN)) + .collect(); + let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN]; + platform.hash_many( + &input_arrays[..], + &[0; 8], + 0, + blake3::IncrementCounter::Yes, + 0, + 0, + 0, + &mut out, + ); + }); } #[bench] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn bench_many_chunks_sse41(b: &mut Bencher) { - if !blake3::platform::sse41_detected() { - return; + if let Some(platform) = Platform::sse41() { + bench_many_chunks_fn(b, platform); } - bench_many_chunks_fn(b, blake3::sse41::hash_many, blake3::sse41::DEGREE); } #[bench] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn bench_many_chunks_avx2(b: &mut Bencher) { - if !blake3::platform::avx2_detected() { - return; + if let Some(platform) = Platform::avx2() { + bench_many_chunks_fn(b, platform); } - bench_many_chunks_fn(b, blake3::avx2::hash_many, blake3::avx2::DEGREE); } #[bench] -#[cfg(feature = "c_avx512")] +#[cfg(feature = "c")] fn bench_many_chunks_avx512(b: &mut Bencher) { - if !blake3::platform::avx512_detected() { - return; + if let Some(platform) = Platform::avx512() { + bench_many_chunks_fn(b, platform); } - bench_many_chunks_fn(b, blake3::c_avx512::hash_many, blake3::c_avx512::DEGREE); } #[bench] #[cfg(feature = "c_neon")] fn bench_many_chunks_neon(b: &mut Bencher) { - // When "c_neon" is on, NEON support is assumed. - bench_many_chunks_fn(b, blake3::c_neon::hash_many, blake3::c_neon::DEGREE); + if let Some(platform) = Platform::neon() { + bench_many_chunks_fn(b, platform); + } } // TODO: When we get const generics we can unify this with the chunks code. -fn bench_many_parents_fn(b: &mut Bencher, f: HashManyFn<[u8; BLOCK_LEN]>, degree: usize) { +fn bench_many_parents_fn(b: &mut Bencher, platform: Platform) { + let degree = platform.simd_degree(); let mut inputs = Vec::new(); for _ in 0..degree { inputs.push(RandomInput::new(b, BLOCK_LEN)); } - unsafe { - b.iter(|| { - let input_arrays: ArrayVec<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE]> = inputs - .iter_mut() - .take(degree) - .map(|i| array_ref!(i.get(), 0, BLOCK_LEN)) - .collect(); - let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN]; - f( - &input_arrays[..], - &[0; 8], - 0, - blake3::IncrementCounter::No, - 0, - 0, - 0, - &mut out, - ); - }); - } + b.iter(|| { + let input_arrays: ArrayVec<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE]> = inputs + .iter_mut() + .take(degree) + .map(|i| array_ref!(i.get(), 0, BLOCK_LEN)) + .collect(); + let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN]; + platform.hash_many( + &input_arrays[..], + &[0; 8], + 0, + blake3::IncrementCounter::No, + 0, + 0, + 0, + &mut out, + ); + }); } #[bench] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn bench_many_parents_sse41(b: &mut Bencher) { - if !blake3::platform::sse41_detected() { - return; + if let Some(platform) = Platform::sse41() { + bench_many_parents_fn(b, platform); } - bench_many_parents_fn(b, blake3::sse41::hash_many, blake3::sse41::DEGREE); } #[bench] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn bench_many_parents_avx2(b: &mut Bencher) { - if !blake3::platform::avx2_detected() { - return; + if let Some(platform) = Platform::avx2() { + bench_many_parents_fn(b, platform); } - bench_many_parents_fn(b, blake3::avx2::hash_many, blake3::avx2::DEGREE); } #[bench] -#[cfg(feature = "c_avx512")] +#[cfg(feature = "c")] fn bench_many_parents_avx512(b: &mut Bencher) { - if !blake3::platform::avx512_detected() { - return; + if let Some(platform) = Platform::avx512() { + bench_many_parents_fn(b, platform); } - bench_many_parents_fn(b, blake3::c_avx512::hash_many, blake3::c_avx512::DEGREE); } #[bench] #[cfg(feature = "c_neon")] fn bench_many_parents_neon(b: &mut Bencher) { - // When "c_neon" is on, NEON support is assumed. - bench_many_parents_fn(b, blake3::c_neon::hash_many, blake3::c_neon::DEGREE); + if let Some(platform) = Platform::neon() { + bench_many_parents_fn(b, platform); + } } fn bench_atonce(b: &mut Bencher, len: usize) { |
