11//! Benchmarks that use `iai-cachegrind` to be reasonably CI-stable.
2+ #![ feature( f16) ]
3+ #![ feature( f128) ]
24
35use std:: hint:: black_box;
46
57use iai_callgrind:: { library_benchmark, library_benchmark_group, main} ;
6- use libm:: support:: { HInt , u256} ;
8+ use libm:: support:: { HInt , Hexf , hf16 , hf32 , hf64 , hf128 , u256} ;
79use libm_test:: generate:: spaced;
810use libm_test:: { CheckBasis , CheckCtx , GeneratorKind , MathOp , OpRustArgs , TupleCall , op} ;
911
@@ -109,11 +111,6 @@ fn icount_bench_u128_widen_mul(cases: Vec<(u128, u128)>) {
109111 }
110112}
111113
112- library_benchmark_group ! (
113- name = icount_bench_u128_widen_mul_group;
114- benchmarks = icount_bench_u128_widen_mul
115- ) ;
116-
117114#[ library_benchmark]
118115#[ bench:: linspace( setup_u256_add( ) ) ]
119116fn icount_bench_u256_add ( cases : Vec < ( u256 , u256 ) > ) {
@@ -122,11 +119,6 @@ fn icount_bench_u256_add(cases: Vec<(u256, u256)>) {
122119 }
123120}
124121
125- library_benchmark_group ! (
126- name = icount_bench_u256_add_group;
127- benchmarks = icount_bench_u256_add
128- ) ;
129-
130122#[ library_benchmark]
131123#[ bench:: linspace( setup_u256_shift( ) ) ]
132124fn icount_bench_u256_shr ( cases : Vec < ( u256 , u32 ) > ) {
@@ -136,16 +128,87 @@ fn icount_bench_u256_shr(cases: Vec<(u256, u32)>) {
136128}
137129
138130library_benchmark_group ! (
139- name = icount_bench_u256_shr_group;
140- benchmarks = icount_bench_u256_shr
131+ name = icount_bench_u128_group;
132+ benchmarks = icount_bench_u128_widen_mul, icount_bench_u256_add, icount_bench_u256_shr
133+ ) ;
134+
135+ #[ library_benchmark]
136+ #[ bench:: short( "0x12.34p+8" ) ]
137+ fn icount_bench_hf16 ( s : & str ) -> f16 {
138+ black_box ( hf16 ( s) )
139+ }
140+
141+ #[ library_benchmark]
142+ #[ bench:: short( "0x12.34p+8" ) ]
143+ #[ bench:: max( "0x1.fffffep+127" ) ]
144+ fn icount_bench_hf32 ( s : & str ) -> f32 {
145+ black_box ( hf32 ( s) )
146+ }
147+
148+ #[ library_benchmark]
149+ #[ bench:: short( "0x12.34p+8" ) ]
150+ #[ bench:: max( "0x1.fffffffffffffp+1023" ) ]
151+ fn icount_bench_hf64 ( s : & str ) -> f64 {
152+ black_box ( hf64 ( s) )
153+ }
154+
155+ #[ library_benchmark]
156+ #[ bench:: short( "0x12.34p+8" ) ]
157+ #[ bench:: max( "0x1.ffffffffffffffffffffffffffffp+16383" ) ]
158+ fn icount_bench_hf128 ( s : & str ) -> f128 {
159+ black_box ( hf128 ( s) )
160+ }
161+
162+ library_benchmark_group ! (
163+ name = icount_bench_hf_parse_group;
164+ benchmarks =
165+ icount_bench_hf16,
166+ icount_bench_hf32,
167+ icount_bench_hf64,
168+ icount_bench_hf128
169+ ) ;
170+
171+ #[ library_benchmark]
172+ #[ bench:: short( hf16!( "0x12.34p+8" ) ) ]
173+ fn icount_bench_print_hf16 ( x : f16 ) -> String {
174+ black_box ( Hexf ( x) . to_string ( ) )
175+ }
176+
177+ #[ library_benchmark]
178+ #[ bench:: short( hf32!( "0x12.34p+8" ) ) ]
179+ #[ bench:: max( hf32!( "0x1.fffffep+127" ) ) ]
180+ fn icount_bench_print_hf32 ( x : f32 ) -> String {
181+ black_box ( Hexf ( x) . to_string ( ) )
182+ }
183+
184+ #[ library_benchmark]
185+ #[ bench:: short( hf64!( "0x12.34p+8" ) ) ]
186+ #[ bench:: max( hf64!( "0x1.fffffffffffffp+1023" ) ) ]
187+ fn icount_bench_print_hf64 ( x : f64 ) -> String {
188+ black_box ( Hexf ( x) . to_string ( ) )
189+ }
190+
191+ #[ library_benchmark]
192+ #[ bench:: short( hf128!( "0x12.34p+8" ) ) ]
193+ #[ bench:: max( hf128!( "0x1.ffffffffffffffffffffffffffffp+16383" ) ) ]
194+ fn icount_bench_print_hf128 ( x : f128 ) -> String {
195+ black_box ( Hexf ( x) . to_string ( ) )
196+ }
197+ library_benchmark_group ! (
198+ name = icount_bench_hf_print_group;
199+ benchmarks =
200+ icount_bench_print_hf16,
201+ icount_bench_print_hf32,
202+ icount_bench_print_hf64,
203+ icount_bench_print_hf128
141204) ;
142205
143206main ! (
144207 library_benchmark_groups =
145- // u256-related benchmarks
146- icount_bench_u128_widen_mul_group ,
147- icount_bench_u256_add_group ,
148- icount_bench_u256_shr_group ,
208+ // non-float benchmarks
209+ icount_bench_u128_group ,
210+ icount_bench_hf_parse_group ,
211+ icount_bench_hf_print_group ,
149212 // verify-apilist-start
150213 // verify-sorted-start
151214 icount_bench_acos_group,
0 commit comments