Skip to content

Commit b25aa4b

Browse files
committed
Add ceilf16 and ceilf128
Use the generic algorithms to provide implementations for these routines.
1 parent eeb0d8e commit b25aa4b

16 files changed

+297
-6
lines changed

br-ceil.txt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.globl libm::math::ceil::ceil
2+
.p2align 2
3+
libm::math::ceil::ceil:
4+
Lfunc_begin17:
5+
.cfi_startproc
6+
sub sp, sp, #16
7+
.cfi_def_cfa_offset 16
8+
fcmp d0, #0.0
9+
b.eq LBB17_5
10+
fmov x8, d0
11+
ubfx x9, x8, #52, #11
12+
cmp w9, #1074
13+
b.hi LBB17_5
14+
mov x10, #-4382002437431492608
15+
fmov d1, x10
16+
fadd d2, d0, d1
17+
mov x10, #4841369599423283200
18+
fmov d3, x10
19+
fadd d2, d2, d3
20+
fadd d3, d0, d3
21+
fadd d1, d3, d1
22+
cmp x8, #0
23+
fcsel d1, d2, d1, lt
24+
fsub d1, d1, d0
25+
str d1, [sp, #8]
26+
cmp w9, #1023
27+
b.hs LBB17_4
28+
ldr d0, [sp, #8]
29+
cmp x8, #0
30+
mov x8, #-9223372036854775808
31+
fmov d0, x8
32+
fmov d1, #1.00000000
33+
fcsel d0, d0, d1, lt
34+
b LBB17_5
35+
LBB17_4:
36+
fadd d0, d1, d0
37+
fmov d2, #1.00000000
38+
fadd d2, d0, d2
39+
fcmp d1, #0.0
40+
fcsel d0, d2, d0, mi
41+
LBB17_5:
42+
add sp, sp, #16
43+
.cfi_def_cfa_offset 0
44+
ret

br-ceil1.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.globl libm::math::ceilf::ceilf
2+
.p2align 2
3+
libm::math::ceilf::ceilf:
4+
Lfunc_begin18:
5+
.cfi_startproc
6+
sub sp, sp, #16
7+
.cfi_def_cfa_offset 16
8+
fcmp s0, #0.0
9+
b.eq LBB18_5
10+
fmov w8, s0
11+
ubfx w9, w8, #23, #8
12+
cmp w9, #149
13+
b.hi LBB18_5
14+
movi.2s v1, #203, lsl #24
15+
fadd s2, s0, s1
16+
movi.2s v3, #75, lsl #24
17+
fadd s2, s2, s3
18+
fadd s3, s0, s3
19+
fadd s1, s3, s1
20+
cmp w8, #0
21+
fcsel s1, s2, s1, lt
22+
fsub s1, s1, s0
23+
str s1, [sp, #12]
24+
cmp w9, #127
25+
b.hs LBB18_4
26+
ldr s0, [sp, #12]
27+
cmp w8, #0
28+
movi.2s v0, #128, lsl #24
29+
fmov s1, #1.00000000
30+
fcsel s0, s0, s1, lt
31+
b LBB18_5
32+
LBB18_4:
33+
fadd s0, s1, s0
34+
fmov s2, #1.00000000
35+
fadd s2, s0, s2
36+
fcmp s1, #0.0
37+
fcsel s0, s2, s0, mi
38+
LBB18_5:
39+
add sp, sp, #16
40+
.cfi_def_cfa_offset 0
41+
ret

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/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

m-ceil.txt

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.globl libm::math::ceil::ceil
2+
.p2align 2
3+
libm::math::ceil::ceil:
4+
Lfunc_begin17:
5+
.cfi_startproc
6+
sub sp, sp, #16
7+
.cfi_def_cfa_offset 16
8+
fcmp d0, #0.0
9+
b.eq LBB17_8
10+
fmov x9, d0
11+
ubfx x8, x9, #52, #11
12+
cmp x8, #1074
13+
b.hi LBB17_8
14+
tbnz x9, #63, LBB17_5
15+
mov x9, #4841369599423283200
16+
fmov d1, x9
17+
fadd d1, d0, d1
18+
mov x9, #-4382002437431492608
19+
fmov d2, x9
20+
fadd d1, d1, d2
21+
fsub d1, d1, d0
22+
str d1, [sp, #8]
23+
cmp x8, #1023
24+
b.hs LBB17_7
25+
ldr d0, [sp, #8]
26+
fmov d0, #1.00000000
27+
b LBB17_8
28+
LBB17_5:
29+
mov x9, #-4382002437431492608
30+
fmov d1, x9
31+
fadd d1, d0, d1
32+
mov x9, #4841369599423283200
33+
fmov d2, x9
34+
fadd d1, d1, d2
35+
fsub d1, d1, d0
36+
str d1, [sp, #8]
37+
cmp x8, #1023
38+
b.hs LBB17_7
39+
ldr d0, [sp, #8]
40+
mov x8, #-9223372036854775808
41+
fmov d0, x8
42+
b LBB17_8
43+
LBB17_7:
44+
fadd d0, d1, d0
45+
fmov d2, #1.00000000
46+
fadd d2, d0, d2
47+
fcmp d1, #0.0
48+
fcsel d0, d2, d0, mi
49+
LBB17_8:
50+
add sp, sp, #16
51+
.cfi_def_cfa_offset 0
52+
ret

m-ceil1.txt

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.globl libm::math::ceilf::ceilf
2+
.p2align 2
3+
libm::math::ceilf::ceilf:
4+
Lfunc_begin18:
5+
.cfi_startproc
6+
sub sp, sp, #16
7+
.cfi_def_cfa_offset 16
8+
fmov w8, s0
9+
ubfx w9, w8, #23, #8
10+
cmp w9, #149
11+
b.hi LBB18_5
12+
cmp w9, #126
13+
b.ls LBB18_4
14+
lsr w9, w8, #23
15+
add w10, w9, #1
16+
mov w9, #8388607
17+
lsr w9, w9, w10
18+
tst w9, w8
19+
b.eq LBB18_5
20+
and w10, w10, #0x1f
21+
mov w11, #2071986176
22+
fmov s1, w11
23+
fadd s0, s0, s1
24+
str s0, [sp, #8]
25+
ldr s0, [sp, #8]
26+
cmp w8, #0
27+
csel w9, wzr, w9, lt
28+
mov w11, #-8388608
29+
asr w10, w11, w10
30+
add w8, w9, w8
31+
and w8, w8, w10
32+
fmov s0, w8
33+
b LBB18_5
34+
LBB18_4:
35+
mov w9, #2071986176
36+
fmov s1, w9
37+
fadd s1, s0, s1
38+
str s1, [sp, #12]
39+
ldr s1, [sp, #12]
40+
movi.2s v1, #128, lsl #24
41+
cmp w8, #0
42+
fmov s2, #1.00000000
43+
fcsel s0, s0, s2, eq
44+
tst w8, #0x80000000
45+
fcsel s0, s0, s1, eq
46+
LBB18_5:
47+
add sp, sp, #16
48+
.cfi_def_cfa_offset 0
49+
ret

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)