diff --git a/Cargo.toml b/Cargo.toml index 9d21b26..3c11c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ features = ["rayon"] [dependencies] arrayref = "0.3.5" -arrayvec = { version = "0.5.1", default-features = false, features = ["array-sizes-33-128"] } +arrayvec = { version = "0.7.0", default-features = false } constant_time_eq = "0.1.5" rayon = { version = "1.2.1", optional = true } cfg-if = "1.0.0" diff --git a/benches/bench.rs b/benches/bench.rs index 9038a94..5efb9e6 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -92,7 +92,7 @@ fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) { inputs.push(RandomInput::new(b, CHUNK_LEN)); } b.iter(|| { - let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]> = inputs + let input_arrays: ArrayVec<&[u8; CHUNK_LEN], MAX_SIMD_DEGREE> = inputs .iter_mut() .take(degree) .map(|i| array_ref!(i.get(), 0, CHUNK_LEN)) @@ -159,7 +159,7 @@ fn bench_many_parents_fn(b: &mut Bencher, platform: Platform) { inputs.push(RandomInput::new(b, BLOCK_LEN)); } b.iter(|| { - let input_arrays: ArrayVec<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE]> = inputs + let input_arrays: ArrayVec<&[u8; BLOCK_LEN], MAX_SIMD_DEGREE> = inputs .iter_mut() .take(degree) .map(|i| array_ref!(i.get(), 0, BLOCK_LEN)) diff --git a/c/blake3_c_rust_bindings/Cargo.toml b/c/blake3_c_rust_bindings/Cargo.toml index 2052c74..a5f0e97 100644 --- a/c/blake3_c_rust_bindings/Cargo.toml +++ b/c/blake3_c_rust_bindings/Cargo.toml @@ -19,7 +19,7 @@ neon = [] [dev-dependencies] arrayref = "0.3.5" -arrayvec = { version = "0.5.1", default-features = false, features = ["array-sizes-33-128"] } +arrayvec = { version = "0.7.0", default-features = false } page_size = "0.4.1" rand = "0.7.2" rand_chacha = "0.2.1" diff --git a/c/blake3_c_rust_bindings/benches/bench.rs b/c/blake3_c_rust_bindings/benches/bench.rs index 119bd20..6e75351 100644 --- a/c/blake3_c_rust_bindings/benches/bench.rs +++ b/c/blake3_c_rust_bindings/benches/bench.rs @@ -123,7 +123,7 @@ fn bench_many_chunks_fn(b: &mut Bencher, f: HashManyFn, degree: usize) { inputs.push(RandomInput::new(b, CHUNK_LEN)); } b.iter(|| { - let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]> = inputs + let input_arrays: ArrayVec<&[u8; CHUNK_LEN], MAX_SIMD_DEGREE> = inputs .iter_mut() .take(degree) .map(|i| array_ref!(i.get(), 0, CHUNK_LEN)) @@ -215,7 +215,7 @@ fn bench_many_parents_fn(b: &mut Bencher, f: HashManyFn, degree: usize) { inputs.push(RandomInput::new(b, BLOCK_LEN)); } b.iter(|| { - let input_arrays: ArrayVec<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE]> = inputs + let input_arrays: ArrayVec<&[u8; BLOCK_LEN], MAX_SIMD_DEGREE> = inputs .iter_mut() .take(degree) .map(|i| array_ref!(i.get(), 0, BLOCK_LEN)) diff --git a/c/blake3_c_rust_bindings/src/test.rs b/c/blake3_c_rust_bindings/src/test.rs index b989ae9..3b3d8a7 100644 --- a/c/blake3_c_rust_bindings/src/test.rs +++ b/c/blake3_c_rust_bindings/src/test.rs @@ -215,7 +215,7 @@ pub fn test_hash_many_fn(hash_many_fn: HashManyFn) { let counter = (1u64 << 32) - 1; // First hash chunks. - let mut chunks = ArrayVec::<[&[u8; CHUNK_LEN]; NUM_INPUTS]>::new(); + let mut chunks = ArrayVec::<&[u8; CHUNK_LEN], NUM_INPUTS>::new(); for i in 0..NUM_INPUTS { chunks.push(array_ref!(input_buf, i * CHUNK_LEN, CHUNK_LEN)); } @@ -259,7 +259,7 @@ pub fn test_hash_many_fn(hash_many_fn: HashManyFn) { } // Then hash parents. - let mut parents = ArrayVec::<[&[u8; 2 * OUT_LEN]; NUM_INPUTS]>::new(); + let mut parents = ArrayVec::<&[u8; 2 * OUT_LEN], NUM_INPUTS>::new(); for i in 0..NUM_INPUTS { parents.push(array_ref!(input_buf, i * 2 * OUT_LEN, 2 * OUT_LEN)); } diff --git a/src/ffi_avx2.rs b/src/ffi_avx2.rs index d805e86..33961e9 100644 --- a/src/ffi_avx2.rs +++ b/src/ffi_avx2.rs @@ -4,8 +4,8 @@ use crate::{CVWords, IncrementCounter, BLOCK_LEN, OUT_LEN}; // compress_xof. // Unsafe because this may only be called on platforms supporting AVX2. -pub unsafe fn hash_many>( - inputs: &[&A], +pub unsafe fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, @@ -21,7 +21,7 @@ pub unsafe fn hash_many>( ffi::blake3_hash_many_avx2( inputs.as_ptr() as *const *const u8, inputs.len(), - A::CAPACITY / BLOCK_LEN, + N / BLOCK_LEN, key.as_ptr(), counter, increment_counter.yes(), diff --git a/src/ffi_avx512.rs b/src/ffi_avx512.rs index c1b9f64..884f481 100644 --- a/src/ffi_avx512.rs +++ b/src/ffi_avx512.rs @@ -32,8 +32,8 @@ pub unsafe fn compress_xof( } // Unsafe because this may only be called on platforms supporting AVX-512. -pub unsafe fn hash_many>( - inputs: &[&A], +pub unsafe fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, @@ -49,7 +49,7 @@ pub unsafe fn hash_many>( ffi::blake3_hash_many_avx512( inputs.as_ptr() as *const *const u8, inputs.len(), - A::CAPACITY / BLOCK_LEN, + N / BLOCK_LEN, key.as_ptr(), counter, increment_counter.yes(), diff --git a/src/ffi_neon.rs b/src/ffi_neon.rs index 8899742..54d07a4 100644 --- a/src/ffi_neon.rs +++ b/src/ffi_neon.rs @@ -1,8 +1,8 @@ use crate::{CVWords, IncrementCounter, BLOCK_LEN, OUT_LEN}; // Unsafe because this may only be called on platforms supporting NEON. -pub unsafe fn hash_many>( - inputs: &[&A], +pub unsafe fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, @@ -18,7 +18,7 @@ pub unsafe fn hash_many>( ffi::blake3_hash_many_neon( inputs.as_ptr() as *const *const u8, inputs.len(), - A::CAPACITY / BLOCK_LEN, + N / BLOCK_LEN, key.as_ptr(), counter, increment_counter.yes(), diff --git a/src/ffi_sse2.rs b/src/ffi_sse2.rs index c49a229..1c5da81 100644 --- a/src/ffi_sse2.rs +++ b/src/ffi_sse2.rs @@ -32,8 +32,8 @@ pub unsafe fn compress_xof( } // Unsafe because this may only be called on platforms supporting SSE2. -pub unsafe fn hash_many>( - inputs: &[&A], +pub unsafe fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, @@ -49,7 +49,7 @@ pub unsafe fn hash_many>( ffi::blake3_hash_many_sse2( inputs.as_ptr() as *const *const u8, inputs.len(), - A::CAPACITY / BLOCK_LEN, + N / BLOCK_LEN, key.as_ptr(), counter, increment_counter.yes(), diff --git a/src/ffi_sse41.rs b/src/ffi_sse41.rs index 0b64c90..62989c5 100644 --- a/src/ffi_sse41.rs +++ b/src/ffi_sse41.rs @@ -32,8 +32,8 @@ pub unsafe fn compress_xof( } // Unsafe because this may only be called on platforms supporting SSE4.1. -pub unsafe fn hash_many>( - inputs: &[&A], +pub unsafe fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, @@ -49,7 +49,7 @@ pub unsafe fn hash_many>( ffi::blake3_hash_many_sse41( inputs.as_ptr() as *const *const u8, inputs.len(), - A::CAPACITY / BLOCK_LEN, + N / BLOCK_LEN, key.as_ptr(), counter, increment_counter.yes(), diff --git a/src/lib.rs b/src/lib.rs index 9dacdcb..0b40c3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,7 +218,7 @@ impl Hash { /// type. /// /// [`ArrayString`]: https://docs.rs/arrayvec/0.5.1/arrayvec/struct.ArrayString.html - pub fn to_hex(&self) -> ArrayString<[u8; 2 * OUT_LEN]> { + pub fn to_hex(&self) -> ArrayString<{ 2 * OUT_LEN }> { let mut s = ArrayString::new(); let table = b"0123456789abcdef"; for &b in self.0.iter() { @@ -584,7 +584,7 @@ fn compress_chunks_parallel( debug_assert!(input.len() <= MAX_SIMD_DEGREE * CHUNK_LEN); let mut chunks_exact = input.chunks_exact(CHUNK_LEN); - let mut chunks_array = ArrayVec::<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]>::new(); + let mut chunks_array = ArrayVec::<&[u8; CHUNK_LEN], MAX_SIMD_DEGREE>::new(); for chunk in &mut chunks_exact { chunks_array.push(array_ref!(chunk, 0, CHUNK_LEN)); } @@ -634,7 +634,7 @@ fn compress_parents_parallel( let mut parents_exact = child_chaining_values.chunks_exact(BLOCK_LEN); // Use MAX_SIMD_DEGREE_OR_2 rather than MAX_SIMD_DEGREE here, because of // the requirements of compress_subtree_wide(). - let mut parents_array = ArrayVec::<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE_OR_2]>::new(); + let mut parents_array = ArrayVec::<&[u8; BLOCK_LEN], MAX_SIMD_DEGREE_OR_2>::new(); for parent in &mut parents_exact { parents_array.push(array_ref!(parent, 0, BLOCK_LEN)); } @@ -947,7 +947,7 @@ pub struct Hasher { // requires a 4th entry, rather than merging everything down to 1, because // we don't know whether more input is coming. This is different from how // the reference implementation does things. - cv_stack: ArrayVec<[CVBytes; MAX_DEPTH + 1]>, + cv_stack: ArrayVec, } impl Hasher { diff --git a/src/platform.rs b/src/platform.rs index 4bd67de..1a732c5 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -176,9 +176,9 @@ impl Platform { // after every block, there's a small but measurable performance loss. // Compressing chunks with a dedicated loop avoids this. - pub fn hash_many>( + pub fn hash_many( &self, - inputs: &[&A], + inputs: &[&[u8; N]], key: &CVWords, counter: u64, increment_counter: IncrementCounter, diff --git a/src/portable.rs b/src/portable.rs index 0a569ce..7af6828 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -120,8 +120,8 @@ pub fn compress_xof( crate::platform::le_bytes_from_words_64(&state) } -pub fn hash1>( - input: &A, +pub fn hash1( + input: &[u8; N], key: &CVWords, counter: u64, flags: u8, @@ -129,10 +129,10 @@ pub fn hash1>( flags_end: u8, out: &mut CVBytes, ) { - debug_assert_eq!(A::CAPACITY % BLOCK_LEN, 0, "uneven blocks"); + debug_assert_eq!(N % BLOCK_LEN, 0, "uneven blocks"); let mut cv = *key; let mut block_flags = flags | flags_start; - let mut slice = input.as_slice(); + let mut slice = &input[..]; while slice.len() >= BLOCK_LEN { if slice.len() == BLOCK_LEN { block_flags |= flags_end; @@ -150,8 +150,8 @@ pub fn hash1>( *out = crate::platform::le_bytes_from_words_32(&cv); } -pub fn hash_many>( - inputs: &[&A], +pub fn hash_many( + inputs: &[&[u8; N]], key: &CVWords, mut counter: u64, increment_counter: IncrementCounter, diff --git a/src/rust_avx2.rs b/src/rust_avx2.rs index 6ab773a..6290e70 100644 --- a/src/rust_avx2.rs +++ b/src/rust_avx2.rs @@ -383,8 +383,8 @@ pub unsafe fn hash8( } #[target_feature(enable = "avx2")] -pub unsafe fn hash_many>( - mut inputs: &[&A], +pub unsafe fn hash_many( + mut inputs: &[&[u8; N]], key: &CVWords, mut counter: u64, increment_counter: IncrementCounter, @@ -398,7 +398,7 @@ pub unsafe fn hash_many>( // Safe because the layout of arrays is guaranteed, and because the // `blocks` count is determined statically from the argument type. let input_ptrs: &[*const u8; DEGREE] = &*(inputs.as_ptr() as *const [*const u8; DEGREE]); - let blocks = A::CAPACITY / BLOCK_LEN; + let blocks = N / BLOCK_LEN; hash8( input_ptrs, blocks, diff --git a/src/rust_sse2.rs b/src/rust_sse2.rs index 15b52ee..ec282d0 100644 --- a/src/rust_sse2.rs +++ b/src/rust_sse2.rs @@ -641,8 +641,8 @@ pub unsafe fn hash4( } #[target_feature(enable = "sse2")] -unsafe fn hash1>( - input: &A, +unsafe fn hash1( + input: &[u8; N], key: &CVWords, counter: u64, flags: u8, @@ -650,10 +650,10 @@ unsafe fn hash1>( flags_end: u8, out: &mut CVBytes, ) { - debug_assert_eq!(A::CAPACITY % BLOCK_LEN, 0, "uneven blocks"); + debug_assert_eq!(N % BLOCK_LEN, 0, "uneven blocks"); let mut cv = *key; let mut block_flags = flags | flags_start; - let mut slice = input.as_slice(); + let mut slice = &input[..]; while slice.len() >= BLOCK_LEN { if slice.len() == BLOCK_LEN { block_flags |= flags_end; @@ -672,8 +672,8 @@ unsafe fn hash1>( } #[target_feature(enable = "sse2")] -pub unsafe fn hash_many>( - mut inputs: &[&A], +pub unsafe fn hash_many( + mut inputs: &[&[u8; N]], key: &CVWords, mut counter: u64, increment_counter: IncrementCounter, @@ -687,7 +687,7 @@ pub unsafe fn hash_many>( // Safe because the layout of arrays is guaranteed, and because the // `blocks` count is determined statically from the argument type. let input_ptrs: &[*const u8; DEGREE] = &*(inputs.as_ptr() as *const [*const u8; DEGREE]); - let blocks = A::CAPACITY / BLOCK_LEN; + let blocks = N / BLOCK_LEN; hash4( input_ptrs, blocks, diff --git a/src/rust_sse41.rs b/src/rust_sse41.rs index d5cf0f4..4b27f41 100644 --- a/src/rust_sse41.rs +++ b/src/rust_sse41.rs @@ -632,8 +632,8 @@ pub unsafe fn hash4( } #[target_feature(enable = "sse4.1")] -unsafe fn hash1>( - input: &A, +unsafe fn hash1( + input: &[u8; N], key: &CVWords, counter: u64, flags: u8, @@ -641,10 +641,10 @@ unsafe fn hash1>( flags_end: u8, out: &mut CVBytes, ) { - debug_assert_eq!(A::CAPACITY % BLOCK_LEN, 0, "uneven blocks"); + debug_assert_eq!(N % BLOCK_LEN, 0, "uneven blocks"); let mut cv = *key; let mut block_flags = flags | flags_start; - let mut slice = input.as_slice(); + let mut slice = &input[..]; while slice.len() >= BLOCK_LEN { if slice.len() == BLOCK_LEN { block_flags |= flags_end; @@ -663,8 +663,8 @@ unsafe fn hash1>( } #[target_feature(enable = "sse4.1")] -pub unsafe fn hash_many>( - mut inputs: &[&A], +pub unsafe fn hash_many( + mut inputs: &[&[u8; N]], key: &CVWords, mut counter: u64, increment_counter: IncrementCounter, @@ -678,7 +678,7 @@ pub unsafe fn hash_many>( // Safe because the layout of arrays is guaranteed, and because the // `blocks` count is determined statically from the argument type. let input_ptrs: &[*const u8; DEGREE] = &*(inputs.as_ptr() as *const [*const u8; DEGREE]); - let blocks = A::CAPACITY / BLOCK_LEN; + let blocks = N / BLOCK_LEN; hash4( input_ptrs, blocks, diff --git a/src/test.rs b/src/test.rs index b16e043..cbe0188 100644 --- a/src/test.rs +++ b/src/test.rs @@ -119,7 +119,7 @@ pub fn test_hash_many_fn( let counter = (1u64 << 32) - 1; // First hash chunks. - let mut chunks = ArrayVec::<[&[u8; CHUNK_LEN]; NUM_INPUTS]>::new(); + let mut chunks = ArrayVec::<&[u8; CHUNK_LEN], NUM_INPUTS>::new(); for i in 0..NUM_INPUTS { chunks.push(array_ref!(input_buf, i * CHUNK_LEN, CHUNK_LEN)); } @@ -158,7 +158,7 @@ pub fn test_hash_many_fn( } // Then hash parents. - let mut parents = ArrayVec::<[&[u8; 2 * OUT_LEN]; NUM_INPUTS]>::new(); + let mut parents = ArrayVec::<&[u8; 2 * OUT_LEN], NUM_INPUTS>::new(); for i in 0..NUM_INPUTS { parents.push(array_ref!(input_buf, i * 2 * OUT_LEN, 2 * OUT_LEN)); }