Skip to content

Commit 8a17296

Browse files
committed
Replace llvm_asm! with asm!
1 parent d40d61d commit 8a17296

File tree

5 files changed

+180
-184
lines changed

5 files changed

+180
-184
lines changed

examples/intrinsics.rs

Lines changed: 2 additions & 7 deletions
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(llvm_asm)]
9+
#![feature(test)]
1010
#![feature(lang_items)]
1111
#![feature(start)]
1212
#![feature(allocator_api)]
@@ -277,12 +277,7 @@ mod intrinsics {
277277

278278
fn run() {
279279
use intrinsics::*;
280-
281-
// A copy of "test::black_box". Used to prevent LLVM from optimizing away the intrinsics during LTO
282-
fn bb<T>(dummy: T) -> T {
283-
unsafe { llvm_asm!("" : : "r"(&dummy)) }
284-
dummy
285-
}
280+
use core::hint::black_box as bb;
286281

287282
bb(aeabi_d2f(bb(2.)));
288283
bb(aeabi_d2i(bb(2.)));

src/arm.rs

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,134 +10,135 @@ use core::intrinsics;
1010
#[naked]
1111
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
1212
pub unsafe fn __aeabi_uidivmod() {
13-
llvm_asm!("
14-
push {lr}
15-
sub sp, sp, #4
16-
mov r2, sp
17-
bl __udivmodsi4
18-
ldr r1, [sp]
19-
add sp, sp, #4
20-
pop {pc}
21-
" ::: "memory" : "volatile");
22-
intrinsics::unreachable();
13+
asm!(
14+
"push {{lr}}",
15+
"sub sp, sp, #4",
16+
"mov r2, sp",
17+
"bl __udivmodsi4",
18+
"ldr r1, [sp]",
19+
"add sp, sp, #4",
20+
"pop {{pc}}",
21+
options(noreturn)
22+
);
2323
}
2424

2525
#[cfg(target_os = "ios")]
2626
#[naked]
2727
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
2828
pub unsafe fn __aeabi_uidivmod() {
29-
llvm_asm!("
30-
push {lr}
31-
sub sp, sp, #4
32-
mov r2, sp
33-
bl ___udivmodsi4
34-
ldr r1, [sp]
35-
add sp, sp, #4
36-
pop {pc}
37-
" ::: "memory" : "volatile");
38-
intrinsics::unreachable();
29+
asm!(
30+
"push {{lr}}",
31+
"sub sp, sp, #4",
32+
"mov r2, sp",
33+
"bl ___udivmodsi4",
34+
"ldr r1, [sp]",
35+
"add sp, sp, #4",
36+
"pop {{pc}}",
37+
options(noreturn)
38+
);
3939
}
4040

4141
#[cfg(not(target_os = "ios"))]
4242
#[naked]
4343
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
4444
pub unsafe fn __aeabi_uldivmod() {
45-
llvm_asm!("
46-
push {r4, lr}
47-
sub sp, sp, #16
48-
add r4, sp, #8
49-
str r4, [sp]
50-
bl __udivmoddi4
51-
ldr r2, [sp, #8]
52-
ldr r3, [sp, #12]
53-
add sp, sp, #16
54-
pop {r4, pc}
55-
" ::: "memory" : "volatile");
45+
asm!(
46+
"push {{r4, lr}}",
47+
"sub sp, sp, #16",
48+
"add r4, sp, #8",
49+
"str r4, [sp]",
50+
"bl __udivmoddi4",
51+
"ldr r2, [sp, #8]",
52+
"ldr r3, [sp, #12]",
53+
"add sp, sp, #16",
54+
"pop {{r4, pc}}",
55+
options(noreturn)
56+
);
5657
intrinsics::unreachable();
5758
}
5859

5960
#[cfg(target_os = "ios")]
6061
#[naked]
6162
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
6263
pub unsafe fn __aeabi_uldivmod() {
63-
llvm_asm!("
64-
push {r4, lr}
65-
sub sp, sp, #16
66-
add r4, sp, #8
67-
str r4, [sp]
68-
bl ___udivmoddi4
69-
ldr r2, [sp, #8]
70-
ldr r3, [sp, #12]
71-
add sp, sp, #16
72-
pop {r4, pc}
73-
" ::: "memory" : "volatile");
74-
intrinsics::unreachable();
64+
asm!(
65+
"push {{r4, lr}}",
66+
"sub sp, sp, #16",
67+
"add r4, sp, #8",
68+
"str r4, [sp]",
69+
"bl ___udivmoddi4",
70+
"ldr r2, [sp, #8]",
71+
"ldr r3, [sp, #12]",
72+
"add sp, sp, #16",
73+
"pop {{r4, pc}}",
74+
options(noreturn)
75+
);
7576
}
7677

7778
#[cfg(not(target_os = "ios"))]
7879
#[naked]
7980
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
8081
pub unsafe fn __aeabi_idivmod() {
81-
llvm_asm!("
82-
push {r0, r1, r4, lr}
83-
bl __aeabi_idiv
84-
pop {r1, r2}
85-
muls r2, r2, r0
86-
subs r1, r1, r2
87-
pop {r4, pc}
88-
" ::: "memory" : "volatile");
89-
intrinsics::unreachable();
82+
asm!(
83+
"push {{r0, r1, r4, lr}}",
84+
"bl __aeabi_idiv",
85+
"pop {r1, r2}",
86+
"muls r2, r2, r0",
87+
"subs r1, r1, r2",
88+
"pop {{r4, pc}}",
89+
options(noreturn)
90+
);
9091
}
9192

9293
#[cfg(target_os = "ios")]
9394
#[naked]
9495
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
9596
pub unsafe fn __aeabi_idivmod() {
96-
llvm_asm!("
97-
push {r0, r1, r4, lr}
98-
bl ___aeabi_idiv
99-
pop {r1, r2}
100-
muls r2, r2, r0
101-
subs r1, r1, r2
102-
pop {r4, pc}
103-
" ::: "memory" : "volatile");
104-
intrinsics::unreachable();
97+
asm!(
98+
"push {{r0, r1, r4, lr}}",
99+
"bl ___aeabi_idiv",
100+
"pop {r1, r2}",
101+
"muls r2, r2, r0",
102+
"subs r1, r1, r2",
103+
"pop {{r4, pc}}",
104+
options(noreturn)
105+
);
105106
}
106107

107108
#[cfg(not(target_os = "ios"))]
108109
#[naked]
109110
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
110111
pub unsafe fn __aeabi_ldivmod() {
111-
llvm_asm!("
112-
push {r4, lr}
113-
sub sp, sp, #16
114-
add r4, sp, #8
115-
str r4, [sp]
116-
bl __divmoddi4
117-
ldr r2, [sp, #8]
118-
ldr r3, [sp, #12]
119-
add sp, sp, #16
120-
pop {r4, pc}
121-
" ::: "memory" : "volatile");
122-
intrinsics::unreachable();
112+
asm!(
113+
"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}}",
122+
options(noreturn)
123+
);
123124
}
124125

125126
#[cfg(target_os = "ios")]
126127
#[naked]
127128
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
128129
pub unsafe fn __aeabi_ldivmod() {
129-
llvm_asm!("
130-
push {r4, lr}
131-
sub sp, sp, #16
132-
add r4, sp, #8
133-
str r4, [sp]
134-
bl ___divmoddi4
135-
ldr r2, [sp, #8]
136-
ldr r3, [sp, #12]
137-
add sp, sp, #16
138-
pop {r4, pc}
139-
" ::: "memory" : "volatile");
140-
intrinsics::unreachable();
130+
asm!(
131+
"push {{r4, lr}}",
132+
"sub sp, sp, #16",
133+
"add r4, sp, #8",
134+
"str r4, [sp]",
135+
"bl ___divmoddi4",
136+
"ldr r2, [sp, #8]",
137+
"ldr r3, [sp, #12]",
138+
"add sp, sp, #16",
139+
"pop {{r4, pc}}",
140+
options(noreturn)
141+
);
141142
}
142143

143144
// The following functions use weak linkage to allow users to override

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
22
#![cfg_attr(not(feature = "no-asm"), feature(asm))]
33
#![feature(abi_unadjusted)]
4-
#![cfg_attr(not(feature = "no-asm"), feature(llvm_asm))]
54
#![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
65
#![feature(cfg_target_has_atomic)]
76
#![feature(compiler_builtins)]

src/x86.rs

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,26 @@ use core::intrinsics;
1717
#[naked]
1818
#[no_mangle]
1919
pub unsafe fn ___chkstk_ms() {
20-
llvm_asm!("
21-
push %ecx
22-
push %eax
23-
cmp $$0x1000,%eax
24-
lea 12(%esp),%ecx
25-
jb 1f
26-
2:
27-
sub $$0x1000,%ecx
28-
test %ecx,(%ecx)
29-
sub $$0x1000,%eax
30-
cmp $$0x1000,%eax
31-
ja 2b
32-
1:
33-
sub %eax,%ecx
34-
test %ecx,(%ecx)
35-
pop %eax
36-
pop %ecx
37-
ret" ::: "memory" : "volatile");
38-
intrinsics::unreachable();
20+
asm!(
21+
"push %ecx",
22+
"push %eax",
23+
"cmp $0x1000,%eax",
24+
"lea 12(%esp),%ecx",
25+
"jb 1f",
26+
"2:",
27+
"sub $0x1000,%ecx",
28+
"test %ecx,(%ecx)",
29+
"sub $0x1000,%eax",
30+
"cmp $0x1000,%eax",
31+
"ja 2b",
32+
"1:",
33+
"sub %eax,%ecx",
34+
"test %ecx,(%ecx)",
35+
"pop %eax",
36+
"pop %ecx",
37+
"ret",
38+
options(noreturn, att_syntax)
39+
);
3940
}
4041

4142
// FIXME: __alloca should be an alias to __chkstk
@@ -48,9 +49,10 @@ pub unsafe fn ___chkstk_ms() {
4849
#[naked]
4950
#[no_mangle]
5051
pub unsafe fn __alloca() {
51-
llvm_asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
52-
::: "memory" : "volatile");
53-
intrinsics::unreachable();
52+
asm!(
53+
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
54+
options(noreturn, att_syntax)
55+
);
5456
}
5557

5658
#[cfg(all(
@@ -62,26 +64,26 @@ pub unsafe fn __alloca() {
6264
#[naked]
6365
#[no_mangle]
6466
pub unsafe fn ___chkstk() {
65-
llvm_asm!("
66-
push %ecx
67-
cmp $$0x1000,%eax
68-
lea 8(%esp),%ecx // esp before calling this routine -> ecx
69-
jb 1f
70-
2:
71-
sub $$0x1000,%ecx
72-
test %ecx,(%ecx)
73-
sub $$0x1000,%eax
74-
cmp $$0x1000,%eax
75-
ja 2b
76-
1:
77-
sub %eax,%ecx
78-
test %ecx,(%ecx)
79-
80-
lea 4(%esp),%eax // load pointer to the return address into eax
81-
mov %ecx,%esp // install the new top of stack pointer into esp
82-
mov -4(%eax),%ecx // restore ecx
83-
push (%eax) // push return address onto the stack
84-
sub %esp,%eax // restore the original value in eax
85-
ret" ::: "memory" : "volatile");
86-
intrinsics::unreachable();
67+
asm!(
68+
"push %ecx",
69+
"cmp $$0x1000,%eax",
70+
"lea 8(%esp),%ecx", // esp before calling this routine -> ecx
71+
"jb 1f",
72+
"2:",
73+
"sub $$0x1000,%ecx",
74+
"test %ecx,(%ecx)",
75+
"sub $$0x1000,%eax",
76+
"cmp $$0x1000,%eax",
77+
"ja 2b",
78+
"1:",
79+
"sub %eax,%ecx",
80+
"test %ecx,(%ecx)",
81+
"lea 4(%esp),%eax", // load pointer to the return address into eax
82+
"mov %ecx,%esp", // install the new top of stack pointer into esp
83+
"mov -4(%eax),%ecx", // restore ecx
84+
"push (%eax)", // push return address onto the stack
85+
"sub %esp,%eax", // restore the original value in eax
86+
"ret",
87+
options(noreturn, att_syntax)
88+
);
8789
}

0 commit comments

Comments
 (0)