Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Add a no-f64 version of fmaf #500

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [ -z "$target" ]; then
target="$host_target"
fi

nowiden_tests=$(grep -vE '^#' etc/has-nowiden-impl.txt | tr '\n' ' ')

# We enumerate features manually.
flags="$flags --no-default-features"

Expand Down Expand Up @@ -112,6 +114,7 @@ $cmd --features unstable-intrinsics --benches
# Test the same in release mode, which also increases coverage. Also ensure
# the soft float routines are checked.
$cmd "$profile" release-checked
[ -n "${nowiden_tests:-}" ] && LIBM_F32_NO_WIDEN=1 $cmd "$profile" release-checked -- $nowiden_tests
$cmd "$profile" release-checked --features force-soft-floats
$cmd "$profile" release-checked --features unstable-intrinsics
$cmd "$profile" release-checked --features unstable-intrinsics --benches
Expand Down
10 changes: 10 additions & 0 deletions configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn emit_libm_config(cfg: &Config) {
emit_intrinsics_cfg();
emit_arch_cfg();
emit_optimization_cfg(cfg);
emit_widen_cfg(cfg);
emit_cfg_shorthands(cfg);
emit_cfg_env(cfg);
emit_f16_f128_cfg(cfg);
Expand Down Expand Up @@ -96,6 +97,15 @@ fn emit_optimization_cfg(cfg: &Config) {
}
}

fn emit_widen_cfg(_cfg: &Config) {
println!("cargo:rustc-check-cfg=cfg(f32_no_widen)");
println!("cargo:rerun-if-env-changed=LIBM_F32_NO_WIDEN");

if env::var_os("LIBM_F32_NO_WIDEN").is_some() {
println!("cargo:rustc-cfg=f32_no_widen");
}
}

/// Provide an alias for common longer config combinations.
fn emit_cfg_shorthands(cfg: &Config) {
println!("cargo:rustc-check-cfg=cfg(x86_no_sse)");
Expand Down
2 changes: 2 additions & 0 deletions etc/has-nowiden-impl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Functions that have a different version based on f32_no_widen
fmaf
6 changes: 5 additions & 1 deletion src/math/fmaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
/// according to the rounding mode characterized by the value of FLT_ROUNDS.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn fmaf(x: f32, y: f32, z: f32) -> f32 {
super::generic::fma_wide(x, y, z)
if cfg!(f32_no_widen) {
super::generic::fma(x, y, z)
} else {
super::generic::fma_wide(x, y, z)
}
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions src/math/generic/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ pub trait FmaHelper {
fn raise_underflow_ret_zero(self) -> Self;
}

impl FmaHelper for f32 {
fn raise_underflow_as_min_positive(self) -> Self {
f32::MIN_POSITIVE.copysign(self)
}

fn raise_underflow_ret_zero(self) -> Self {
f32::ZERO
}
}

impl FmaHelper for f64 {
fn raise_underflow_as_min_positive(self) -> Self {
/* min normal after rounding, underflow depends
Expand Down