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

Commit 45af771

Browse files
committed
Use wasm32 arch intrinsics for rint{,f}
1 parent 1666f41 commit 45af771

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

libm/etc/function-definitions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,14 @@
604604
"rint": {
605605
"sources": [
606606
"src/libm_helper.rs",
607+
"src/math/arch/wasm32.rs",
607608
"src/math/rint.rs"
608609
],
609610
"type": "f64"
610611
},
611612
"rintf": {
612613
"sources": [
614+
"src/math/arch/wasm32.rs",
613615
"src/math/rintf.rs"
614616
],
615617
"type": "f32"

libm/src/math/arch/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
cfg_if! {
1212
if #[cfg(all(target_arch = "wasm32", intrinsics_enabled))] {
1313
mod wasm32;
14-
pub use wasm32::{ceil, ceilf, fabs, fabsf, floor, floorf, sqrt, sqrtf, trunc, truncf};
14+
pub use wasm32::{
15+
ceil, ceilf, fabs, fabsf, floor, floorf, rint, rintf, sqrt, sqrtf, trunc, truncf,
16+
};
1517
} else if #[cfg(target_feature = "sse2")] {
1618
mod i686;
1719
pub use i686::{sqrt, sqrtf};

libm/src/math/arch/wasm32.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ pub fn floorf(x: f32) -> f32 {
2525
core::arch::wasm32::f32_floor(x)
2626
}
2727

28+
pub fn rint(x: f64) -> f64 {
29+
core::arch::wasm32::f64_nearest(x)
30+
}
31+
32+
pub fn rintf(x: f32) -> f32 {
33+
core::arch::wasm32::f32_nearest(x)
34+
}
35+
2836
pub fn sqrt(x: f64) -> f64 {
2937
core::arch::wasm32::f64_sqrt(x)
3038
}

libm/src/math/rint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
22
pub fn rint(x: f64) -> f64 {
3+
select_implementation! {
4+
name: rint,
5+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
6+
args: x,
7+
}
8+
39
let one_over_e = 1.0 / f64::EPSILON;
410
let as_u64: u64 = x.to_bits();
511
let exponent: u64 = (as_u64 >> 52) & 0x7ff;

libm/src/math/rintf.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
22
pub fn rintf(x: f32) -> f32 {
3+
select_implementation! {
4+
name: rintf,
5+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
6+
args: x,
7+
}
8+
39
let one_over_e = 1.0 / f32::EPSILON;
410
let as_u32: u32 = x.to_bits();
511
let exponent: u32 = (as_u32 >> 23) & 0xff;

0 commit comments

Comments
 (0)