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

Commit 601b5a2

Browse files
committed
Add fmaf16
1 parent 2795848 commit 601b5a2

File tree

13 files changed

+45
-1
lines changed

13 files changed

+45
-1
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 7 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", "fdimf128", "fmaxf128", "fminf128", "fmodf128"],
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,

crates/libm-test/benches/icount.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ main!(
109109
icount_bench_floorf_group,
110110
icount_bench_fma_group,
111111
icount_bench_fmaf128_group,
112+
icount_bench_fmaf16_group,
112113
icount_bench_fmaf_group,
113114
icount_bench_fmax_group,
114115
icount_bench_fmaxf128_group,

crates/libm-test/benches/random.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ libm_macros::for_each_function! {
128128
| floorf128
129129
| floorf16
130130
| fmaf128
131+
| fmaf16
131132
| fmaxf128
132133
| fmaxf16
133134
| fminf128

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//!
77
//! This is useful for adding regression tests or expected failures.
88
9+
#[cfg(f16_enabled)]
10+
use libm::hf16;
911
#[cfg(f128_enabled)]
1012
use libm::hf128;
1113

@@ -293,6 +295,20 @@ fn fmaf128_cases() -> Vec<TestCase<op::fmaf128::Routine>> {
293295
v
294296
}
295297

298+
#[cfg(f16_enabled)]
299+
fn fmaf16_cases() -> Vec<TestCase<op::fmaf16::Routine>> {
300+
let mut v = vec![];
301+
TestCase::append_pairs(
302+
&mut v,
303+
&[(
304+
// Failed during extensive tests
305+
(hf16!("-0x1.c4p-12"), hf16!("0x1.22p-14"), hf16!("-0x1.f4p-15")),
306+
Some(hf16!("-0x1.f48p-15")),
307+
)],
308+
);
309+
v
310+
}
311+
296312
fn fmax_cases() -> Vec<TestCase<op::fmax::Routine>> {
297313
vec![]
298314
}

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 | fmaf128 => mul_add,
199+
fma | fmaf | fmaf16 | 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
@@ -558,6 +558,8 @@ impl MaybeOverride<(f64, i32)> for SpecialCase {}
558558
#[cfg(f128_enabled)]
559559
impl MaybeOverride<(f128, i32)> for SpecialCase {}
560560

561+
#[cfg(f16_enabled)]
562+
impl MaybeOverride<(f16, f16, f16)> for SpecialCase {}
561563
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
562564
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
563565
#[cfg(f128_enabled)]

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ libm_macros::for_each_function! {
100100
floorf128,
101101
floorf16,
102102
fmaf128,
103+
fmaf16,
103104
fmaxf128,
104105
fmaxf16,
105106
fminf128,

crates/util/src/main.rs

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

etc/function-definitions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@
363363
],
364364
"type": "f128"
365365
},
366+
"fmaf16": {
367+
"sources": [
368+
"src/math/fmaf16.rs",
369+
"src/math/generic/fma.rs"
370+
],
371+
"type": "f16"
372+
},
366373
"fmax": {
367374
"sources": [
368375
"src/math/fmax.rs",

etc/function-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ floorf16
5454
fma
5555
fmaf
5656
fmaf128
57+
fmaf16
5758
fmax
5859
fmaxf
5960
fmaxf128

src/libm_helper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ libm_helper! {
185185
(fn fabs(x: f16) -> (f16); => fabsf16);
186186
(fn fdim(x: f16, y: f16) -> (f16); => fdimf16);
187187
(fn floorf(x: f16) -> (f16); => floorf16);
188+
(fn fmaf16(x: f16, y: f16, z: f16) -> (f16); => fmaf16);
188189
(fn fmaxf(x: f16, y: f16) -> (f16); => fmaxf16);
189190
(fn fminf(x: f16, y: f16) -> (f16); => fminf16);
190191
(fn fmodf(x: f16, y: f16) -> (f16); => fmodf16);

src/math/fmaf16.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 fmaf16(x: f16, y: f16, z: f16) -> f16 {
3+
super::generic::fma_big::<f16, f32>(x, y, z)
4+
}

src/math/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ cfg_if! {
347347
mod fabsf16;
348348
mod fdimf16;
349349
mod floorf16;
350+
mod fmaf16;
350351
mod fmaxf16;
351352
mod fminf16;
352353
mod fmodf16;
@@ -364,6 +365,7 @@ cfg_if! {
364365
pub use self::fabsf16::fabsf16;
365366
pub use self::fdimf16::fdimf16;
366367
pub use self::floorf16::floorf16;
368+
pub use self::fmaf16::fmaf16;
367369
pub use self::fmaxf16::fmaxf16;
368370
pub use self::fminf16::fminf16;
369371
pub use self::fmodf16::fmodf16;

0 commit comments

Comments
 (0)