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

Commit 53ccf52

Browse files
committed
Use wasm32 arch intrinsics for rint{,f}
1 parent 6712204 commit 53ccf52

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

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};

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
}

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;

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)