Skip to content

Commit 67e64d5

Browse files
committed
factor out the blake3 crate changes from the guts_api branch
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.
1 parent 5558fa4 commit 67e64d5

File tree

9 files changed

+337
-824
lines changed

9 files changed

+337
-824
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ no_neon = []
9292
features = ["mmap", "rayon", "serde", "zeroize"]
9393

9494
[dependencies]
95-
arrayref = "0.3.5"
9695
arrayvec = { version = "0.7.4", default-features = false }
96+
blake3_guts = { path = "rust/guts" }
9797
constant_time_eq = "0.3.0"
9898
cfg-if = "1.0.0"
9999
digest = { version = "0.10.1", features = [ "mac" ], optional = true }

b3sum/Cargo.lock

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

b3sum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn write_hex_output(mut output: blake3::OutputReader, args: &Args) -> Result<()>
186186
// TODO: This computes each output block twice when the --seek argument isn't a multiple of 64.
187187
// We'll refactor all of this soon anyway, once SIMD optimizations are available for the XOF.
188188
let mut len = args.len();
189-
let mut block = [0; blake3::guts::BLOCK_LEN];
189+
let mut block = [0; 64];
190190
while len > 0 {
191191
output.fill(&mut block);
192192
let hex_str = hex::encode(&block[..]);

benches/bench.rs

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
extern crate test;
44

5-
use arrayref::array_ref;
6-
use arrayvec::ArrayVec;
7-
use blake3::guts::{BLOCK_LEN, CHUNK_LEN};
8-
use blake3::platform::{Platform, MAX_SIMD_DEGREE};
9-
use blake3::OUT_LEN;
5+
use blake3_guts::BLOCK_LEN;
106
use rand::prelude::*;
117
use test::Bencher;
128

@@ -49,175 +45,6 @@ impl RandomInput {
4945
}
5046
}
5147

52-
fn bench_single_compression_fn(b: &mut Bencher, platform: Platform) {
53-
let mut state = [1u32; 8];
54-
let mut r = RandomInput::new(b, 64);
55-
let input = array_ref!(r.get(), 0, 64);
56-
b.iter(|| platform.compress_in_place(&mut state, input, 64 as u8, 0, 0));
57-
}
58-
59-
#[bench]
60-
fn bench_single_compression_portable(b: &mut Bencher) {
61-
bench_single_compression_fn(b, Platform::portable());
62-
}
63-
64-
#[bench]
65-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
66-
fn bench_single_compression_sse2(b: &mut Bencher) {
67-
if let Some(platform) = Platform::sse2() {
68-
bench_single_compression_fn(b, platform);
69-
}
70-
}
71-
72-
#[bench]
73-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
74-
fn bench_single_compression_sse41(b: &mut Bencher) {
75-
if let Some(platform) = Platform::sse41() {
76-
bench_single_compression_fn(b, platform);
77-
}
78-
}
79-
80-
#[bench]
81-
#[cfg(blake3_avx512_ffi)]
82-
fn bench_single_compression_avx512(b: &mut Bencher) {
83-
if let Some(platform) = Platform::avx512() {
84-
bench_single_compression_fn(b, platform);
85-
}
86-
}
87-
88-
fn bench_many_chunks_fn(b: &mut Bencher, platform: Platform) {
89-
let degree = platform.simd_degree();
90-
let mut inputs = Vec::new();
91-
for _ in 0..degree {
92-
inputs.push(RandomInput::new(b, CHUNK_LEN));
93-
}
94-
b.iter(|| {
95-
let input_arrays: ArrayVec<&[u8; CHUNK_LEN], MAX_SIMD_DEGREE> = inputs
96-
.iter_mut()
97-
.take(degree)
98-
.map(|i| array_ref!(i.get(), 0, CHUNK_LEN))
99-
.collect();
100-
let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
101-
platform.hash_many(
102-
&input_arrays[..],
103-
&[0; 8],
104-
0,
105-
blake3::IncrementCounter::Yes,
106-
0,
107-
0,
108-
0,
109-
&mut out,
110-
);
111-
});
112-
}
113-
114-
#[bench]
115-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
116-
fn bench_many_chunks_sse2(b: &mut Bencher) {
117-
if let Some(platform) = Platform::sse2() {
118-
bench_many_chunks_fn(b, platform);
119-
}
120-
}
121-
122-
#[bench]
123-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
124-
fn bench_many_chunks_sse41(b: &mut Bencher) {
125-
if let Some(platform) = Platform::sse41() {
126-
bench_many_chunks_fn(b, platform);
127-
}
128-
}
129-
130-
#[bench]
131-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
132-
fn bench_many_chunks_avx2(b: &mut Bencher) {
133-
if let Some(platform) = Platform::avx2() {
134-
bench_many_chunks_fn(b, platform);
135-
}
136-
}
137-
138-
#[bench]
139-
#[cfg(blake3_avx512_ffi)]
140-
fn bench_many_chunks_avx512(b: &mut Bencher) {
141-
if let Some(platform) = Platform::avx512() {
142-
bench_many_chunks_fn(b, platform);
143-
}
144-
}
145-
146-
#[bench]
147-
#[cfg(feature = "neon")]
148-
fn bench_many_chunks_neon(b: &mut Bencher) {
149-
if let Some(platform) = Platform::neon() {
150-
bench_many_chunks_fn(b, platform);
151-
}
152-
}
153-
154-
// TODO: When we get const generics we can unify this with the chunks code.
155-
fn bench_many_parents_fn(b: &mut Bencher, platform: Platform) {
156-
let degree = platform.simd_degree();
157-
let mut inputs = Vec::new();
158-
for _ in 0..degree {
159-
inputs.push(RandomInput::new(b, BLOCK_LEN));
160-
}
161-
b.iter(|| {
162-
let input_arrays: ArrayVec<&[u8; BLOCK_LEN], MAX_SIMD_DEGREE> = inputs
163-
.iter_mut()
164-
.take(degree)
165-
.map(|i| array_ref!(i.get(), 0, BLOCK_LEN))
166-
.collect();
167-
let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
168-
platform.hash_many(
169-
&input_arrays[..],
170-
&[0; 8],
171-
0,
172-
blake3::IncrementCounter::No,
173-
0,
174-
0,
175-
0,
176-
&mut out,
177-
);
178-
});
179-
}
180-
181-
#[bench]
182-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
183-
fn bench_many_parents_sse2(b: &mut Bencher) {
184-
if let Some(platform) = Platform::sse2() {
185-
bench_many_parents_fn(b, platform);
186-
}
187-
}
188-
189-
#[bench]
190-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
191-
fn bench_many_parents_sse41(b: &mut Bencher) {
192-
if let Some(platform) = Platform::sse41() {
193-
bench_many_parents_fn(b, platform);
194-
}
195-
}
196-
197-
#[bench]
198-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
199-
fn bench_many_parents_avx2(b: &mut Bencher) {
200-
if let Some(platform) = Platform::avx2() {
201-
bench_many_parents_fn(b, platform);
202-
}
203-
}
204-
205-
#[bench]
206-
#[cfg(blake3_avx512_ffi)]
207-
fn bench_many_parents_avx512(b: &mut Bencher) {
208-
if let Some(platform) = Platform::avx512() {
209-
bench_many_parents_fn(b, platform);
210-
}
211-
}
212-
213-
#[bench]
214-
#[cfg(feature = "neon")]
215-
fn bench_many_parents_neon(b: &mut Bencher) {
216-
if let Some(platform) = Platform::neon() {
217-
bench_many_parents_fn(b, platform);
218-
}
219-
}
220-
22148
fn bench_atonce(b: &mut Bencher, len: usize) {
22249
let mut input = RandomInput::new(b, len);
22350
b.iter(|| blake3::hash(input.get()));

0 commit comments

Comments
 (0)