Skip to content

Commit cde22bc

Browse files
authored
Switch to using llvm_asm! instead of asm! (#351)
* Switch to using `llvm_asm!` instead of `asm!` * Run rustfmt * Fix how LTO is specified on nightly
1 parent 25ea08d commit cde22bc

File tree

7 files changed

+128
-110
lines changed

7 files changed

+128
-110
lines changed

ci/run.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ RUSTFLAGS="-C debug-assertions=no" $build_intrinsics --features c --release
8585
if [ -z "$DEBUG_LTO_BUILD_DOESNT_WORK" ]; then
8686
RUSTFLAGS="-C debug-assertions=no" \
8787
CARGO_INCREMENTAL=0 \
88-
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics -- -C lto
88+
CARGO_PROFILE_DEV_LTO=true \
89+
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics
8990
fi
90-
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics --release -- -C lto
91+
CARGO_PROFILE_RELEASE_LTO=true \
92+
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics --release
9193

9294
# Ensure no references to a panicking function
9395
for rlib in $(echo $path); do

examples/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![allow(unused_features)]
77
#![cfg_attr(thumb, no_main)]
88
#![deny(dead_code)]
9-
#![feature(asm)]
9+
#![feature(llvm_asm)]
1010
#![feature(lang_items)]
1111
#![feature(start)]
1212
#![feature(allocator_api)]
@@ -280,7 +280,7 @@ fn run() {
280280

281281
// A copy of "test::black_box". Used to prevent LLVM from optimizing away the intrinsics during LTO
282282
fn bb<T>(dummy: T) -> T {
283-
unsafe { asm!("" : : "r"(&dummy)) }
283+
unsafe { llvm_asm!("" : : "r"(&dummy)) }
284284
dummy
285285
}
286286

src/arm.rs

+78-62
Original file line numberDiff line numberDiff line change
@@ -8,117 +8,133 @@ use core::intrinsics;
88
#[naked]
99
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
1010
pub unsafe fn __aeabi_uidivmod() {
11-
asm!("push {lr}
12-
sub sp, sp, #4
13-
mov r2, sp
14-
bl __udivmodsi4
15-
ldr r1, [sp]
16-
add sp, sp, #4
17-
pop {pc}" ::: "memory" : "volatile");
11+
llvm_asm!("
12+
push {lr}
13+
sub sp, sp, #4
14+
mov r2, sp
15+
bl __udivmodsi4
16+
ldr r1, [sp]
17+
add sp, sp, #4
18+
pop {pc}
19+
" ::: "memory" : "volatile");
1820
intrinsics::unreachable();
1921
}
2022

2123
#[cfg(target_os = "ios")]
2224
#[naked]
2325
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
2426
pub unsafe fn __aeabi_uidivmod() {
25-
asm!("push {lr}
26-
sub sp, sp, #4
27-
mov r2, sp
28-
bl ___udivmodsi4
29-
ldr r1, [sp]
30-
add sp, sp, #4
31-
pop {pc}" ::: "memory" : "volatile");
27+
llvm_asm!("
28+
push {lr}
29+
sub sp, sp, #4
30+
mov r2, sp
31+
bl ___udivmodsi4
32+
ldr r1, [sp]
33+
add sp, sp, #4
34+
pop {pc}
35+
" ::: "memory" : "volatile");
3236
intrinsics::unreachable();
3337
}
3438

3539
#[cfg(not(target_os = "ios"))]
3640
#[naked]
3741
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
3842
pub unsafe fn __aeabi_uldivmod() {
39-
asm!("push {r4, lr}
40-
sub sp, sp, #16
41-
add r4, sp, #8
42-
str r4, [sp]
43-
bl __udivmoddi4
44-
ldr r2, [sp, #8]
45-
ldr r3, [sp, #12]
46-
add sp, sp, #16
47-
pop {r4, pc}" ::: "memory" : "volatile");
43+
llvm_asm!("
44+
push {r4, lr}
45+
sub sp, sp, #16
46+
add r4, sp, #8
47+
str r4, [sp]
48+
bl __udivmoddi4
49+
ldr r2, [sp, #8]
50+
ldr r3, [sp, #12]
51+
add sp, sp, #16
52+
pop {r4, pc}
53+
" ::: "memory" : "volatile");
4854
intrinsics::unreachable();
4955
}
5056

5157
#[cfg(target_os = "ios")]
5258
#[naked]
5359
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
5460
pub unsafe fn __aeabi_uldivmod() {
55-
asm!("push {r4, lr}
56-
sub sp, sp, #16
57-
add r4, sp, #8
58-
str r4, [sp]
59-
bl ___udivmoddi4
60-
ldr r2, [sp, #8]
61-
ldr r3, [sp, #12]
62-
add sp, sp, #16
63-
pop {r4, pc}" ::: "memory" : "volatile");
61+
llvm_asm!("
62+
push {r4, lr}
63+
sub sp, sp, #16
64+
add r4, sp, #8
65+
str r4, [sp]
66+
bl ___udivmoddi4
67+
ldr r2, [sp, #8]
68+
ldr r3, [sp, #12]
69+
add sp, sp, #16
70+
pop {r4, pc}
71+
" ::: "memory" : "volatile");
6472
intrinsics::unreachable();
6573
}
6674

6775
#[cfg(not(target_os = "ios"))]
6876
#[naked]
6977
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
7078
pub unsafe fn __aeabi_idivmod() {
71-
asm!("push {r0, r1, r4, lr}
72-
bl __aeabi_idiv
73-
pop {r1, r2}
74-
muls r2, r2, r0
75-
subs r1, r1, r2
76-
pop {r4, pc}" ::: "memory" : "volatile");
79+
llvm_asm!("
80+
push {r0, r1, r4, lr}
81+
bl __aeabi_idiv
82+
pop {r1, r2}
83+
muls r2, r2, r0
84+
subs r1, r1, r2
85+
pop {r4, pc}
86+
" ::: "memory" : "volatile");
7787
intrinsics::unreachable();
7888
}
7989

8090
#[cfg(target_os = "ios")]
8191
#[naked]
8292
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
8393
pub unsafe fn __aeabi_idivmod() {
84-
asm!("push {r0, r1, r4, lr}
85-
bl ___aeabi_idiv
86-
pop {r1, r2}
87-
muls r2, r2, r0
88-
subs r1, r1, r2
89-
pop {r4, pc}" ::: "memory" : "volatile");
94+
llvm_asm!("
95+
push {r0, r1, r4, lr}
96+
bl ___aeabi_idiv
97+
pop {r1, r2}
98+
muls r2, r2, r0
99+
subs r1, r1, r2
100+
pop {r4, pc}
101+
" ::: "memory" : "volatile");
90102
intrinsics::unreachable();
91103
}
92104

93105
#[cfg(not(target_os = "ios"))]
94106
#[naked]
95107
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
96108
pub unsafe fn __aeabi_ldivmod() {
97-
asm!("push {r4, lr}
98-
sub sp, sp, #16
99-
add r4, sp, #8
100-
str r4, [sp]
101-
bl __divmoddi4
102-
ldr r2, [sp, #8]
103-
ldr r3, [sp, #12]
104-
add sp, sp, #16
105-
pop {r4, pc}" ::: "memory" : "volatile");
109+
llvm_asm!("
110+
push {r4, lr}
111+
sub sp, sp, #16
112+
add r4, sp, #8
113+
str r4, [sp]
114+
bl __divmoddi4
115+
ldr r2, [sp, #8]
116+
ldr r3, [sp, #12]
117+
add sp, sp, #16
118+
pop {r4, pc}
119+
" ::: "memory" : "volatile");
106120
intrinsics::unreachable();
107121
}
108122

109123
#[cfg(target_os = "ios")]
110124
#[naked]
111125
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
112126
pub unsafe fn __aeabi_ldivmod() {
113-
asm!("push {r4, lr}
114-
sub sp, sp, #16
115-
add r4, sp, #8
116-
str r4, [sp]
117-
bl ___divmoddi4
118-
ldr r2, [sp, #8]
119-
ldr r3, [sp, #12]
120-
add sp, sp, #16
121-
pop {r4, pc}" ::: "memory" : "volatile");
127+
llvm_asm!("
128+
push {r4, lr}
129+
sub sp, sp, #16
130+
add r4, sp, #8
131+
str r4, [sp]
132+
bl ___divmoddi4
133+
ldr r2, [sp, #8]
134+
ldr r3, [sp, #12]
135+
add sp, sp, #16
136+
pop {r4, pc}
137+
" ::: "memory" : "volatile");
122138
intrinsics::unreachable();
123139
}
124140

src/int/mod.rs

+37-37
Original file line numberDiff line numberDiff line change
@@ -88,55 +88,55 @@ fn unwrap<T>(t: Option<T>) -> T {
8888

8989
macro_rules! int_impl_common {
9090
($ty:ty, $bits:expr) => {
91-
const BITS: u32 = $bits;
91+
const BITS: u32 = $bits;
9292

93-
const ZERO: Self = 0;
94-
const ONE: Self = 1;
93+
const ZERO: Self = 0;
94+
const ONE: Self = 1;
9595

96-
fn from_bool(b: bool) -> Self {
97-
b as $ty
98-
}
96+
fn from_bool(b: bool) -> Self {
97+
b as $ty
98+
}
9999

100-
fn max_value() -> Self {
101-
<Self>::max_value()
102-
}
100+
fn max_value() -> Self {
101+
<Self>::max_value()
102+
}
103103

104-
fn min_value() -> Self {
105-
<Self>::min_value()
106-
}
104+
fn min_value() -> Self {
105+
<Self>::min_value()
106+
}
107107

108-
fn wrapping_add(self, other: Self) -> Self {
109-
<Self>::wrapping_add(self, other)
110-
}
108+
fn wrapping_add(self, other: Self) -> Self {
109+
<Self>::wrapping_add(self, other)
110+
}
111111

112-
fn wrapping_mul(self, other: Self) -> Self {
113-
<Self>::wrapping_mul(self, other)
114-
}
112+
fn wrapping_mul(self, other: Self) -> Self {
113+
<Self>::wrapping_mul(self, other)
114+
}
115115

116-
fn wrapping_sub(self, other: Self) -> Self {
117-
<Self>::wrapping_sub(self, other)
118-
}
116+
fn wrapping_sub(self, other: Self) -> Self {
117+
<Self>::wrapping_sub(self, other)
118+
}
119119

120-
fn wrapping_shl(self, other: u32) -> Self {
121-
<Self>::wrapping_shl(self, other)
122-
}
120+
fn wrapping_shl(self, other: u32) -> Self {
121+
<Self>::wrapping_shl(self, other)
122+
}
123123

124-
fn overflowing_add(self, other: Self) -> (Self, bool) {
125-
<Self>::overflowing_add(self, other)
126-
}
124+
fn overflowing_add(self, other: Self) -> (Self, bool) {
125+
<Self>::overflowing_add(self, other)
126+
}
127127

128-
fn aborting_div(self, other: Self) -> Self {
129-
unwrap(<Self>::checked_div(self, other))
130-
}
128+
fn aborting_div(self, other: Self) -> Self {
129+
unwrap(<Self>::checked_div(self, other))
130+
}
131131

132-
fn aborting_rem(self, other: Self) -> Self {
133-
unwrap(<Self>::checked_rem(self, other))
134-
}
132+
fn aborting_rem(self, other: Self) -> Self {
133+
unwrap(<Self>::checked_rem(self, other))
134+
}
135135

136-
fn leading_zeros(self) -> u32 {
137-
<Self>::leading_zeros(self)
138-
}
139-
}
136+
fn leading_zeros(self) -> u32 {
137+
<Self>::leading_zeros(self)
138+
}
139+
};
140140
}
141141

142142
macro_rules! int_impl {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
22
#![feature(abi_unadjusted)]
3-
#![feature(asm)]
3+
#![feature(llvm_asm)]
44
#![feature(global_asm)]
55
#![feature(cfg_target_has_atomic)]
66
#![feature(compiler_builtins)]

src/x86.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::intrinsics;
1212
#[naked]
1313
#[no_mangle]
1414
pub unsafe fn ___chkstk_ms() {
15-
asm!("
15+
llvm_asm!("
1616
push %ecx
1717
push %eax
1818
cmp $$0x1000,%eax
@@ -38,7 +38,7 @@ pub unsafe fn ___chkstk_ms() {
3838
#[naked]
3939
#[no_mangle]
4040
pub unsafe fn __alloca() {
41-
asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
41+
llvm_asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
4242
::: "memory" : "volatile");
4343
intrinsics::unreachable();
4444
}
@@ -47,7 +47,7 @@ pub unsafe fn __alloca() {
4747
#[naked]
4848
#[no_mangle]
4949
pub unsafe fn ___chkstk() {
50-
asm!("
50+
llvm_asm!("
5151
push %ecx
5252
cmp $$0x1000,%eax
5353
lea 8(%esp),%ecx // esp before calling this routine -> ecx

src/x86_64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::intrinsics;
1212
#[naked]
1313
#[no_mangle]
1414
pub unsafe fn ___chkstk_ms() {
15-
asm!("
15+
llvm_asm!("
1616
push %rcx
1717
push %rax
1818
cmp $$0x1000,%rax
@@ -37,7 +37,7 @@ pub unsafe fn ___chkstk_ms() {
3737
#[naked]
3838
#[no_mangle]
3939
pub unsafe fn __alloca() {
40-
asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
40+
llvm_asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
4141
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
4242
::: "memory" : "volatile");
4343
intrinsics::unreachable();
@@ -47,7 +47,7 @@ pub unsafe fn __alloca() {
4747
#[naked]
4848
#[no_mangle]
4949
pub unsafe fn ___chkstk() {
50-
asm!(
50+
llvm_asm!(
5151
"
5252
push %rcx
5353
cmp $$0x1000,%rax

0 commit comments

Comments
 (0)