Skip to content

Commit c967c7e

Browse files
committed
Add fmaf128
Resolve all remaining `f64`-specific items in the generic version of `fma`, then expose `fmaf128`.
1 parent c8aec8f commit c967c7e

File tree

14 files changed

+237
-67
lines changed

14 files changed

+237
-67
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
106106
None,
107107
&["fma"],
108108
),
109+
(
110+
// `(f128, f128, f128) -> f128`
111+
FloatTy::F128,
112+
Signature { args: &[Ty::F128, Ty::F128, Ty::F128], returns: &[Ty::F128] },
113+
None,
114+
&["fmaf128"],
115+
),
109116
(
110117
// `(f32) -> i32`
111118
FloatTy::F32,

crates/libm-test/benches/icount.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ main!(
108108
icount_bench_floorf16_group,
109109
icount_bench_floorf_group,
110110
icount_bench_fma_group,
111+
icount_bench_fmaf128_group,
111112
icount_bench_fmaf_group,
112113
icount_bench_fmax_group,
113114
icount_bench_fmaxf128_group,

crates/libm-test/benches/random.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ libm_macros::for_each_function! {
127127
| fdimf16
128128
| floorf128
129129
| floorf16
130+
| fmaf128
130131
| fmaxf128
131132
| fmaxf16
132133
| fminf128

crates/libm-test/src/gen/case_list.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//!
77
//! This is useful for adding regression tests or expected failures.
88
9+
#[cfg(f128_enabled)]
10+
use libm::hf128;
11+
912
use crate::{CheckBasis, CheckCtx, GeneratorKind, MathOp, op};
1013

1114
pub struct TestCase<Op: MathOp> {
@@ -250,7 +253,7 @@ fn fma_cases() -> Vec<TestCase<op::fma::Routine>> {
250253
TestCase::append_pairs(
251254
&mut v,
252255
&[
253-
// Previously failure with incorrect sign
256+
// Previous failure with incorrect sign
254257
((5e-324, -5e-324, 0.0), Some(-0.0)),
255258
],
256259
);
@@ -261,6 +264,24 @@ fn fmaf_cases() -> Vec<TestCase<op::fmaf::Routine>> {
261264
vec![]
262265
}
263266

267+
#[cfg(f128_enabled)]
268+
fn fmaf128_cases() -> Vec<TestCase<op::fmaf128::Routine>> {
269+
let mut v = vec![];
270+
TestCase::append_pairs(
271+
&mut v,
272+
&[(
273+
// Tricky rounding case that previously failed in extensive tests
274+
(
275+
hf128!("-0x1.1966cc01966cc01966cc01966f06p-25"),
276+
hf128!("-0x1.669933fe69933fe69933fe6997c9p-16358"),
277+
hf128!("-0x0.000000000000000000000000048ap-16382"),
278+
),
279+
Some(hf128!("0x0.c5171470a3ff5e0f68d751491b18p-16382")),
280+
)],
281+
);
282+
v
283+
}
284+
264285
fn fmax_cases() -> Vec<TestCase<op::fmax::Routine>> {
265286
vec![]
266287
}

crates/libm-test/src/mpfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ libm_macros::for_each_function! {
196196
expm1 | expm1f => exp_m1,
197197
fabs | fabsf => abs,
198198
fdim | fdimf | fdimf16 | fdimf128 => positive_diff,
199-
fma | fmaf => mul_add,
199+
fma | fmaf | fmaf128 => mul_add,
200200
fmax | fmaxf | fmaxf16 | fmaxf128 => max,
201201
fmin | fminf | fminf16 | fminf128 => min,
202202
lgamma | lgammaf => ln_gamma,

crates/libm-test/src/precision.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,5 @@ impl MaybeOverride<(f128, i32)> for SpecialCase {}
560560

561561
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
562562
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
563+
#[cfg(f128_enabled)]
564+
impl MaybeOverride<(f128, f128, f128)> for SpecialCase {}

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ libm_macros::for_each_function! {
9999
fdimf16,
100100
floorf128,
101101
floorf16,
102+
fmaf128,
102103
fmaxf128,
103104
fmaxf16,
104105
fminf128,

crates/util/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9696
| fdimf16
9797
| floorf128
9898
| floorf16
99+
| fmaf128
99100
| fmaxf128
100101
| fmaxf16
101102
| fminf128

etc/function-definitions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@
356356
],
357357
"type": "f32"
358358
},
359+
"fmaf128": {
360+
"sources": [
361+
"src/math/fmaf128.rs",
362+
"src/math/generic/fma.rs"
363+
],
364+
"type": "f128"
365+
},
359366
"fmax": {
360367
"sources": [
361368
"src/math/fmax.rs",

etc/function-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ floorf128
5353
floorf16
5454
fma
5555
fmaf
56+
fmaf128
5657
fmax
5758
fmaxf
5859
fmaxf128

src/libm_helper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ libm_helper! {
208208
(fn fabs(x: f128) -> (f128); => fabsf128);
209209
(fn fdim(x: f128, y: f128) -> (f128); => fdimf128);
210210
(fn floor(x: f128) -> (f128); => floorf128);
211+
(fn fmaf128(x: f128, y: f128, z: f128) -> (f128); => fmaf128);
211212
(fn fmax(x: f128, y: f128) -> (f128); => fmaxf128);
212213
(fn fmin(x: f128, y: f128) -> (f128); => fminf128);
213214
(fn fmod(x: f128, y: f128) -> (f128); => fmodf128);

src/math/fmaf128.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Fused multiply add (f128)
2+
///
3+
/// Computes `(x*y)+z`, rounded as one ternary operation (i.e. calculated with infinite precision).
4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5+
pub fn fmaf128(x: f128, y: f128, z: f128) -> f128 {
6+
return super::generic::fma(x, y, z);
7+
}

0 commit comments

Comments
 (0)