Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/libm-macros/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ const ALL_OPERATIONS_NESTED: &[NestedOp] = &[
],
public: true,
},
NestedOp {
// `(f16, f16, f16) -> f16`
float_ty: FloatTy::F16,
rust_sig: Signature {
args: &[Ty::F16, Ty::F16, Ty::F16],
returns: &[Ty::F16],
},
c_sig: None,
fn_list: &["fmaf16"],
public: true,
},
NestedOp {
// `(f32, f32, f32) -> f32`
float_ty: FloatTy::F32,
Expand Down
6 changes: 6 additions & 0 deletions etc/function-definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@
],
"type": "f128"
},
"fmaf16": {
"sources": [
"libm/src/math/fma.rs"
],
"type": "f16"
},
"fmax": {
"sources": [
"libm/src/math/fmin_fmax.rs",
Expand Down
1 change: 1 addition & 0 deletions etc/function-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ floorf16
fma
fmaf
fmaf128
fmaf16
fmax
fmaxf
fmaxf128
Expand Down
1 change: 1 addition & 0 deletions libm-test/benches/icount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ main!(
icount_bench_floorf_group,
icount_bench_fma_group,
icount_bench_fmaf128_group,
icount_bench_fmaf16_group,
icount_bench_fmaf_group,
icount_bench_fmax_group,
icount_bench_fmaxf128_group,
Expand Down
20 changes: 20 additions & 0 deletions libm-test/src/generate/case_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//!
//! This is useful for adding regression tests or expected failures.
#[cfg(f16_enabled)]
use libm::hf16;
use libm::hf64;
#[cfg(f128_enabled)]
use libm::hf128;
Expand Down Expand Up @@ -256,6 +258,24 @@ fn floorf16_cases() -> Vec<TestCase<op::floorf16::Routine>> {
vec![]
}

#[cfg(f16_enabled)]
fn fmaf16_cases() -> Vec<TestCase<op::fmaf16::Routine>> {
let mut v = vec![];
TestCase::append_pairs(
&mut v,
&[(
// Failed during extensive tests
(
hf16!("-0x1.c4p-12"),
hf16!("0x1.22p-14"),
hf16!("-0x1.f4p-15"),
),
Some(hf16!("-0x1.f48p-15")),
)],
);
v
}

fn fma_cases() -> Vec<TestCase<op::fma::Routine>> {
let mut v = vec![];
TestCase::append_pairs(
Expand Down
2 changes: 1 addition & 1 deletion libm-test/src/mpfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ libm_macros::for_each_function! {
expm1 | expm1f => exp_m1,
fabs | fabsf => abs,
fdim | fdimf | fdimf16 | fdimf128 => positive_diff,
fma | fmaf | fmaf128 => mul_add,
fmaf16 | fma | fmaf | fmaf128 => mul_add,
fmax | fmaxf | fmaxf16 | fmaxf128 |
fmaximum_num | fmaximum_numf | fmaximum_numf16 | fmaximum_numf128 => max,
fmin | fminf | fminf16 | fminf128 |
Expand Down
2 changes: 2 additions & 0 deletions libm-test/src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ impl MaybeOverride<(f64, i32)> for SpecialCase {}
#[cfg(f128_enabled)]
impl MaybeOverride<(f128, i32)> for SpecialCase {}

#[cfg(f16_enabled)]
impl MaybeOverride<(f16, f16, f16)> for SpecialCase {}
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
#[cfg(f128_enabled)]
Expand Down
1 change: 1 addition & 0 deletions libm/src/libm_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ libm_helper! {
(fn fabs(x: f16) -> (f16); => fabsf16);
(fn fdim(x: f16, y: f16) -> (f16); => fdimf16);
(fn floor(x: f16) -> (f16); => floorf16);
(fn fma(x: f16, y: f16, z: f16) -> (f16); => fmaf16);
(fn fmax(x: f16, y: f16) -> (f16); => fmaxf16);
(fn fmaximum_num(x: f16, y: f16) -> (f16); => fmaximum_numf16);
(fn fmaximumf16(x: f16, y: f16) -> (f16); => fmaximumf16);
Expand Down
9 changes: 5 additions & 4 deletions libm/src/math/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use super::generic;
use crate::support::Round;

// Placeholder so we can have `fmaf16` in the `Float` trait.
#[allow(unused)]
/// Floating multiply add (f16)
///
/// Computes `(x*y)+z`, rounded as one ternary operation (i.e. calculated with infinite precision).
#[cfg(f16_enabled)]
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
pub(crate) fn fmaf16(_x: f16, _y: f16, _z: f16) -> f16 {
unimplemented!()
pub fn fmaf16(x: f16, y: f16, z: f16) -> f16 {
generic::fma_wide_round(x, y, z, Round::Nearest).val
}

/// Floating multiply add (f32)
Expand Down
4 changes: 1 addition & 3 deletions libm/src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ cfg_if! {
pub use self::fabs::fabsf16;
pub use self::fdim::fdimf16;
pub use self::floor::floorf16;
pub use self::fma::fmaf16;
pub use self::fmin_fmax::{fmaxf16, fminf16};
pub use self::fminimum_fmaximum::{fmaximumf16, fminimumf16};
pub use self::fminimum_fmaximum_num::{fmaximum_numf16, fminimum_numf16};
Expand All @@ -332,9 +333,6 @@ cfg_if! {
pub use self::sqrt::sqrtf16;
pub use self::trunc::truncf16;
// verify-sorted-end

#[allow(unused_imports)]
pub(crate) use self::fma::fmaf16;
}
}

Expand Down
Loading