Skip to content

Commit d202e8f

Browse files
committed
Change how operators are black_boxed
For some reason, the upcoming limb changes in [1] seem to ignore the black boxing when applied to the operator function. Changing to instead black box the inputs appears to fix this. [1]: rust-lang/libm#503
1 parent 555a29c commit d202e8f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

crates/libm-test/benches/icount.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Benchmarks that use `iai-cachegrind` to be reasonably CI-stable.
22
33
use std::hint::black_box;
4-
use std::ops::Shr;
54

65
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
76
use libm::support::{HInt, u256};
@@ -107,9 +106,8 @@ fn setup_u256_shift() -> Vec<(u256, u32)> {
107106
#[library_benchmark]
108107
#[bench::linspace(setup_u128_mul())]
109108
fn icount_bench_u128_widen_mul(cases: Vec<(u128, u128)>) {
110-
let f = black_box(u128::zero_widen_mul);
111109
for (x, y) in cases.iter().copied() {
112-
f(x, y);
110+
black_box(black_box(x).zero_widen_mul(black_box(y)));
113111
}
114112
}
115113

@@ -122,9 +120,8 @@ library_benchmark_group!(
122120
#[library_benchmark]
123121
#[bench::linspace(setup_u256_add())]
124122
fn icount_bench_u256_add(cases: Vec<(u256, u256)>) {
125-
let f = black_box(u256::add);
126123
for (x, y) in cases.iter().copied() {
127-
f(x, y);
124+
black_box(black_box(x) + black_box(y));
128125
}
129126
}
130127
@@ -137,9 +134,8 @@ library_benchmark_group!(
137134
#[library_benchmark]
138135
#[bench::linspace(setup_u256_shift())]
139136
fn icount_bench_u256_shr(cases: Vec<(u256, u32)>) {
140-
let f = black_box(u256::shr);
141137
for (x, y) in cases.iter().copied() {
142-
f(x, y);
138+
black_box(black_box(x) >> black_box(y));
143139
}
144140
}
145141

0 commit comments

Comments
 (0)