Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine fma public API with its implementation #520

Merged
merged 4 commits into from
Feb 12, 2025
Merged
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
4 changes: 4 additions & 0 deletions crates/libm-test/src/f8_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl Float for f8 {
libm::generic::copysign(self, other)
}

fn fma(self, _y: Self, _z: Self) -> Self {
unimplemented!()
}

fn normalize(_significand: Self::Int) -> (i32, Self::Int) {
unimplemented!()
}
Expand Down
12 changes: 4 additions & 8 deletions etc/function-definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
"copysign": {
"sources": [
"src/math/copysign.rs",
"src/math/generic/copysign.rs",
"src/math/support/float_traits.rs"
"src/math/generic/copysign.rs"
],
"type": "f64"
},
Expand Down Expand Up @@ -343,22 +342,19 @@
},
"fma": {
"sources": [
"src/math/fma.rs",
"src/math/generic/fma.rs"
"src/math/fma.rs"
],
"type": "f64"
},
"fmaf": {
"sources": [
"src/math/fmaf.rs",
"src/math/generic/fma.rs"
"src/math/fma_wide.rs"
],
"type": "f32"
},
"fmaf128": {
"sources": [
"src/math/fmaf128.rs",
"src/math/generic/fma.rs"
"src/math/fma.rs"
],
"type": "f128"
},
Expand Down
2 changes: 1 addition & 1 deletion etc/update-api-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
DIRECTORIES = [".github", "ci", "crates", "etc", "src"]

# These files do not trigger a retest.
IGNORED_SOURCES = ["src/libm_helper.rs"]
IGNORED_SOURCES = ["src/libm_helper.rs", "src/math/support/float_traits.rs"]

IndexTy: TypeAlias = dict[str, dict[str, Any]]
"""Type of the `index` item in rustdoc's JSON output"""
Expand Down
20 changes: 4 additions & 16 deletions src/math/cbrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
* and rr an approximation of 1/zz. We now perform another iteration of
* Newton-Raphson, this time with a linear approximation only. */
y2 = y * y;
let mut y2l: f64 = fmaf64(y, y, -y2);
let mut y2l: f64 = y.fma(y, -y2);

/* y2 + y2l = y^2 exactly */
let mut y3: f64 = y2 * y;
let mut y3l: f64 = fmaf64(y, y2, -y3) + y * y2l;
let mut y3l: f64 = y.fma(y2, -y3) + y * y2l;

/* y3 + y3l approximates y^3 with about 106 bits of accuracy */
h = ((y3 - zz) + y3l) * rr;
Expand All @@ -132,9 +132,9 @@ pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
cold_path();

y2 = y1 * y1;
y2l = fmaf64(y1, y1, -y2);
y2l = y1.fma(y1, -y2);
y3 = y2 * y1;
y3l = fmaf64(y1, y2, -y3) + y1 * y2l;
y3l = y1.fma(y2, -y3) + y1 * y2l;
h = ((y3 - zz) + y3l) * rr;
dy = h * (y1 * u0);
y = y1 - dy;
Expand Down Expand Up @@ -198,18 +198,6 @@ pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
FpResult::ok(f64::from_bits(cvt3))
}

fn fmaf64(x: f64, y: f64, z: f64) -> f64 {
#[cfg(intrinsics_enabled)]
{
return unsafe { core::intrinsics::fmaf64(x, y, z) };
}

#[cfg(not(intrinsics_enabled))]
{
return super::fma(x, y, z);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading