Skip to content

Commit 17e6bc1

Browse files
committed
Add a way to avoid f32 implementations that do math as an f64
1 parent 6675cd1 commit 17e6bc1

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

ci/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ fi
184184

185185
mflags=()
186186

187+
nowiden_tests=$(grep -vE '^#' etc/has-nowiden-impl.txt | tr '\n' ' ')
188+
187189
# We enumerate features manually.
188190
mflags+=(--no-default-features)
189191

@@ -283,6 +285,7 @@ else
283285
# Test the same in release mode, which also increases coverage. Also ensure
284286
# the soft float routines are checked.
285287
"${cmd[@]}" "$profile_flag" release-checked
288+
[ -n "${nowiden_tests:-}" ] && LIBM_F32_NO_WIDEN=1 "${cmd[@]}" "$profile_flag" release-checked -- $nowiden_tests
286289
"${cmd[@]}" "$profile_flag" release-checked --features force-soft-floats
287290
"${cmd[@]}" "$profile_flag" release-checked --features unstable-intrinsics
288291
"${cmd[@]}" "$profile_flag" release-checked --features unstable-intrinsics --benches

etc/has-nowiden-impl.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Functions that have a different version based on f32_no_widen
2+
fmaf

libm/configure.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub fn emit_libm_config(cfg: &Config) {
5050
emit_intrinsics_cfg();
5151
emit_arch_cfg();
5252
emit_optimization_cfg(cfg);
53+
emit_widen_cfg(cfg);
5354
emit_cfg_shorthands(cfg);
5455
emit_cfg_env(cfg);
5556
emit_f16_f128_cfg(cfg);
@@ -96,6 +97,15 @@ fn emit_optimization_cfg(cfg: &Config) {
9697
}
9798
}
9899

100+
fn emit_widen_cfg(_cfg: &Config) {
101+
println!("cargo:rustc-check-cfg=cfg(f32_no_widen)");
102+
println!("cargo:rerun-if-env-changed=LIBM_F32_NO_WIDEN");
103+
104+
if env::var_os("LIBM_F32_NO_WIDEN").is_some() {
105+
println!("cargo:rustc-cfg=f32_no_widen");
106+
}
107+
}
108+
99109
/// Provide an alias for common longer config combinations.
100110
fn emit_cfg_shorthands(cfg: &Config) {
101111
println!("cargo:rustc-check-cfg=cfg(x86_no_sse)");

libm/src/math/fma_wide.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ pub fn fmaf(x: f32, y: f32, z: f32) -> f32 {
2323
args: x, y, z,
2424
}
2525

26-
fma_wide_round(x, y, z, Round::Nearest).val
26+
if cfg!(f32_no_widen) {
27+
super::fma::fma_round(x, y, z, Round::Nearest).val
28+
} else {
29+
fma_wide_round(x, y, z, Round::Nearest).val
30+
}
2731
}
2832

2933
/// Fma implementation when a hardware-backed larger float type is available. For `f32` and `f64`,

0 commit comments

Comments
 (0)