Debian Codegraph @

debian/rust-vendor/blake3/src/ffi_avx2.rs

raw
1 use crate::{BLOCK_LEN, CVWords, IncrementCounter, OUT_LEN};
2
3 // Note that there is no AVX2 implementation of compress_in_place or
4 // compress_xof.
5
6 // Unsafe because this may only be called on platforms supporting AVX2.
7 pub unsafe fn hash_many<const N: usize>(
8 inputs: &[&[u8; N]],
9 key: &CVWords,
10 counter: u64,
11 increment_counter: IncrementCounter,
12 flags: u8,
13 flags_start: u8,
14 flags_end: u8,
15 out: &mut [u8],
16 ) {
17 unsafe {
18 // The Rust hash_many implementations do bounds checking on the `out`
19 // array, but the C implementations don't. Even though this is an unsafe
20 // function, assert the bounds here.
21 assert!(out.len() >= inputs.len() * OUT_LEN);
22 ffi::blake3_hash_many_avx2(
23 inputs.as_ptr() as *const *const u8,
24 inputs.len(),
25 N / BLOCK_LEN,
26 key.as_ptr(),
27 counter,
28 increment_counter.yes(),
29 flags,
30 flags_start,
31 flags_end,
32 out.as_mut_ptr(),
33 )
34 }
35 }
36
37 pub mod ffi {
38 unsafe extern "C" {
39 pub fn blake3_hash_many_avx2(
40 inputs: *const *const u8,
41 num_inputs: usize,
42 blocks: usize,
43 key: *const u32,
44 counter: u64,
45 increment_counter: bool,
46 flags: u8,
47 flags_start: u8,
48 flags_end: u8,
49 out: *mut u8,
50 );
51 }
52 }
53
54 #[cfg(test)]
55 mod test {
56 use super::*;
57
58 #[test]
59 fn test_hash_many() {
60 if !crate::platform::avx2_detected() {
61 return;
62 }
63 crate::test::test_hash_many_fn(hash_many, hash_many);
64 }
65 }