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,90 @@ 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+ #[ bench:: max( "0x1.ffcp+15" ) ]
138+ fn icount_bench_hf16 ( s : & str ) -> f16 {
139+ black_box ( hf16 ( s) )
140+ }
141+
142+ #[ library_benchmark]
143+ #[ bench:: short( "0x12.34p+8" ) ]
144+ #[ bench:: max( "0x1.fffffep+127" ) ]
145+ fn icount_bench_hf32 ( s : & str ) -> f32 {
146+ black_box ( hf32 ( s) )
147+ }
148+
149+ #[ library_benchmark]
150+ #[ bench:: short( "0x12.34p+8" ) ]
151+ #[ bench:: max( "0x1.fffffffffffffp+1023" ) ]
152+ fn icount_bench_hf64 ( s : & str ) -> f64 {
153+ black_box ( hf64 ( s) )
154+ }
155+
156+ #[ library_benchmark]
157+ #[ bench:: short( "0x12.34p+8" ) ]
158+ #[ bench:: max( "0x1.ffffffffffffffffffffffffffffp+16383" ) ]
159+ fn icount_bench_hf128 ( s : & str ) -> f128 {
160+ black_box ( hf128 ( s) )
161+ }
162+
163+ library_benchmark_group ! (
164+ name = icount_bench_hf_parse_group;
165+ benchmarks =
166+ icount_bench_hf16,
167+ icount_bench_hf32,
168+ icount_bench_hf64,
169+ icount_bench_hf128
170+ ) ;
171+
172+ #[ library_benchmark]
173+ #[ bench:: short( 1.015625 ) ]
174+ #[ bench:: max( f16:: MAX ) ]
175+ fn icount_bench_print_hf16 ( x : f16 ) -> String {
176+ black_box ( Hexf ( x) . to_string ( ) )
177+ }
178+
179+ #[ library_benchmark]
180+ #[ bench:: short( 1.015625 ) ]
181+ #[ bench:: max( f32 :: MAX ) ]
182+ fn icount_bench_print_hf32 ( x : f32 ) -> String {
183+ black_box ( Hexf ( x) . to_string ( ) )
184+ }
185+
186+ #[ library_benchmark]
187+ #[ bench:: short( 1.015625 ) ]
188+ #[ bench:: max( f64 :: MAX ) ]
189+ fn icount_bench_print_hf64 ( x : f64 ) -> String {
190+ black_box ( Hexf ( x) . to_string ( ) )
191+ }
192+
193+ #[ library_benchmark]
194+ #[ bench:: short( 1.015625 ) ]
195+ #[ bench:: max( f128:: MAX ) ]
196+ fn icount_bench_print_hf128 ( x : f128 ) -> String {
197+ black_box ( Hexf ( x) . to_string ( ) )
198+ }
199+
200+ library_benchmark_group ! (
201+ name = icount_bench_hf_print_group;
202+ benchmarks =
203+ icount_bench_print_hf16,
204+ icount_bench_print_hf32,
205+ icount_bench_print_hf64,
206+ icount_bench_print_hf128
141207) ;
142208
143209main ! (
144210 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 ,
211+ // Benchmarks not related to public libm math
212+ icount_bench_u128_group ,
213+ icount_bench_hf_parse_group ,
214+ icount_bench_hf_print_group ,
149215 // verify-apilist-start
150216 // verify-sorted-start
151217 icount_bench_acos_group,
0 commit comments