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

Commit 07a52ff

Browse files
committed
Make use of select_implementation
Replace all uses of `llvm_intrinsically` with select_implementation`.
1 parent f216aab commit 07a52ff

File tree

11 files changed

+50
-90
lines changed

11 files changed

+50
-90
lines changed

src/math/ceil.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ const TOINT: f64 = 1. / f64::EPSILON;
88
/// Finds the nearest integer greater than or equal to `x`.
99
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1010
pub fn ceil(x: f64) -> f64 {
11-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
12-
// `f64.ceil` native instruction, so we can leverage this for both code size
13-
// and speed.
14-
llvm_intrinsically_optimized! {
15-
#[cfg(target_arch = "wasm32")] {
16-
return unsafe { ::core::intrinsics::ceilf64(x) }
17-
}
11+
select_implementation! {
12+
name: ceil,
13+
use_intrinsic: target_arch = "wasm32",
14+
args: x,
1815
}
16+
1917
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
2018
{
2119
//use an alternative implementation on x86, because the

src/math/ceilf.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ use core::f32;
55
/// Finds the nearest integer greater than or equal to `x`.
66
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
77
pub fn ceilf(x: f32) -> f32 {
8-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
9-
// `f32.ceil` native instruction, so we can leverage this for both code size
10-
// and speed.
11-
llvm_intrinsically_optimized! {
12-
#[cfg(target_arch = "wasm32")] {
13-
return unsafe { ::core::intrinsics::ceilf32(x) }
14-
}
8+
select_implementation! {
9+
name: ceilf,
10+
use_intrinsic: target_arch = "wasm32",
11+
args: x,
1512
}
13+
1614
let mut ui = x.to_bits();
1715
let e = (((ui >> 23) & 0xff).wrapping_sub(0x7f)) as i32;
1816

src/math/fabs.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ use core::u64;
55
/// by direct manipulation of the bit representation of `x`.
66
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
77
pub fn fabs(x: f64) -> f64 {
8-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
9-
// `f64.abs` native instruction, so we can leverage this for both code size
10-
// and speed.
11-
llvm_intrinsically_optimized! {
12-
#[cfg(target_arch = "wasm32")] {
13-
return unsafe { ::core::intrinsics::fabsf64(x) }
14-
}
8+
select_implementation! {
9+
name: fabs,
10+
use_intrinsic: target_arch = "wasm32",
11+
args: x,
1512
}
13+
1614
f64::from_bits(x.to_bits() & (u64::MAX / 2))
1715
}
1816

src/math/fabsf.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
/// by direct manipulation of the bit representation of `x`.
44
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
55
pub fn fabsf(x: f32) -> f32 {
6-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
7-
// `f32.abs` native instruction, so we can leverage this for both code size
8-
// and speed.
9-
llvm_intrinsically_optimized! {
10-
#[cfg(target_arch = "wasm32")] {
11-
return unsafe { ::core::intrinsics::fabsf32(x) }
12-
}
6+
select_implementation! {
7+
name: fabsf,
8+
use_intrinsic: target_arch = "wasm32",
9+
args: x,
1310
}
11+
1412
f32::from_bits(x.to_bits() & 0x7fffffff)
1513
}
1614

src/math/floor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ const TOINT: f64 = 1. / f64::EPSILON;
88
/// Finds the nearest integer less than or equal to `x`.
99
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1010
pub fn floor(x: f64) -> f64 {
11-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
12-
// `f64.floor` native instruction, so we can leverage this for both code size
13-
// and speed.
14-
llvm_intrinsically_optimized! {
15-
#[cfg(target_arch = "wasm32")] {
16-
return unsafe { ::core::intrinsics::floorf64(x) }
17-
}
11+
select_implementation! {
12+
name: floor,
13+
use_intrinsic: target_arch = "wasm32",
14+
args: x,
1815
}
16+
1917
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
2018
{
2119
//use an alternative implementation on x86, because the

src/math/floorf.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ use core::f32;
55
/// Finds the nearest integer less than or equal to `x`.
66
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
77
pub fn floorf(x: f32) -> f32 {
8-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
9-
// `f32.floor` native instruction, so we can leverage this for both code size
10-
// and speed.
11-
llvm_intrinsically_optimized! {
12-
#[cfg(target_arch = "wasm32")] {
13-
return unsafe { ::core::intrinsics::floorf32(x) }
14-
}
8+
select_implementation! {
9+
name: floorf,
10+
use_intrinsic: target_arch = "wasm32",
11+
args: x,
1512
}
13+
1614
let mut ui = x.to_bits();
1715
let e = (((ui >> 23) as i32) & 0xff) - 0x7f;
1816

src/math/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ macro_rules! div {
7474
};
7575
}
7676

77-
// FIXME: phase this out, to be replaced by the more flexible `select_implementation`
78-
macro_rules! llvm_intrinsically_optimized {
79-
(#[cfg($($clause:tt)*)] $e:expr) => {
80-
#[cfg(all(intrinsics_enabled, not(feature = "force-soft-floats"), $($clause)*))]
81-
{
82-
if true { // thwart the dead code lint
83-
$e
84-
}
85-
}
86-
};
87-
}
88-
8977
// Private modules
9078
#[macro_use]
9179
mod support;

src/math/sqrt.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,12 @@ use core::f64;
8181
/// The square root of `x` (f64).
8282
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
8383
pub fn sqrt(x: f64) -> f64 {
84-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
85-
// `f64.sqrt` native instruction, so we can leverage this for both code size
86-
// and speed.
87-
llvm_intrinsically_optimized! {
88-
#[cfg(target_arch = "wasm32")] {
89-
return if x < 0.0 {
90-
f64::NAN
91-
} else {
92-
unsafe { ::core::intrinsics::sqrtf64(x) }
93-
}
94-
}
84+
select_implementation! {
85+
name: sqrt,
86+
use_intrinsic: target_arch = "wasm32",
87+
args: x,
9588
}
89+
9690
#[cfg(all(target_feature = "sse2", not(feature = "force-soft-floats")))]
9791
{
9892
// Note: This path is unlikely since LLVM will usually have already

src/math/sqrtf.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
/// The square root of `x` (f32).
1717
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1818
pub fn sqrtf(x: f32) -> f32 {
19-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
20-
// `f32.sqrt` native instruction, so we can leverage this for both code size
21-
// and speed.
22-
llvm_intrinsically_optimized! {
23-
#[cfg(target_arch = "wasm32")] {
24-
return if x < 0.0 {
25-
::core::f32::NAN
26-
} else {
27-
unsafe { ::core::intrinsics::sqrtf32(x) }
28-
}
29-
}
19+
select_implementation! {
20+
name: sqrtf,
21+
use_intrinsic: target_arch = "wasm32",
22+
args: x,
3023
}
24+
3125
#[cfg(all(target_feature = "sse", not(feature = "force-soft-floats")))]
3226
{
3327
// Note: This path is unlikely since LLVM will usually have already

src/math/trunc.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ use core::f64;
22

33
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
44
pub fn trunc(x: f64) -> f64 {
5-
// On wasm32 we know that LLVM's intrinsic will compile to an optimized
6-
// `f64.trunc` native instruction, so we can leverage this for both code size
7-
// and speed.
8-
llvm_intrinsically_optimized! {
9-
#[cfg(target_arch = "wasm32")] {
10-
return unsafe { ::core::intrinsics::truncf64(x) }
11-
}
5+
select_implementation! {
6+
name: trunc,
7+
use_intrinsic: target_arch = "wasm32",
8+
args: x,
129
}
10+
1311
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120
1412

1513
let mut i: u64 = x.to_bits();

0 commit comments

Comments
 (0)