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

Commit 753d69f

Browse files
authored
Merge pull request #454 from tgross35/generic-rint
Add `rintf16` and `rintf128`
2 parents 5e9ded4 + d2da7f7 commit 753d69f

File tree

16 files changed

+130
-100
lines changed

16 files changed

+130
-100
lines changed

crates/compiler-builtins-smoke-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ no_mangle! {
145145
remquof(x: f32, y: f32 | q: &mut c_int) -> f32;
146146
rint(x: f64) -> f64;
147147
rintf(x: f32) -> f32;
148+
rintf128(x: f128) -> f128;
149+
rintf16(x: f16) -> f16;
148150
round(x: f64) -> f64;
149151
roundf(x: f32) -> f32;
150152
scalbn(x: f64, y: c_int) -> f64;

crates/libm-macros/src/shared.rs

Lines changed: 2 additions & 2 deletions
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-
&["ceilf16", "fabsf16", "floorf16", "sqrtf16", "truncf16"],
12+
&["ceilf16", "fabsf16", "floorf16", "rintf16", "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-
&["ceilf128", "fabsf128", "floorf128", "sqrtf128", "truncf128"],
43+
&["ceilf128", "fabsf128", "floorf128", "rintf128", "sqrtf128", "truncf128"],
4444
),
4545
(
4646
// `(f16, f16) -> f16`

crates/libm-test/benches/icount.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ main!(
149149
icount_bench_remquo_group,
150150
icount_bench_remquof_group,
151151
icount_bench_rint_group,
152+
icount_bench_rintf128_group,
153+
icount_bench_rintf16_group,
152154
icount_bench_rintf_group,
153155
icount_bench_round_group,
154156
icount_bench_roundf_group,

crates/libm-test/benches/random.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ libm_macros::for_each_function! {
127127
| fdimf16
128128
| floorf128
129129
| floorf16
130+
| rintf128
131+
| rintf16
130132
| sqrtf128
131133
| sqrtf16
132134
| truncf128

crates/libm-test/src/mpfloat.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ libm_macros::for_each_function! {
170170
remquof,
171171
rint,
172172
rintf,
173+
rintf128,
174+
rintf16,
173175
round,
174176
roundf,
175177
scalbn,
@@ -240,17 +242,19 @@ impl_no_round! {
240242

241243
#[cfg(f16_enabled)]
242244
impl_no_round! {
243-
fabsf16 => abs_mut;
244245
ceilf16 => ceil_mut;
246+
fabsf16 => abs_mut;
245247
floorf16 => floor_mut;
248+
rintf16 => round_even_mut; // FIXME: respect rounding mode
246249
truncf16 => trunc_mut;
247250
}
248251

249252
#[cfg(f128_enabled)]
250253
impl_no_round! {
251-
fabsf128 => abs_mut;
252254
ceilf128 => ceil_mut;
255+
fabsf128 => abs_mut;
253256
floorf128 => floor_mut;
257+
rintf128 => round_even_mut; // FIXME: respect rounding mode
254258
truncf128 => trunc_mut;
255259
}
256260

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ libm_macros::for_each_function! {
8989
fdimf16,
9090
floorf128,
9191
floorf16,
92+
rintf128,
93+
rintf16,
94+
sqrtf128,
95+
sqrtf16,
9296
truncf128,
9397
truncf16,
94-
sqrtf16,
95-
sqrtf128,
9698
],
9799
}

crates/util/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9494
| fdimf16
9595
| floorf128
9696
| floorf16
97+
| rintf128
98+
| rintf16
9799
| sqrtf128
98100
| sqrtf16
99101
| truncf128

etc/function-definitions.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@
654654
"src/libm_helper.rs",
655655
"src/math/arch/aarch64.rs",
656656
"src/math/arch/wasm32.rs",
657+
"src/math/generic/rint.rs",
657658
"src/math/rint.rs"
658659
],
659660
"type": "f64"
@@ -662,10 +663,25 @@
662663
"sources": [
663664
"src/math/arch/aarch64.rs",
664665
"src/math/arch/wasm32.rs",
666+
"src/math/generic/rint.rs",
665667
"src/math/rintf.rs"
666668
],
667669
"type": "f32"
668670
},
671+
"rintf128": {
672+
"sources": [
673+
"src/math/generic/rint.rs",
674+
"src/math/rintf128.rs"
675+
],
676+
"type": "f128"
677+
},
678+
"rintf16": {
679+
"sources": [
680+
"src/math/generic/rint.rs",
681+
"src/math/rintf16.rs"
682+
],
683+
"type": "f16"
684+
},
669685
"round": {
670686
"sources": [
671687
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ remquo
9797
remquof
9898
rint
9999
rintf
100+
rintf128
101+
rintf16
100102
round
101103
roundf
102104
scalbn

src/math/generic/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod copysign;
33
mod fabs;
44
mod fdim;
55
mod floor;
6+
mod rint;
67
mod sqrt;
78
mod trunc;
89

@@ -11,5 +12,6 @@ pub use copysign::copysign;
1112
pub use fabs::fabs;
1213
pub use fdim::fdim;
1314
pub use floor::floor;
15+
pub use rint::rint;
1416
pub use sqrt::sqrt;
1517
pub use trunc::trunc;

0 commit comments

Comments
 (0)