Skip to content

Commit 0a65206

Browse files
josephlrAaronKutch
authored andcommitted
Move from an "asm" flag to a "no-asm" feature flag (rust-lang#386)
* Use a no-asm feature instead of an asm feature This works better as core/alloc/std have trouble supporting default featues in this crate. Signed-off-by: Joe Richey <[email protected]> * Have no-asm disable arm assembly intrinsics Signed-off-by: Joe Richey <[email protected]>
1 parent 5e41b86 commit 0a65206

File tree

10 files changed

+65
-28
lines changed

10 files changed

+65
-28
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ panic-handler = { path = 'crates/panic-handler' }
4040
[features]
4141
default = ["compiler-builtins"]
4242

43-
# Some algorithms benefit from inline assembly, but some compiler backends do
44-
# not support it, so inline assembly is only enabled when this flag is set.
45-
asm = []
46-
4743
# Enable compilation of C code in compiler-rt, filling in some more optimized
4844
# implementations and also filling in unimplemented intrinsics
4945
c = ["cc"]
5046

47+
# Workaround for the Cranelift codegen backend. Disables any implementations
48+
# which use inline assembly and fall back to pure Rust versions (if avalible).
49+
no-asm = []
50+
5151
# Flag this library as the unstable compiler-builtins lib
5252
compiler-builtins = []
5353

ci/run.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ else
1212
$run --release
1313
$run --features c
1414
$run --features c --release
15-
$run --features asm
16-
$run --features asm --release
15+
$run --features no-asm
16+
$run --features no-asm --release
1717
fi
1818

1919
cargo build --target $1
2020
cargo build --target $1 --release
2121
cargo build --target $1 --features c
2222
cargo build --target $1 --release --features c
23-
cargo build --target $1 --features asm
24-
cargo build --target $1 --release --features asm
23+
cargo build --target $1 --features no-asm
24+
cargo build --target $1 --release --features no-asm
2525

2626
PREFIX=$(echo $1 | sed -e 's/unknown-//')-
2727
case $1 in

src/arm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(feature = "no-asm"))]
2+
13
use core::intrinsics;
24

35
// NOTE This function and the ones below are implemented using assembly because they using a custom

src/int/specialized_div_rem/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn u64_by_u64_div_rem(duo: u64, div: u64) -> (u64, u64) {
115115
// microarchitecture can multiply and divide. We decide to be optimistic and assume `trifecta` is
116116
// faster if the target pointer width is at least 64.
117117
#[cfg(all(
118-
not(all(feature = "asm", target_arch = "x86_64")),
118+
not(all(not(feature = "no-asm"), target_arch = "x86_64")),
119119
not(any(target_pointer_width = "16", target_pointer_width = "32"))
120120
))]
121121
impl_trifecta!(
@@ -131,7 +131,7 @@ impl_trifecta!(
131131
// If the pointer width less than 64, then the target architecture almost certainly does not have
132132
// the fast 64 to 128 bit widening multiplication needed for `trifecta` to be faster.
133133
#[cfg(all(
134-
not(all(feature = "asm", target_arch = "x86_64")),
134+
not(all(not(feature = "no-asm"), target_arch = "x86_64")),
135135
any(target_pointer_width = "16", target_pointer_width = "32")
136136
))]
137137
impl_delegate!(
@@ -152,7 +152,7 @@ impl_delegate!(
152152
///
153153
/// If the quotient does not fit in a `u64`, a floating point exception occurs.
154154
/// If `div == 0`, then a division by zero exception occurs.
155-
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
155+
#[cfg(all(not(feature = "no-asm"), target_arch = "x86_64"))]
156156
#[inline]
157157
unsafe fn u128_by_u64_div_rem(duo: u128, div: u64) -> (u64, u64) {
158158
let duo_lo = duo as u64;
@@ -174,7 +174,7 @@ unsafe fn u128_by_u64_div_rem(duo: u128, div: u64) -> (u64, u64) {
174174
}
175175

176176
// use `asymmetric` instead of `trifecta` on x86_64
177-
#[cfg(all(feature = "asm", target_arch = "x86_64"))]
177+
#[cfg(all(not(feature = "no-asm"), target_arch = "x86_64"))]
178178
impl_asymmetric!(
179179
u128_div_rem,
180180
zero_div_fn,
@@ -203,7 +203,7 @@ fn u32_by_u32_div_rem(duo: u32, div: u32) -> (u32, u32) {
203203
// When not on x86 and the pointer width is not 64, use `delegate` since the division size is larger
204204
// than register size.
205205
#[cfg(all(
206-
not(all(feature = "asm", target_arch = "x86")),
206+
not(all(not(feature = "no-asm"), target_arch = "x86")),
207207
not(target_pointer_width = "64")
208208
))]
209209
impl_delegate!(
@@ -220,7 +220,7 @@ impl_delegate!(
220220

221221
// When not on x86 and the pointer width is 64, use `binary_long`.
222222
#[cfg(all(
223-
not(all(feature = "asm", target_arch = "x86")),
223+
not(all(not(feature = "no-asm"), target_arch = "x86")),
224224
target_pointer_width = "64"
225225
))]
226226
impl_binary_long!(
@@ -238,7 +238,7 @@ impl_binary_long!(
238238
///
239239
/// If the quotient does not fit in a `u32`, a floating point exception occurs.
240240
/// If `div == 0`, then a division by zero exception occurs.
241-
#[cfg(all(feature = "asm", target_arch = "x86"))]
241+
#[cfg(all(not(feature = "no-asm"), target_arch = "x86"))]
242242
#[inline]
243243
unsafe fn u64_by_u32_div_rem(duo: u64, div: u32) -> (u32, u32) {
244244
let duo_lo = duo as u32;
@@ -260,7 +260,7 @@ unsafe fn u64_by_u32_div_rem(duo: u64, div: u32) -> (u32, u32) {
260260
}
261261

262262
// use `asymmetric` instead of `delegate` on x86
263-
#[cfg(all(feature = "asm", target_arch = "x86"))]
263+
#[cfg(all(not(feature = "no-asm"), target_arch = "x86"))]
264264
impl_asymmetric!(
265265
u64_div_rem,
266266
zero_div_fn,

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
2-
#![cfg_attr(feature = "asm", feature(asm))]
2+
#![cfg_attr(not(feature = "no-asm"), feature(asm))]
33
#![feature(abi_unadjusted)]
4-
#![feature(llvm_asm)]
5-
#![feature(global_asm)]
4+
#![cfg_attr(not(feature = "no-asm"), feature(llvm_asm))]
5+
#![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
66
#![feature(cfg_target_has_atomic)]
77
#![feature(compiler_builtins)]
88
#![feature(core_intrinsics)]

src/mem/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use core::mem;
1010
use core::ops::{BitOr, Shl};
1111

1212
// memcpy/memmove/memset have optimized implementations on some architectures
13-
#[cfg_attr(all(feature = "asm", target_arch = "x86_64"), path = "x86_64.rs")]
13+
#[cfg_attr(
14+
all(not(feature = "no-asm"), target_arch = "x86_64"),
15+
path = "x86_64.rs"
16+
)]
1417
mod impls;
1518

1619
#[cfg_attr(all(feature = "mem", not(feature = "mangled-names")), no_mangle)]

src/probestack.rs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#![cfg(not(feature = "mangled-names"))]
4545
// Windows already has builtins to do this.
4646
#![cfg(not(windows))]
47+
// All these builtins require assembly
48+
#![cfg(not(feature = "no-asm"))]
4749
// We only define stack probing for these architectures today.
4850
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]
4951

src/x86.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use core::intrinsics;
88
// NOTE These functions are never mangled as they are not tested against compiler-rt
99
// and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
1010

11-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
11+
#[cfg(all(
12+
windows,
13+
target_env = "gnu",
14+
not(feature = "no-asm"),
15+
not(feature = "mangled-names")
16+
))]
1217
#[naked]
1318
#[no_mangle]
1419
pub unsafe fn ___chkstk_ms() {
@@ -34,7 +39,12 @@ pub unsafe fn ___chkstk_ms() {
3439
}
3540

3641
// FIXME: __alloca should be an alias to __chkstk
37-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
42+
#[cfg(all(
43+
windows,
44+
target_env = "gnu",
45+
not(feature = "no-asm"),
46+
not(feature = "mangled-names")
47+
))]
3848
#[naked]
3949
#[no_mangle]
4050
pub unsafe fn __alloca() {
@@ -43,7 +53,12 @@ pub unsafe fn __alloca() {
4353
intrinsics::unreachable();
4454
}
4555

46-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
56+
#[cfg(all(
57+
windows,
58+
target_env = "gnu",
59+
not(feature = "no-asm"),
60+
not(feature = "mangled-names")
61+
))]
4762
#[naked]
4863
#[no_mangle]
4964
pub unsafe fn ___chkstk() {

src/x86_64.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use core::intrinsics;
88
// NOTE These functions are never mangled as they are not tested against compiler-rt
99
// and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
1010

11-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
11+
#[cfg(all(
12+
windows,
13+
target_env = "gnu",
14+
not(feature = "no-asm"),
15+
not(feature = "mangled-names")
16+
))]
1217
#[naked]
1318
#[no_mangle]
1419
pub unsafe fn ___chkstk_ms() {
@@ -33,7 +38,12 @@ pub unsafe fn ___chkstk_ms() {
3338
intrinsics::unreachable();
3439
}
3540

36-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
41+
#[cfg(all(
42+
windows,
43+
target_env = "gnu",
44+
not(feature = "no-asm"),
45+
not(feature = "mangled-names")
46+
))]
3747
#[naked]
3848
#[no_mangle]
3949
pub unsafe fn __alloca() {
@@ -43,7 +53,12 @@ pub unsafe fn __alloca() {
4353
intrinsics::unreachable();
4454
}
4555

46-
#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
56+
#[cfg(all(
57+
windows,
58+
target_env = "gnu",
59+
not(feature = "no-asm"),
60+
not(feature = "mangled-names")
61+
))]
4762
#[naked]
4863
#[no_mangle]
4964
pub unsafe fn ___chkstk() {

testcrate/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ utest-cortex-m-qemu = { default-features = false, git = "https://github.com/japa
2828
utest-macros = { git = "https://github.com/japaric/utest" }
2929

3030
[features]
31-
default = ["asm", "mangled-names"]
32-
asm = ["compiler_builtins/asm"]
31+
default = ["mangled-names"]
3332
c = ["compiler_builtins/c"]
33+
no-asm = ["compiler_builtins/no-asm"]
3434
mem = ["compiler_builtins/mem"]
3535
mangled-names = ["compiler_builtins/mangled-names"]

0 commit comments

Comments
 (0)