Add ceilf16 and ceilf128

Use the generic algorithms to provide implementations for these
routines.
This commit is contained in:
Trevor Gross 2025-01-13 11:17:17 +00:00
parent c00f119166
commit 9064c42abe
12 changed files with 68 additions and 6 deletions

View file

@ -9,7 +9,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
FloatTy::F16,
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
None,
&["fabsf16", "sqrtf16", "truncf16"],
&["ceilf16", "fabsf16", "sqrtf16", "truncf16"],
),
(
// `fn(f32) -> f32`
@ -40,7 +40,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
FloatTy::F128,
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
None,
&["fabsf128", "sqrtf128", "truncf128"],
&["ceilf128", "fabsf128", "sqrtf128", "truncf128"],
),
(
// `(f16, f16) -> f16`

View file

@ -69,6 +69,8 @@ main!(
icount_bench_cbrt_group,
icount_bench_cbrtf_group,
icount_bench_ceil_group,
icount_bench_ceilf128_group,
icount_bench_ceilf16_group,
icount_bench_ceilf_group,
icount_bench_copysign_group,
icount_bench_copysignf128_group,

View file

@ -117,7 +117,9 @@ libm_macros::for_each_function! {
exp10 | exp10f | exp2 | exp2f => (true, Some(musl_math_sys::MACRO_FN_NAME)),
// Musl does not provide `f16` and `f128` functions
copysignf128
ceilf128
| ceilf16
| copysignf128
| copysignf16
| fabsf128
| fabsf16

View file

@ -137,6 +137,8 @@ libm_macros::for_each_function! {
// Most of these need a manual implementation
ceil,
ceilf,
ceilf128,
ceilf16,
copysign,
copysignf,
copysignf128,
@ -237,12 +239,14 @@ impl_no_round! {
#[cfg(f16_enabled)]
impl_no_round! {
fabsf16 => abs_mut;
ceilf16 => ceil_mut;
truncf16 => trunc_mut;
}
#[cfg(f128_enabled)]
impl_no_round! {
fabsf128 => abs_mut;
ceilf128 => ceil_mut;
truncf128 => trunc_mut;
}

View file

@ -79,6 +79,8 @@ libm_macros::for_each_function! {
ynf,
// Not provided by musl
ceilf128,
ceilf16,
copysignf128,
copysignf16,
fabsf128,

View file

@ -84,7 +84,9 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
emit_types: [CFn, RustFn, RustArgs],
extra: (basis, op, inputs),
fn_extra: match MACRO_FN_NAME {
copysignf128
ceilf128
| ceilf16
| copysignf128
| copysignf16
| fabsf128
| fabsf16

View file

@ -109,17 +109,33 @@
"src/libm_helper.rs",
"src/math/arch/i586.rs",
"src/math/arch/wasm32.rs",
"src/math/ceil.rs"
"src/math/ceil.rs",
"src/math/generic/ceil.rs"
],
"type": "f64"
},
"ceilf": {
"sources": [
"src/math/arch/wasm32.rs",
"src/math/ceilf.rs"
"src/math/ceilf.rs",
"src/math/generic/ceil.rs"
],
"type": "f32"
},
"ceilf128": {
"sources": [
"src/math/ceilf128.rs",
"src/math/generic/ceil.rs"
],
"type": "f128"
},
"ceilf16": {
"sources": [
"src/math/ceilf16.rs",
"src/math/generic/ceil.rs"
],
"type": "f16"
},
"copysign": {
"sources": [
"src/libm_helper.rs",

View file

@ -17,6 +17,8 @@ cbrt
cbrtf
ceil
ceilf
ceilf128
ceilf16
copysign
copysignf
copysignf128

View file

@ -0,0 +1,7 @@
/// Ceil (f128)
///
/// Finds the nearest integer greater than or equal to `x`.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn ceilf128(x: f128) -> f128 {
super::generic::ceil(x)
}

View file

@ -0,0 +1,7 @@
/// Ceil (f16)
///
/// Finds the nearest integer greater than or equal to `x`.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn ceilf16(x: f16) -> f16 {
super::generic::ceil(x)
}

View file

@ -63,6 +63,14 @@ mod tests {
}
}
/* Skipping f16 / f128 "sanity_check"s due to rejected literal lexing at MSRV */
#[test]
#[cfg(f16_enabled)]
fn spec_tests_f16() {
spec_test::<f16>();
}
#[test]
fn sanity_check_f32() {
assert_eq!(ceil(1.1f32), 2.0);
@ -84,4 +92,10 @@ mod tests {
fn spec_tests_f64() {
spec_test::<f64>();
}
#[test]
#[cfg(f128_enabled)]
fn spec_tests_f128() {
spec_test::<f128>();
}
}

View file

@ -341,12 +341,14 @@ pub use self::truncf::truncf;
cfg_if! {
if #[cfg(f16_enabled)] {
mod ceilf16;
mod copysignf16;
mod fabsf16;
mod fdimf16;
mod sqrtf16;
mod truncf16;
pub use self::ceilf16::ceilf16;
pub use self::copysignf16::copysignf16;
pub use self::fabsf16::fabsf16;
pub use self::fdimf16::fdimf16;
@ -357,12 +359,14 @@ cfg_if! {
cfg_if! {
if #[cfg(f128_enabled)] {
mod ceilf128;
mod copysignf128;
mod fabsf128;
mod fdimf128;
mod sqrtf128;
mod truncf128;
pub use self::ceilf128::ceilf128;
pub use self::copysignf128::copysignf128;
pub use self::fabsf128::fabsf128;
pub use self::fdimf128::fdimf128;