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

Add roundeven{,f,f16,f128} #514

Merged
merged 2 commits into from
Feb 11, 2025
Merged
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
104 changes: 94 additions & 10 deletions crates/libm-macros/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,60 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
FloatTy::F16,
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
None,
&["ceilf16", "fabsf16", "floorf16", "rintf16", "roundf16", "sqrtf16", "truncf16"],
&[
"ceilf16",
"fabsf16",
"floorf16",
"rintf16",
"roundevenf16",
"roundf16",
"sqrtf16",
"truncf16",
],
),
(
// `fn(f32) -> f32`
FloatTy::F32,
Signature { args: &[Ty::F32], returns: &[Ty::F32] },
None,
&[
"acosf", "acoshf", "asinf", "asinhf", "atanf", "atanhf", "cbrtf", "ceilf", "cosf",
"coshf", "erfcf", "erff", "exp10f", "exp2f", "expf", "expm1f", "fabsf", "floorf",
"j0f", "j1f", "lgammaf", "log10f", "log1pf", "log2f", "logf", "rintf", "roundf",
"sinf", "sinhf", "sqrtf", "tanf", "tanhf", "tgammaf", "truncf", "y0f", "y1f",
"acosf",
"acoshf",
"asinf",
"asinhf",
"atanf",
"atanhf",
"cbrtf",
"ceilf",
"cosf",
"coshf",
"erfcf",
"erff",
"exp10f",
"exp2f",
"expf",
"expm1f",
"fabsf",
"floorf",
"j0f",
"j1f",
"lgammaf",
"log10f",
"log1pf",
"log2f",
"logf",
"rintf",
"roundevenf",
"roundf",
"sinf",
"sinhf",
"sqrtf",
"tanf",
"tanhf",
"tgammaf",
"truncf",
"y0f",
"y1f",
],
),
(
Expand All @@ -29,18 +71,60 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
Signature { args: &[Ty::F64], returns: &[Ty::F64] },
None,
&[
"acos", "acosh", "asin", "asinh", "atan", "atanh", "cbrt", "ceil", "cos", "cosh",
"erf", "erfc", "exp", "exp10", "exp2", "expm1", "fabs", "floor", "j0", "j1", "lgamma",
"log", "log10", "log1p", "log2", "rint", "round", "sin", "sinh", "sqrt", "tan", "tanh",
"tgamma", "trunc", "y0", "y1",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"cos",
"cosh",
"erf",
"erfc",
"exp",
"exp10",
"exp2",
"expm1",
"fabs",
"floor",
"j0",
"j1",
"lgamma",
"log",
"log10",
"log1p",
"log2",
"rint",
"round",
"roundeven",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"tgamma",
"trunc",
"y0",
"y1",
],
),
(
// `fn(f128) -> f128`
FloatTy::F128,
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
None,
&["ceilf128", "fabsf128", "floorf128", "rintf128", "roundf128", "sqrtf128", "truncf128"],
&[
"ceilf128",
"fabsf128",
"floorf128",
"rintf128",
"roundevenf128",
"roundf128",
"sqrtf128",
"truncf128",
],
),
(
// `(f16, f16) -> f16`
Expand Down
4 changes: 4 additions & 0 deletions crates/libm-test/benches/icount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ main!(
icount_bench_rintf16_group,
icount_bench_rintf_group,
icount_bench_round_group,
icount_bench_roundeven_group,
icount_bench_roundevenf128_group,
icount_bench_roundevenf16_group,
icount_bench_roundevenf_group,
icount_bench_roundf128_group,
icount_bench_roundf16_group,
icount_bench_roundf_group,
Expand Down
4 changes: 4 additions & 0 deletions crates/libm-test/benches/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ libm_macros::for_each_function! {
| ldexpf16
| rintf128
| rintf16
| roundeven
| roundevenf
| roundevenf128
| roundevenf16
| roundf128
| roundf16
| scalbnf128
Expand Down
1 change: 1 addition & 0 deletions crates/libm-test/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub fn get_domain<F: Float, I: Int>(
BaseName::Remquo => &EitherPrim::UNBOUNDED2[..],
BaseName::Rint => &EitherPrim::UNBOUNDED1[..],
BaseName::Round => &EitherPrim::UNBOUNDED1[..],
BaseName::Roundeven => &EitherPrim::UNBOUNDED1[..],
BaseName::Scalbn => &EitherPrim::UNBOUNDED_F_I[..],
BaseName::Sin => &EitherPrim::TRIG[..],
BaseName::Sincos => &EitherPrim::TRIG[..],
Expand Down
39 changes: 37 additions & 2 deletions crates/libm-test/src/gen/case_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
//! This is useful for adding regression tests or expected failures.

use libm::hf64;
#[cfg(f128_enabled)]
use libm::hf128;

Expand Down Expand Up @@ -574,7 +575,15 @@ fn remquof_cases() -> Vec<TestCase<op::remquof::Routine>> {
}

fn rint_cases() -> Vec<TestCase<op::rint::Routine>> {
vec![]
let mut v = vec![];
TestCase::append_pairs(
&mut v,
&[
// Failure on i586
((hf64!("-0x1.e3f13ff995ffcp+38"),), Some(hf64!("-0x1.e3f13ff994000p+38"))),
],
);
v
}

fn rintf_cases() -> Vec<TestCase<op::rintf::Routine>> {
Expand All @@ -591,6 +600,11 @@ fn rintf16_cases() -> Vec<TestCase<op::rintf16::Routine>> {
vec![]
}

#[cfg(f16_enabled)]
fn roundf16_cases() -> Vec<TestCase<op::roundf16::Routine>> {
vec![]
}

fn round_cases() -> Vec<TestCase<op::round::Routine>> {
vec![]
}
Expand All @@ -605,7 +619,28 @@ fn roundf128_cases() -> Vec<TestCase<op::roundf128::Routine>> {
}

#[cfg(f16_enabled)]
fn roundf16_cases() -> Vec<TestCase<op::roundf16::Routine>> {
fn roundevenf16_cases() -> Vec<TestCase<op::roundevenf16::Routine>> {
vec![]
}

fn roundeven_cases() -> Vec<TestCase<op::roundeven::Routine>> {
let mut v = vec![];
TestCase::append_pairs(
&mut v,
&[
// Failure on i586
((hf64!("-0x1.e3f13ff995ffcp+38"),), Some(hf64!("-0x1.e3f13ff994000p+38"))),
],
);
v
}

fn roundevenf_cases() -> Vec<TestCase<op::roundevenf::Routine>> {
vec![]
}

#[cfg(f128_enabled)]
fn roundevenf128_cases() -> Vec<TestCase<op::roundevenf128::Routine>> {
vec![]
}

Expand Down
8 changes: 8 additions & 0 deletions crates/libm-test/src/mpfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ libm_macros::for_each_function! {
rintf128,
rintf16,
round,
roundeven,
roundevenf,
roundevenf128,
roundevenf16,
roundf,
roundf128,
roundf16,
Expand Down Expand Up @@ -253,6 +257,8 @@ impl_no_round! {
rint => round_even_mut; // FIXME: respect rounding mode
rintf => round_even_mut; // FIXME: respect rounding mode
round => round_mut;
roundeven => round_even_mut;
roundevenf => round_even_mut;
roundf => round_mut;
trunc => trunc_mut;
truncf => trunc_mut;
Expand All @@ -265,6 +271,7 @@ impl_no_round! {
floorf16 => floor_mut;
rintf16 => round_even_mut; // FIXME: respect rounding mode
roundf16 => round_mut;
roundevenf16 => round_even_mut;
truncf16 => trunc_mut;
}

Expand All @@ -275,6 +282,7 @@ impl_no_round! {
floorf128 => floor_mut;
rintf128 => round_even_mut; // FIXME: respect rounding mode
roundf128 => round_mut;
roundevenf128 => round_even_mut;
truncf128 => trunc_mut;
}

Expand Down
3 changes: 2 additions & 1 deletion crates/libm-test/src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn default_ulp(ctx: &CheckCtx) -> u32 {
| Bn::Remquo
| Bn::Rint
| Bn::Round
| Bn::Roundeven
| Bn::Scalbn
| Bn::Sqrt
| Bn::Trunc => 0,
Expand Down Expand Up @@ -282,7 +283,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
}

if cfg!(x86_no_sse)
&& ctx.base_name == BaseName::Rint
&& (ctx.base_name == BaseName::Rint || ctx.base_name == BaseName::Roundeven)
&& (expected - actual).abs() <= F::ONE
&& (expected - actual).abs() > F::ZERO
{
Expand Down
4 changes: 4 additions & 0 deletions crates/libm-test/tests/compare_built_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ libm_macros::for_each_function! {
ldexpf16,
rintf128,
rintf16,
roundeven,
roundevenf,
roundevenf128,
roundevenf16,
roundf128,
roundf16,
scalbnf128,
Expand Down
6 changes: 5 additions & 1 deletion crates/util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
| ldexpf16
| rintf128
| rintf16
| roundeven
| roundevenf
| roundevenf128
| roundevenf16
| roundf128
| roundf16
| scalbnf128
Expand Down Expand Up @@ -274,7 +278,7 @@ fn parse<T: FromStr + FromStrRadix>(input: &[&str], idx: usize) -> T {

let msg = || format!("invalid {} input '{s}'", type_name::<T>());

if s.starts_with("0x") {
if s.starts_with("0x") || s.starts_with("-0x") {
return T::from_str_radix(s, 16).unwrap_or_else(|_| panic!("{}", msg()));
}

Expand Down
34 changes: 27 additions & 7 deletions etc/function-definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,6 @@
"sources": [
"src/math/arch/aarch64.rs",
"src/math/arch/wasm32.rs",
"src/math/generic/rint.rs",
"src/math/rint.rs"
],
"type": "f64"
Expand All @@ -800,22 +799,19 @@
"sources": [
"src/math/arch/aarch64.rs",
"src/math/arch/wasm32.rs",
"src/math/generic/rint.rs",
"src/math/rintf.rs"
"src/math/rint.rs"
],
"type": "f32"
},
"rintf128": {
"sources": [
"src/math/generic/rint.rs",
"src/math/rintf128.rs"
"src/math/rint.rs"
],
"type": "f128"
},
"rintf16": {
"sources": [
"src/math/generic/rint.rs",
"src/math/rintf16.rs"
"src/math/rint.rs"
],
"type": "f16"
},
Expand All @@ -826,6 +822,30 @@
],
"type": "f64"
},
"roundeven": {
"sources": [
"src/math/roundeven.rs"
],
"type": "f64"
},
"roundevenf": {
"sources": [
"src/math/roundeven.rs"
],
"type": "f32"
},
"roundevenf128": {
"sources": [
"src/math/roundeven.rs"
],
"type": "f128"
},
"roundevenf16": {
"sources": [
"src/math/roundeven.rs"
],
"type": "f16"
},
"roundf": {
"sources": [
"src/math/generic/round.rs",
Expand Down
4 changes: 4 additions & 0 deletions etc/function-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ rintf
rintf128
rintf16
round
roundeven
roundevenf
roundevenf128
roundevenf16
roundf
roundf128
roundf16
Expand Down
Loading
Loading