Skip to content

Commit

Permalink
factor out the blake3 crate changes from the guts_api branch
Browse files Browse the repository at this point in the history
This commit and the branch that it starts are unlikely to land as-is,
but I want to maintain them while I flesh out the new `blake3_guts`
sub-crate.
  • Loading branch information
oconnor663 committed Jan 22, 2024
1 parent 5558fa4 commit bd160e3
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 825 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ no_neon = []
features = ["mmap", "rayon", "serde", "zeroize"]

[dependencies]
arrayref = "0.3.5"
arrayvec = { version = "0.7.4", default-features = false }
blake3_guts = { path = "rust/guts" }
constant_time_eq = "0.3.0"
cfg-if = "1.0.0"
digest = { version = "0.10.1", features = [ "mac" ], optional = true }
Expand Down
12 changes: 5 additions & 7 deletions b3sum/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion b3sum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn write_hex_output(mut output: blake3::OutputReader, args: &Args) -> Result<()>
// TODO: This computes each output block twice when the --seek argument isn't a multiple of 64.
// We'll refactor all of this soon anyway, once SIMD optimizations are available for the XOF.
let mut len = args.len();
let mut block = [0; blake3::guts::BLOCK_LEN];
let mut block = [0; 64];
while len > 0 {
output.fill(&mut block);
let hex_str = hex::encode(&block[..]);
Expand Down
175 changes: 1 addition & 174 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

extern crate test;

use arrayref::array_ref;
use arrayvec::ArrayVec;
use blake3::guts::{BLOCK_LEN, CHUNK_LEN};
use blake3::platform::{Platform, MAX_SIMD_DEGREE};
use blake3::OUT_LEN;
use blake3_guts::BLOCK_LEN;
use rand::prelude::*;
use test::Bencher;

Expand Down Expand Up @@ -49,175 +45,6 @@ impl RandomInput {
}
}

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);
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, Platform::portable());
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_single_compression_sse2(b: &mut Bencher) {
if let Some(platform) = Platform::sse2() {
bench_single_compression_fn(b, platform);
}
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_single_compression_sse41(b: &mut Bencher) {
if let Some(platform) = Platform::sse41() {
bench_single_compression_fn(b, platform);
}
}

#[bench]
#[cfg(blake3_avx512_ffi)]
fn bench_single_compression_avx512(b: &mut Bencher) {
if let Some(platform) = Platform::avx512() {
bench_single_compression_fn(b, platform);
}
}

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));
}
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_sse2(b: &mut Bencher) {
if let Some(platform) = Platform::sse2() {
bench_many_chunks_fn(b, platform);
}
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_many_chunks_sse41(b: &mut Bencher) {
if let Some(platform) = Platform::sse41() {
bench_many_chunks_fn(b, platform);
}
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_many_chunks_avx2(b: &mut Bencher) {
if let Some(platform) = Platform::avx2() {
bench_many_chunks_fn(b, platform);
}
}

#[bench]
#[cfg(blake3_avx512_ffi)]
fn bench_many_chunks_avx512(b: &mut Bencher) {
if let Some(platform) = Platform::avx512() {
bench_many_chunks_fn(b, platform);
}
}

#[bench]
#[cfg(feature = "neon")]
fn bench_many_chunks_neon(b: &mut Bencher) {
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, platform: Platform) {
let degree = platform.simd_degree();
let mut inputs = Vec::new();
for _ in 0..degree {
inputs.push(RandomInput::new(b, BLOCK_LEN));
}
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_sse2(b: &mut Bencher) {
if let Some(platform) = Platform::sse2() {
bench_many_parents_fn(b, platform);
}
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_many_parents_sse41(b: &mut Bencher) {
if let Some(platform) = Platform::sse41() {
bench_many_parents_fn(b, platform);
}
}

#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn bench_many_parents_avx2(b: &mut Bencher) {
if let Some(platform) = Platform::avx2() {
bench_many_parents_fn(b, platform);
}
}

#[bench]
#[cfg(blake3_avx512_ffi)]
fn bench_many_parents_avx512(b: &mut Bencher) {
if let Some(platform) = Platform::avx512() {
bench_many_parents_fn(b, platform);
}
}

#[bench]
#[cfg(feature = "neon")]
fn bench_many_parents_neon(b: &mut Bencher) {
if let Some(platform) = Platform::neon() {
bench_many_parents_fn(b, platform);
}
}

fn bench_atonce(b: &mut Bencher, len: usize) {
let mut input = RandomInput::new(b, len);
b.iter(|| blake3::hash(input.get()));
Expand Down
Loading

0 comments on commit bd160e3

Please sign in to comment.