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

Commit c90d3e6

Browse files
committed
Add fmaf16 and fmaf128
1 parent bc6b854 commit c90d3e6

File tree

16 files changed

+141
-7
lines changed

16 files changed

+141
-7
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
9292
None,
9393
&["copysignf128"],
9494
),
95+
(
96+
// `(f16, f16, f16) -> f16`
97+
FloatTy::F16,
98+
Signature { args: &[Ty::F16, Ty::F16, Ty::F16], returns: &[Ty::F16] },
99+
None,
100+
&["fmaf16"],
101+
),
95102
(
96103
// `(f32, f32, f32) -> f32`
97104
FloatTy::F32,
@@ -106,6 +113,13 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
106113
None,
107114
&["fma"],
108115
),
116+
(
117+
// `(f128, f128, f128) -> f128`
118+
FloatTy::F128,
119+
Signature { args: &[Ty::F128, Ty::F128, Ty::F128], returns: &[Ty::F128] },
120+
None,
121+
&["fmaf128"],
122+
),
109123
(
110124
// `(f32) -> i32`
111125
FloatTy::F32,

crates/libm-test/benches/random.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ libm_macros::for_each_function! {
117117
exp10 | exp10f | exp2 | exp2f => (true, Some(musl_math_sys::MACRO_FN_NAME)),
118118

119119
// Musl does not provide `f16` and `f128` functions
120-
copysignf16 | copysignf128 | fabsf16 | fabsf128 => (false, None),
120+
copysignf16 | copysignf128 | fabsf16 | fabsf128 |
121+
fmaf16 | fmaf128 => (false, None),
121122

122123
// By default we never skip (false) and always have a musl function available
123124
_ => (false, Some(musl_math_sys::MACRO_FN_NAME))

crates/libm-test/src/mpfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ libm_macros::for_each_function! {
144144
expm1 | expm1f => exp_m1,
145145
fabs | fabsf => abs,
146146
fdim | fdimf => positive_diff,
147-
fma | fmaf => mul_add,
147+
fma | fmaf | fmaf16 | fmaf128 => mul_add,
148148
fmax | fmaxf => max,
149149
fmin | fminf => min,
150150
lgamma | lgammaf => ln_gamma,

crates/libm-test/src/precision.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ fn bessel_prec_dropoff<F: Float>(
459459
None
460460
}
461461

462+
#[cfg(f16_enabled)]
463+
impl MaybeOverride<(f16, f16, f16)> for SpecialCase {}
462464
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
463465
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
466+
#[cfg(f128_enabled)]
467+
impl MaybeOverride<(f128, f128, f128)> for SpecialCase {}
468+
464469
impl MaybeOverride<(f32, i32)> for SpecialCase {}
465470
impl MaybeOverride<(f64, i32)> for SpecialCase {}

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ where
4747
libm_macros::for_each_function! {
4848
callback: musl_rand_tests,
4949
// Musl does not support `f16` and `f128` on all platforms.
50-
skip: [copysignf16, copysignf128, fabsf16, fabsf128],
50+
skip: [copysignf16, copysignf128, fabsf16, fabsf128, fmaf16, fmaf128],
5151
attributes: [
5252
#[cfg_attr(x86_no_sse, ignore)] // FIXME(correctness): wrong result on i586
5353
[exp10, exp10f, exp2, exp2f, rint]

crates/libm-test/tests/multiprecision.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ libm_macros::for_each_function! {
126126
fdimf,
127127
fma,
128128
fmaf,
129+
fmaf16,
130+
fmaf128,
129131
fmax,
130132
fmaxf,
131133
fmin,

etc/function-definitions.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,32 @@
318318
"fma": {
319319
"sources": [
320320
"src/libm_helper.rs",
321-
"src/math/fma.rs"
321+
"src/math/fma.rs",
322+
"src/math/generic/fma.rs"
322323
],
323324
"type": "f64"
324325
},
325326
"fmaf": {
326327
"sources": [
327-
"src/math/fmaf.rs"
328+
"src/math/fmaf.rs",
329+
"src/math/generic/fma.rs"
328330
],
329331
"type": "f32"
330332
},
333+
"fmaf128": {
334+
"sources": [
335+
"src/math/fmaf128.rs",
336+
"src/math/generic/fma.rs"
337+
],
338+
"type": "f128"
339+
},
340+
"fmaf16": {
341+
"sources": [
342+
"src/math/fmaf16.rs",
343+
"src/math/generic/fma.rs"
344+
],
345+
"type": "f16"
346+
},
331347
"fmax": {
332348
"sources": [
333349
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ floor
4747
floorf
4848
fma
4949
fmaf
50+
fmaf128
51+
fmaf16
5052
fmax
5153
fmaxf
5254
fmin

src/math/fmaf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ use super::fenv::{
4747
/// according to the rounding mode characterized by the value of FLT_ROUNDS.
4848
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4949
pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 {
50+
if true {
51+
return super::generic::fma_big::<f32, f64>(x, y, z);
52+
}
53+
5054
let xy: f64;
5155
let mut result: f64;
5256
let mut ui: u64;

src/math/fmaf128.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn fmaf128(x: f128, y: f128, z: f128) -> f128 {
3+
super::generic::fma(x, y, z)
4+
}

0 commit comments

Comments
 (0)