Skip to content

Commit 40f4317

Browse files
committed
Add fmaf16
1 parent c344b66 commit 40f4317

File tree

10 files changed

+46
-8
lines changed

10 files changed

+46
-8
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ const ALL_OPERATIONS_NESTED: &[NestedOp] = &[
246246
],
247247
public: true,
248248
},
249+
NestedOp {
250+
// `(f16, f16, f16) -> f16`
251+
float_ty: FloatTy::F16,
252+
rust_sig: Signature {
253+
args: &[Ty::F16, Ty::F16, Ty::F16],
254+
returns: &[Ty::F16],
255+
},
256+
c_sig: None,
257+
fn_list: &["fmaf16"],
258+
public: true,
259+
},
249260
NestedOp {
250261
// `(f32, f32, f32) -> f32`
251262
float_ty: FloatTy::F32,

etc/function-definitions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@
362362
],
363363
"type": "f128"
364364
},
365+
"fmaf16": {
366+
"sources": [
367+
"libm/src/math/fma.rs"
368+
],
369+
"type": "f16"
370+
},
365371
"fmax": {
366372
"sources": [
367373
"libm/src/math/fmin_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

libm-test/benches/icount.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ main!(
301301
icount_bench_floorf_group,
302302
icount_bench_fma_group,
303303
icount_bench_fmaf128_group,
304+
icount_bench_fmaf16_group,
304305
icount_bench_fmaf_group,
305306
icount_bench_fmax_group,
306307
icount_bench_fmaxf128_group,

libm-test/src/generate/case_list.rs

Lines changed: 20 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
use libm::hf64;
1012
#[cfg(f128_enabled)]
1113
use libm::hf128;
@@ -256,6 +258,24 @@ fn floorf16_cases() -> Vec<TestCase<op::floorf16::Routine>> {
256258
vec![]
257259
}
258260

261+
#[cfg(f16_enabled)]
262+
fn fmaf16_cases() -> Vec<TestCase<op::fmaf16::Routine>> {
263+
let mut v = vec![];
264+
TestCase::append_pairs(
265+
&mut v,
266+
&[(
267+
// Failed during extensive tests
268+
(
269+
hf16!("-0x1.c4p-12"),
270+
hf16!("0x1.22p-14"),
271+
hf16!("-0x1.f4p-15"),
272+
),
273+
Some(hf16!("-0x1.f48p-15")),
274+
)],
275+
);
276+
v
277+
}
278+
259279
fn fma_cases() -> Vec<TestCase<op::fma::Routine>> {
260280
let mut v = vec![];
261281
TestCase::append_pairs(

libm-test/src/mpfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ libm_macros::for_each_function! {
214214
expm1 | expm1f => exp_m1,
215215
fabs | fabsf => abs,
216216
fdim | fdimf | fdimf16 | fdimf128 => positive_diff,
217-
fma | fmaf | fmaf128 => mul_add,
217+
fmaf16 | fma | fmaf | fmaf128 => mul_add,
218218
fmax | fmaxf | fmaxf16 | fmaxf128 |
219219
fmaximum_num | fmaximum_numf | fmaximum_numf16 | fmaximum_numf128 => max,
220220
fmin | fminf | fminf16 | fminf128 |

libm-test/src/precision.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ impl MaybeOverride<(f64, i32)> for SpecialCase {}
511511
#[cfg(f128_enabled)]
512512
impl MaybeOverride<(f128, i32)> for SpecialCase {}
513513

514+
#[cfg(f16_enabled)]
515+
impl MaybeOverride<(f16, f16, f16)> for SpecialCase {}
514516
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
515517
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
516518
#[cfg(f128_enabled)]

libm/src/libm_helper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ libm_helper! {
195195
(fn fabs(x: f16) -> (f16); => fabsf16);
196196
(fn fdim(x: f16, y: f16) -> (f16); => fdimf16);
197197
(fn floor(x: f16) -> (f16); => floorf16);
198+
(fn fma(x: f16, y: f16, z: f16) -> (f16); => fmaf16);
198199
(fn fmax(x: f16, y: f16) -> (f16); => fmaxf16);
199200
(fn fmaximum_num(x: f16, y: f16) -> (f16); => fmaximum_numf16);
200201
(fn fmaximumf16(x: f16, y: f16) -> (f16); => fmaximumf16);

libm/src/math/fma.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
use super::generic;
55
use crate::support::Round;
66

7-
// Placeholder so we can have `fmaf16` in the `Float` trait.
8-
#[allow(unused)]
97
#[cfg(f16_enabled)]
108
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
11-
pub(crate) fn fmaf16(_x: f16, _y: f16, _z: f16) -> f16 {
12-
unimplemented!()
9+
pub fn fmaf16(x: f16, y: f16, z: f16) -> f16 {
10+
generic::fma_wide_round(x, y, z, Round::Nearest).val
1311
}
1412

1513
/// Floating multiply add (f32)

libm/src/math/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ cfg_if! {
318318
pub use self::fabs::fabsf16;
319319
pub use self::fdim::fdimf16;
320320
pub use self::floor::floorf16;
321+
pub use self::fma::fmaf16;
321322
pub use self::fmin_fmax::{fmaxf16, fminf16};
322323
pub use self::fminimum_fmaximum::{fmaximumf16, fminimumf16};
323324
pub use self::fminimum_fmaximum_num::{fmaximum_numf16, fminimum_numf16};
@@ -332,9 +333,6 @@ cfg_if! {
332333
pub use self::sqrt::sqrtf16;
333334
pub use self::trunc::truncf16;
334335
// verify-sorted-end
335-
336-
#[allow(unused_imports)]
337-
pub(crate) use self::fma::fmaf16;
338336
}
339337
}
340338

0 commit comments

Comments
 (0)