Skip to content

Commit bbdaf29

Browse files
authored
Merge pull request rust-lang/libm#520 from tgross35/fma-restructure
Combine `fma` public API with its implementation
2 parents f790449 + f1ea040 commit bbdaf29

File tree

12 files changed

+487
-486
lines changed

12 files changed

+487
-486
lines changed

libm/crates/libm-test/src/f8_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ impl Float for f8 {
7878
libm::generic::copysign(self, other)
7979
}
8080

81+
fn fma(self, _y: Self, _z: Self) -> Self {
82+
unimplemented!()
83+
}
84+
8185
fn normalize(_significand: Self::Int) -> (i32, Self::Int) {
8286
unimplemented!()
8387
}

libm/etc/function-definitions.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@
130130
"copysign": {
131131
"sources": [
132132
"src/math/copysign.rs",
133-
"src/math/generic/copysign.rs",
134-
"src/math/support/float_traits.rs"
133+
"src/math/generic/copysign.rs"
135134
],
136135
"type": "f64"
137136
},
@@ -343,22 +342,19 @@
343342
},
344343
"fma": {
345344
"sources": [
346-
"src/math/fma.rs",
347-
"src/math/generic/fma.rs"
345+
"src/math/fma.rs"
348346
],
349347
"type": "f64"
350348
},
351349
"fmaf": {
352350
"sources": [
353-
"src/math/fmaf.rs",
354-
"src/math/generic/fma.rs"
351+
"src/math/fma_wide.rs"
355352
],
356353
"type": "f32"
357354
},
358355
"fmaf128": {
359356
"sources": [
360-
"src/math/fmaf128.rs",
361-
"src/math/generic/fma.rs"
357+
"src/math/fma.rs"
362358
],
363359
"type": "f128"
364360
},

libm/etc/update-api-list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
DIRECTORIES = [".github", "ci", "crates", "etc", "src"]
2525

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

2929
IndexTy: TypeAlias = dict[str, dict[str, Any]]
3030
"""Type of the `index` item in rustdoc's JSON output"""

libm/src/math/cbrt.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
103103
* and rr an approximation of 1/zz. We now perform another iteration of
104104
* Newton-Raphson, this time with a linear approximation only. */
105105
y2 = y * y;
106-
let mut y2l: f64 = fmaf64(y, y, -y2);
106+
let mut y2l: f64 = y.fma(y, -y2);
107107

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

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

134134
y2 = y1 * y1;
135-
y2l = fmaf64(y1, y1, -y2);
135+
y2l = y1.fma(y1, -y2);
136136
y3 = y2 * y1;
137-
y3l = fmaf64(y1, y2, -y3) + y1 * y2l;
137+
y3l = y1.fma(y2, -y3) + y1 * y2l;
138138
h = ((y3 - zz) + y3l) * rr;
139139
dy = h * (y1 * u0);
140140
y = y1 - dy;
@@ -198,18 +198,6 @@ pub fn cbrt_round(x: f64, round: Round) -> FpResult<f64> {
198198
FpResult::ok(f64::from_bits(cvt3))
199199
}
200200

201-
fn fmaf64(x: f64, y: f64, z: f64) -> f64 {
202-
#[cfg(intrinsics_enabled)]
203-
{
204-
return unsafe { core::intrinsics::fmaf64(x, y, z) };
205-
}
206-
207-
#[cfg(not(intrinsics_enabled))]
208-
{
209-
return super::fma(x, y, z);
210-
}
211-
}
212-
213201
#[cfg(test)]
214202
mod tests {
215203
use super::*;

0 commit comments

Comments
 (0)