1010//! - https://github.com/stillwater-sc/universal/
1111
1212use criterion:: { black_box, criterion_group, criterion_main, Criterion , Throughput } ;
13- use fast_posit:: { p32 , p64 , q32 } ;
13+ use fast_posit:: * ;
1414
1515//
1616
@@ -23,6 +23,22 @@ mod berkeley_softfloat;
2323#[ cfg( feature = "stillwater-softposit" ) ]
2424mod stillwater_softposit;
2525
26+ /// Create an array of `n` [`p8`]s.
27+ fn make_data_8 ( n : usize ) -> Box < [ p8 ] > {
28+ use fast_posit:: RoundFrom ;
29+ let rand = || p8:: from_bits ( rand:: random_range ( i8:: MIN + 1 ..= i8:: MAX ) ) ;
30+ let posits: Vec < _ > = ( 0 ..n) . map ( |_| rand ( ) ) . collect ( ) ;
31+ posits. into_boxed_slice ( )
32+ }
33+
34+ /// Create an array of `n` [`p16`]s.
35+ fn make_data_16 ( n : usize ) -> Box < [ p16 ] > {
36+ use fast_posit:: RoundFrom ;
37+ let rand = || p16:: from_bits ( rand:: random_range ( i16:: MIN + 1 ..= i16:: MAX ) ) ;
38+ let posits: Vec < _ > = ( 0 ..n) . map ( |_| rand ( ) ) . collect ( ) ;
39+ posits. into_boxed_slice ( )
40+ }
41+
2642/// Create an array of `n` [`p32`]s and an array of `n` [`f32`]s. The values of the float array
2743/// are the values of the posit array, rounded.
2844fn make_data_32 ( n : usize ) -> ( Box < [ p32 ] > , Box < [ f32 ] > ) {
@@ -256,6 +272,40 @@ fn sqrt_64(c: &mut Criterion) {
256272 g. finish ( ) ;
257273}
258274
275+ /// Generate arrays of random posits and benchmark our impl and external impls in summing them all
276+ /// into a quire.
277+ fn quire_add_8 ( c : & mut Criterion ) {
278+ let data_posit = make_data_8 ( LEN ) ;
279+ let mut g = c. benchmark_group ( "quire_add_8" ) ;
280+
281+ bench_1ary_accumulate (
282+ & mut g,
283+ "posit" ,
284+ q8:: ZERO ,
285+ & data_posit,
286+ |q : & mut q8 , x : p8 | * q += x,
287+ ) ;
288+
289+ g. finish ( ) ;
290+ }
291+
292+ /// Generate arrays of random posits and benchmark our impl and external impls in summing them all
293+ /// into a quire.
294+ fn quire_add_16 ( c : & mut Criterion ) {
295+ let data_posit = make_data_16 ( LEN ) ;
296+ let mut g = c. benchmark_group ( "quire_add_16" ) ;
297+
298+ bench_1ary_accumulate (
299+ & mut g,
300+ "posit" ,
301+ q16:: ZERO ,
302+ & data_posit,
303+ |q : & mut q16 , x : p16 | * q += x,
304+ ) ;
305+
306+ g. finish ( ) ;
307+ }
308+
259309/// Generate arrays of random posits and benchmark our impl and external impls in summing them all
260310/// into a quire.
261311fn quire_add_32 ( c : & mut Criterion ) {
@@ -282,6 +332,23 @@ fn quire_add_32(c: &mut Criterion) {
282332 g. finish ( ) ;
283333}
284334
335+ /// Generate arrays of random posits and benchmark our impl and external impls in summing them all
336+ /// into a quire.
337+ fn quire_add_64 ( c : & mut Criterion ) {
338+ let ( data_posit, _) = make_data_64 ( LEN ) ;
339+ let mut g = c. benchmark_group ( "quire_add_64" ) ;
340+
341+ bench_1ary_accumulate (
342+ & mut g,
343+ "posit" ,
344+ q64:: ZERO ,
345+ & data_posit,
346+ |q : & mut q64 , x : p64 | * q += x,
347+ ) ;
348+
349+ g. finish ( ) ;
350+ }
351+
285352criterion_group ! ( add,
286353 add_32,
287354 add_64,
@@ -303,7 +370,10 @@ criterion_group!(sqrt,
303370) ;
304371
305372criterion_group ! ( quire,
373+ quire_add_8,
374+ quire_add_16,
306375 quire_add_32,
376+ quire_add_64,
307377) ;
308378
309379criterion_main ! ( add, mul, div, sqrt, quire) ;
0 commit comments