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

Commit 44770b9

Browse files
committed
Replace "intrinsic" config with "arch" config
WASM is the only architecture we use `intrinsics::` for. We probably don't want to do this for any other architectures since it is better to use assembly, or work toward getting the functions available in `core`. To more accurately reflect the relationship between arch and intrinsics, make wasm32 an `arch` module and call the intrinsics from there.
1 parent 424c3ec commit 44770b9

File tree

14 files changed

+37
-50
lines changed

14 files changed

+37
-50
lines changed

etc/function-definitions.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@
108108
"sources": [
109109
"src/libm_helper.rs",
110110
"src/math/arch/i586.rs",
111-
"src/math/arch/intrinsics.rs",
111+
"src/math/arch/wasm32.rs",
112112
"src/math/ceil.rs"
113113
],
114114
"type": "f64"
115115
},
116116
"ceilf": {
117117
"sources": [
118-
"src/math/arch/intrinsics.rs",
118+
"src/math/arch/wasm32.rs",
119119
"src/math/ceilf.rs"
120120
],
121121
"type": "f32"
@@ -258,15 +258,15 @@
258258
"fabs": {
259259
"sources": [
260260
"src/libm_helper.rs",
261-
"src/math/arch/intrinsics.rs",
261+
"src/math/arch/wasm32.rs",
262262
"src/math/fabs.rs",
263263
"src/math/generic/fabs.rs"
264264
],
265265
"type": "f64"
266266
},
267267
"fabsf": {
268268
"sources": [
269-
"src/math/arch/intrinsics.rs",
269+
"src/math/arch/wasm32.rs",
270270
"src/math/fabsf.rs",
271271
"src/math/generic/fabs.rs"
272272
],
@@ -303,14 +303,14 @@
303303
"sources": [
304304
"src/libm_helper.rs",
305305
"src/math/arch/i586.rs",
306-
"src/math/arch/intrinsics.rs",
306+
"src/math/arch/wasm32.rs",
307307
"src/math/floor.rs"
308308
],
309309
"type": "f64"
310310
},
311311
"floorf": {
312312
"sources": [
313-
"src/math/arch/intrinsics.rs",
313+
"src/math/arch/wasm32.rs",
314314
"src/math/floorf.rs"
315315
],
316316
"type": "f32"
@@ -683,15 +683,15 @@
683683
"sources": [
684684
"src/libm_helper.rs",
685685
"src/math/arch/i686.rs",
686-
"src/math/arch/intrinsics.rs",
686+
"src/math/arch/wasm32.rs",
687687
"src/math/sqrt.rs"
688688
],
689689
"type": "f64"
690690
},
691691
"sqrtf": {
692692
"sources": [
693693
"src/math/arch/i686.rs",
694-
"src/math/arch/intrinsics.rs",
694+
"src/math/arch/wasm32.rs",
695695
"src/math/sqrtf.rs"
696696
],
697697
"type": "f32"
@@ -738,14 +738,14 @@
738738
"trunc": {
739739
"sources": [
740740
"src/libm_helper.rs",
741-
"src/math/arch/intrinsics.rs",
741+
"src/math/arch/wasm32.rs",
742742
"src/math/trunc.rs"
743743
],
744744
"type": "f64"
745745
},
746746
"truncf": {
747747
"sources": [
748-
"src/math/arch/intrinsics.rs",
748+
"src/math/arch/wasm32.rs",
749749
"src/math/truncf.rs"
750750
],
751751
"type": "f32"

src/math/arch/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
//! is used when calling the function directly. This helps anyone who uses `libm` directly, as
66
//! well as improving things when these routines are called as part of other implementations.
77
8-
#[cfg(intrinsics_enabled)]
9-
pub mod intrinsics;
10-
118
// Most implementations should be defined here, to ensure they are not made available when
129
// soft floats are required.
1310
#[cfg(arch_enabled)]
1411
cfg_if! {
15-
if #[cfg(target_feature = "sse2")] {
12+
if #[cfg(all(target_arch = "wasm32", intrinsics_enabled))] {
13+
mod wasm32;
14+
pub use wasm32::{ceil, ceilf, fabs, fabsf, floor, floorf, sqrt, sqrtf, trunc, truncf};
15+
} else if #[cfg(target_feature = "sse2")] {
1616
mod i686;
1717
pub use i686::{sqrt, sqrtf};
1818
}

src/math/arch/intrinsics.rs renamed to src/math/arch/wasm32.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Config is needed for times when this module is available but we don't call everything
2-
#![allow(dead_code)]
1+
//! Wasm asm is not stable; just use intrinsics for operations that have asm routine equivalents.
2+
//!
3+
//! Note that we need to be absolutely certain that everything here lowers to assembly operations,
4+
//! otherwise libcalls will be recursive.
35
46
pub fn ceil(x: f64) -> f64 {
57
// SAFETY: safe intrinsic with no preconditions

src/math/ceil.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const TOINT: f64 = 1. / f64::EPSILON;
1010
pub fn ceil(x: f64) -> f64 {
1111
select_implementation! {
1212
name: ceil,
13+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1314
use_arch_required: all(target_arch = "x86", not(target_feature = "sse2")),
14-
use_intrinsic: target_arch = "wasm32",
1515
args: x,
1616
}
1717

src/math/ceilf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::f32;
77
pub fn ceilf(x: f32) -> f32 {
88
select_implementation! {
99
name: ceilf,
10-
use_intrinsic: target_arch = "wasm32",
10+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1111
args: x,
1212
}
1313

src/math/fabs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub fn fabs(x: f64) -> f64 {
77
select_implementation! {
88
name: fabs,
9-
use_intrinsic: target_arch = "wasm32",
9+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1010
args: x,
1111
}
1212

src/math/fabsf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub fn fabsf(x: f32) -> f32 {
77
select_implementation! {
88
name: fabsf,
9-
use_intrinsic: target_arch = "wasm32",
9+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1010
args: x,
1111
}
1212

src/math/floor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const TOINT: f64 = 1. / f64::EPSILON;
1010
pub fn floor(x: f64) -> f64 {
1111
select_implementation! {
1212
name: floor,
13+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1314
use_arch_required: all(target_arch = "x86", not(target_feature = "sse2")),
14-
use_intrinsic: target_arch = "wasm32",
1515
args: x,
1616
}
1717

src/math/floorf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::f32;
77
pub fn floorf(x: f32) -> f32 {
88
select_implementation! {
99
name: floorf,
10-
use_intrinsic: target_arch = "wasm32",
10+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
1111
args: x,
1212
}
1313

src/math/sqrt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ use core::f64;
8383
pub fn sqrt(x: f64) -> f64 {
8484
select_implementation! {
8585
name: sqrt,
86-
use_arch: target_feature = "sse2",
87-
use_intrinsic: target_arch = "wasm32",
86+
use_arch: any(
87+
all(target_arch = "wasm32", intrinsics_enabled),
88+
target_feature = "sse2"
89+
),
8890
args: x,
8991
}
9092

0 commit comments

Comments
 (0)