Skip to content

Commit 060274d

Browse files
committed
Add ceilf16 and ceilf128
Use the generic algorithms to provide implementations for these routines.
1 parent 14e5338 commit 060274d

File tree

12 files changed

+68
-6
lines changed

12 files changed

+68
-6
lines changed

crates/libm-macros/src/shared.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
99
FloatTy::F16,
1010
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
1111
None,
12-
&["fabsf16", "sqrtf16", "truncf16"],
12+
&["ceilf16", "fabsf16", "sqrtf16", "truncf16"],
1313
),
1414
(
1515
// `fn(f32) -> f32`
@@ -40,7 +40,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4040
FloatTy::F128,
4141
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
4242
None,
43-
&["fabsf128", "sqrtf128", "truncf128"],
43+
&["ceilf128", "fabsf128", "sqrtf128", "truncf128"],
4444
),
4545
(
4646
// `(f16, f16) -> f16`

crates/libm-test/benches/icount.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ main!(
6969
icount_bench_cbrt_group,
7070
icount_bench_cbrtf_group,
7171
icount_bench_ceil_group,
72+
icount_bench_ceilf128_group,
73+
icount_bench_ceilf16_group,
7274
icount_bench_ceilf_group,
7375
icount_bench_copysign_group,
7476
icount_bench_copysignf128_group,

crates/libm-test/benches/random.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ libm_macros::for_each_function! {
117117
exp10 | exp10f | exp2 | exp2f => (true, Some(musl_math_sys::MACRO_FN_NAME)),
118118

119119
// Musl does not provide `f16` and `f128` functions
120-
copysignf128
120+
ceilf128
121+
| ceilf16
122+
| copysignf128
121123
| copysignf16
122124
| fabsf128
123125
| fabsf16

crates/libm-test/src/mpfloat.rs

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ libm_macros::for_each_function! {
137137
// Most of these need a manual implementation
138138
ceil,
139139
ceilf,
140+
ceilf128,
141+
ceilf16,
140142
copysign,
141143
copysignf,
142144
copysignf128,
@@ -237,12 +239,14 @@ impl_no_round! {
237239
#[cfg(f16_enabled)]
238240
impl_no_round! {
239241
fabsf16 => abs_mut;
242+
ceilf16 => ceil_mut;
240243
truncf16 => trunc_mut;
241244
}
242245

243246
#[cfg(f128_enabled)]
244247
impl_no_round! {
245248
fabsf128 => abs_mut;
249+
ceilf128 => ceil_mut;
246250
truncf128 => trunc_mut;
247251
}
248252

crates/libm-test/tests/compare_built_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ libm_macros::for_each_function! {
7979
ynf,
8080

8181
// Not provided by musl
82+
ceilf128,
83+
ceilf16,
8284
copysignf128,
8385
copysignf16,
8486
fabsf128,

crates/util/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
8484
emit_types: [CFn, RustFn, RustArgs],
8585
extra: (basis, op, inputs),
8686
fn_extra: match MACRO_FN_NAME {
87-
copysignf128
87+
ceilf128
88+
| ceilf16
89+
| copysignf128
8890
| copysignf16
8991
| fabsf128
9092
| fabsf16

etc/function-definitions.json

+18-2
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,33 @@
109109
"src/libm_helper.rs",
110110
"src/math/arch/i586.rs",
111111
"src/math/arch/wasm32.rs",
112-
"src/math/ceil.rs"
112+
"src/math/ceil.rs",
113+
"src/math/generic/ceil.rs"
113114
],
114115
"type": "f64"
115116
},
116117
"ceilf": {
117118
"sources": [
118119
"src/math/arch/wasm32.rs",
119-
"src/math/ceilf.rs"
120+
"src/math/ceilf.rs",
121+
"src/math/generic/ceil.rs"
120122
],
121123
"type": "f32"
122124
},
125+
"ceilf128": {
126+
"sources": [
127+
"src/math/ceilf128.rs",
128+
"src/math/generic/ceil.rs"
129+
],
130+
"type": "f128"
131+
},
132+
"ceilf16": {
133+
"sources": [
134+
"src/math/ceilf16.rs",
135+
"src/math/generic/ceil.rs"
136+
],
137+
"type": "f16"
138+
},
123139
"copysign": {
124140
"sources": [
125141
"src/libm_helper.rs",

etc/function-list.txt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ cbrt
1717
cbrtf
1818
ceil
1919
ceilf
20+
ceilf128
21+
ceilf16
2022
copysign
2123
copysignf
2224
copysignf128

src/math/ceilf128.rs

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

src/math/ceilf16.rs

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

src/math/generic/ceil.rs

+14
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ mod tests {
6363
}
6464
}
6565

66+
/* Skipping f16 / f128 "sanity_check"s due to rejected literal lexing at MSRV */
67+
68+
#[test]
69+
#[cfg(f16_enabled)]
70+
fn spec_tests_f16() {
71+
spec_test::<f16>();
72+
}
73+
6674
#[test]
6775
fn sanity_check_f32() {
6876
assert_eq!(ceil(1.1f32), 2.0);
@@ -84,4 +92,10 @@ mod tests {
8492
fn spec_tests_f64() {
8593
spec_test::<f64>();
8694
}
95+
96+
#[test]
97+
#[cfg(f128_enabled)]
98+
fn spec_tests_f128() {
99+
spec_test::<f128>();
100+
}
87101
}

src/math/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,14 @@ pub use self::truncf::truncf;
341341

342342
cfg_if! {
343343
if #[cfg(f16_enabled)] {
344+
mod ceilf16;
344345
mod copysignf16;
345346
mod fabsf16;
346347
mod fdimf16;
347348
mod sqrtf16;
348349
mod truncf16;
349350

351+
pub use self::ceilf16::ceilf16;
350352
pub use self::copysignf16::copysignf16;
351353
pub use self::fabsf16::fabsf16;
352354
pub use self::fdimf16::fdimf16;
@@ -357,12 +359,14 @@ cfg_if! {
357359

358360
cfg_if! {
359361
if #[cfg(f128_enabled)] {
362+
mod ceilf128;
360363
mod copysignf128;
361364
mod fabsf128;
362365
mod fdimf128;
363366
mod sqrtf128;
364367
mod truncf128;
365368

369+
pub use self::ceilf128::ceilf128;
366370
pub use self::copysignf128::copysignf128;
367371
pub use self::fabsf128::fabsf128;
368372
pub use self::fdimf128::fdimf128;

0 commit comments

Comments
 (0)