1
0
Fork 0
mirror of https://github.com/BLAKE3-team/BLAKE3 synced 2024-04-26 15:55:01 +02:00

upgrade to arrayvec 0.7.0

This version uses const generics, which bumps our minimum supported
compiler version to 1.51.
This commit is contained in:
Jack O'Connor 2021-05-18 12:28:29 -04:00
parent aa52ce3a4b
commit 037de38bfe
17 changed files with 54 additions and 54 deletions

View File

@ -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"

View File

@ -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))

View File

@ -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"

View File

@ -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))

View File

@ -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));
}

View File

@ -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<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,
@ -21,7 +21,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
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(),

View File

@ -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<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,
@ -49,7 +49,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
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(),

View File

@ -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<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,
@ -18,7 +18,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
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(),

View File

@ -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<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,
@ -49,7 +49,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
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(),

View File

@ -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<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,
@ -49,7 +49,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
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(),

View File

@ -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<CVBytes, { MAX_DEPTH + 1 }>,
}
impl Hasher {

View File

@ -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<A: arrayvec::Array<Item = u8>>(
pub fn hash_many<const N: usize>(
&self,
inputs: &[&A],
inputs: &[&[u8; N]],
key: &CVWords,
counter: u64,
increment_counter: IncrementCounter,

View File

@ -120,8 +120,8 @@ pub fn compress_xof(
crate::platform::le_bytes_from_words_64(&state)
}
pub fn hash1<A: arrayvec::Array<Item = u8>>(
input: &A,
pub fn hash1<const N: usize>(
input: &[u8; N],
key: &CVWords,
counter: u64,
flags: u8,
@ -129,10 +129,10 @@ pub fn hash1<A: arrayvec::Array<Item = u8>>(
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<A: arrayvec::Array<Item = u8>>(
*out = crate::platform::le_bytes_from_words_32(&cv);
}
pub fn hash_many<A: arrayvec::Array<Item = u8>>(
inputs: &[&A],
pub fn hash_many<const N: usize>(
inputs: &[&[u8; N]],
key: &CVWords,
mut counter: u64,
increment_counter: IncrementCounter,

View File

@ -383,8 +383,8 @@ pub unsafe fn hash8(
}
#[target_feature(enable = "avx2")]
pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
mut inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
mut inputs: &[&[u8; N]],
key: &CVWords,
mut counter: u64,
increment_counter: IncrementCounter,
@ -398,7 +398,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
// 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,

View File

@ -641,8 +641,8 @@ pub unsafe fn hash4(
}
#[target_feature(enable = "sse2")]
unsafe fn hash1<A: arrayvec::Array<Item = u8>>(
input: &A,
unsafe fn hash1<const N: usize>(
input: &[u8; N],
key: &CVWords,
counter: u64,
flags: u8,
@ -650,10 +650,10 @@ unsafe fn hash1<A: arrayvec::Array<Item = u8>>(
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<A: arrayvec::Array<Item = u8>>(
}
#[target_feature(enable = "sse2")]
pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
mut inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
mut inputs: &[&[u8; N]],
key: &CVWords,
mut counter: u64,
increment_counter: IncrementCounter,
@ -687,7 +687,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
// 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,

View File

@ -632,8 +632,8 @@ pub unsafe fn hash4(
}
#[target_feature(enable = "sse4.1")]
unsafe fn hash1<A: arrayvec::Array<Item = u8>>(
input: &A,
unsafe fn hash1<const N: usize>(
input: &[u8; N],
key: &CVWords,
counter: u64,
flags: u8,
@ -641,10 +641,10 @@ unsafe fn hash1<A: arrayvec::Array<Item = u8>>(
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<A: arrayvec::Array<Item = u8>>(
}
#[target_feature(enable = "sse4.1")]
pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
mut inputs: &[&A],
pub unsafe fn hash_many<const N: usize>(
mut inputs: &[&[u8; N]],
key: &CVWords,
mut counter: u64,
increment_counter: IncrementCounter,
@ -678,7 +678,7 @@ pub unsafe fn hash_many<A: arrayvec::Array<Item = u8>>(
// 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,

View File

@ -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));
}