|
2 | 2 |
|
3 | 3 | extern crate test; |
4 | 4 |
|
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; |
10 | 6 | use rand::prelude::*; |
11 | 7 | use test::Bencher; |
12 | 8 |
|
@@ -49,175 +45,6 @@ impl RandomInput { |
49 | 45 | } |
50 | 46 | } |
51 | 47 |
|
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 | | - |
221 | 48 | fn bench_atonce(b: &mut Bencher, len: usize) { |
222 | 49 | let mut input = RandomInput::new(b, len); |
223 | 50 | b.iter(|| blake3::hash(input.get())); |
|
0 commit comments