1
1
#![ cfg( not( feature = "no-asm" ) ) ]
2
- #![ allow( unused_imports) ]
3
2
4
- use core:: intrinsics;
5
-
6
- // Apple symbols have a leading underscore.
7
- #[ cfg( target_vendor = "apple" ) ]
8
- macro_rules! bl {
9
- ( $func: literal) => {
10
- concat!( "bl _" , $func)
11
- } ;
3
+ // Interfaces used by naked trampolines. The signatures are not correct, but this does not matter
4
+ // since we implement the calling convention by hand.
5
+ extern "C" {
6
+ fn __udivmodsi4 ( a : u32 , b : u32 , rem : * mut u32 ) -> u32 ;
7
+ fn __udivmoddi4 ( a : u64 , b : u64 , rem : * mut u64 ) -> u64 ;
8
+ fn __divmoddi4 ( a : i64 , b : i64 , rem : * mut i64 ) -> i64 ;
12
9
}
13
- #[ cfg( not( target_vendor = "apple" ) ) ]
14
- macro_rules! bl {
15
- ( $func: literal) => {
16
- concat!( "bl " , $func)
17
- } ;
10
+
11
+ extern "aapcs" {
12
+ fn __aeabi_idiv ( a : i32 , b : i32 ) -> i32 ;
18
13
}
19
14
20
15
intrinsics ! {
@@ -27,10 +22,11 @@ intrinsics! {
27
22
"push {{lr}}" ,
28
23
"sub sp, sp, #4" ,
29
24
"mov r2, sp" ,
30
- bl! ( "__udivmodsi4" ) ,
25
+ "bl {trampoline}" ,
31
26
"ldr r1, [sp]" ,
32
27
"add sp, sp, #4" ,
33
28
"pop {{pc}}" ,
29
+ trampoline = sym crate :: arm:: __udivmodsi4
34
30
) ;
35
31
}
36
32
@@ -41,23 +37,25 @@ intrinsics! {
41
37
"sub sp, sp, #16" ,
42
38
"add r4, sp, #8" ,
43
39
"str r4, [sp]" ,
44
- bl! ( "__udivmoddi4" ) ,
40
+ "bl {trampoline}" ,
45
41
"ldr r2, [sp, #8]" ,
46
42
"ldr r3, [sp, #12]" ,
47
43
"add sp, sp, #16" ,
48
44
"pop {{r4, pc}}" ,
45
+ trampoline = sym crate :: arm:: __udivmoddi4
49
46
) ;
50
47
}
51
48
52
49
#[ unsafe ( naked) ]
53
50
pub unsafe extern "C" fn __aeabi_idivmod( ) {
54
51
core:: arch:: naked_asm!(
55
52
"push {{r0, r1, r4, lr}}" ,
56
- bl! ( "__aeabi_idiv" ) ,
53
+ "bl {trampoline}" ,
57
54
"pop {{r1, r2}}" ,
58
55
"muls r2, r2, r0" ,
59
56
"subs r1, r1, r2" ,
60
57
"pop {{r4, pc}}" ,
58
+ trampoline = sym crate :: arm:: __aeabi_idiv,
61
59
) ;
62
60
}
63
61
@@ -68,11 +66,12 @@ intrinsics! {
68
66
"sub sp, sp, #16" ,
69
67
"add r4, sp, #8" ,
70
68
"str r4, [sp]" ,
71
- bl! ( "__divmoddi4" ) ,
69
+ "bl {trampoline}" ,
72
70
"ldr r2, [sp, #8]" ,
73
71
"ldr r3, [sp, #12]" ,
74
72
"add sp, sp, #16" ,
75
73
"pop {{r4, pc}}" ,
74
+ trampoline = sym crate :: arm:: __divmoddi4,
76
75
) ;
77
76
}
78
77
0 commit comments