Use wasm32 arch intrinsics for rint{,f}
This commit is contained in:
parent
b50ea809ff
commit
7defd9b429
5 changed files with 25 additions and 1 deletions
|
|
@ -604,12 +604,14 @@
|
|||
"rint": {
|
||||
"sources": [
|
||||
"src/libm_helper.rs",
|
||||
"src/math/arch/wasm32.rs",
|
||||
"src/math/rint.rs"
|
||||
],
|
||||
"type": "f64"
|
||||
},
|
||||
"rintf": {
|
||||
"sources": [
|
||||
"src/math/arch/wasm32.rs",
|
||||
"src/math/rintf.rs"
|
||||
],
|
||||
"type": "f32"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
cfg_if! {
|
||||
if #[cfg(all(target_arch = "wasm32", intrinsics_enabled))] {
|
||||
mod wasm32;
|
||||
pub use wasm32::{ceil, ceilf, fabs, fabsf, floor, floorf, sqrt, sqrtf, trunc, truncf};
|
||||
pub use wasm32::{
|
||||
ceil, ceilf, fabs, fabsf, floor, floorf, rint, rintf, sqrt, sqrtf, trunc, truncf,
|
||||
};
|
||||
} else if #[cfg(target_feature = "sse2")] {
|
||||
mod i686;
|
||||
pub use i686::{sqrt, sqrtf};
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ pub fn floorf(x: f32) -> f32 {
|
|||
core::arch::wasm32::f32_floor(x)
|
||||
}
|
||||
|
||||
pub fn rint(x: f64) -> f64 {
|
||||
core::arch::wasm32::f64_nearest(x)
|
||||
}
|
||||
|
||||
pub fn rintf(x: f32) -> f32 {
|
||||
core::arch::wasm32::f32_nearest(x)
|
||||
}
|
||||
|
||||
pub fn sqrt(x: f64) -> f64 {
|
||||
core::arch::wasm32::f64_sqrt(x)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn rint(x: f64) -> f64 {
|
||||
select_implementation! {
|
||||
name: rint,
|
||||
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
|
||||
args: x,
|
||||
}
|
||||
|
||||
let one_over_e = 1.0 / f64::EPSILON;
|
||||
let as_u64: u64 = x.to_bits();
|
||||
let exponent: u64 = (as_u64 >> 52) & 0x7ff;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn rintf(x: f32) -> f32 {
|
||||
select_implementation! {
|
||||
name: rintf,
|
||||
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
|
||||
args: x,
|
||||
}
|
||||
|
||||
let one_over_e = 1.0 / f32::EPSILON;
|
||||
let as_u32: u32 = x.to_bits();
|
||||
let exponent: u32 = (as_u32 >> 23) & 0xff;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue