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.
4
+ extern "C" {
5
+ fn __udivmodsi4 ( a : u32 , b : u32 , rem : * mut u32 ) -> u32 ;
6
+ fn __udivmoddi4 ( a : u64 , b : u64 , rem : * mut u64 ) -> u64 ;
7
+ fn __divmoddi4 ( a : i64 , b : i64 , rem : * mut i64 ) -> i64 ;
12
8
}
13
- # [ cfg ( not ( target_vendor = "apple" ) ) ]
14
- macro_rules! bl {
15
- ( $func : literal ) => {
16
- concat! ( "bl " , $func )
17
- } ;
9
+
10
+ extern "aapcs" {
11
+ // AAPCS is not always the correct ABI for these intrinsics, but we only use this to
12
+ // forward another `__aeabi_` call so it doesn't matter.
13
+ fn __aeabi_idiv ( a : i32 , b : i32 ) -> i32 ;
18
14
}
19
15
20
16
intrinsics ! {
@@ -27,10 +23,11 @@ intrinsics! {
27
23
"push {{lr}}" ,
28
24
"sub sp, sp, #4" ,
29
25
"mov r2, sp" ,
30
- bl! ( "__udivmodsi4" ) ,
26
+ "bl {trampoline}" ,
31
27
"ldr r1, [sp]" ,
32
28
"add sp, sp, #4" ,
33
29
"pop {{pc}}" ,
30
+ trampoline = sym crate :: arm:: __udivmodsi4
34
31
) ;
35
32
}
36
33
@@ -41,23 +38,25 @@ intrinsics! {
41
38
"sub sp, sp, #16" ,
42
39
"add r4, sp, #8" ,
43
40
"str r4, [sp]" ,
44
- bl! ( "__udivmoddi4" ) ,
41
+ "bl {trampoline}" ,
45
42
"ldr r2, [sp, #8]" ,
46
43
"ldr r3, [sp, #12]" ,
47
44
"add sp, sp, #16" ,
48
45
"pop {{r4, pc}}" ,
46
+ trampoline = sym crate :: arm:: __udivmoddi4
49
47
) ;
50
48
}
51
49
52
50
#[ unsafe ( naked) ]
53
51
pub unsafe extern "C" fn __aeabi_idivmod( ) {
54
52
core:: arch:: naked_asm!(
55
53
"push {{r0, r1, r4, lr}}" ,
56
- bl! ( "__aeabi_idiv" ) ,
54
+ "bl {trampoline}" ,
57
55
"pop {{r1, r2}}" ,
58
56
"muls r2, r2, r0" ,
59
57
"subs r1, r1, r2" ,
60
58
"pop {{r4, pc}}" ,
59
+ trampoline = sym crate :: arm:: __aeabi_idiv,
61
60
) ;
62
61
}
63
62
@@ -68,11 +67,12 @@ intrinsics! {
68
67
"sub sp, sp, #16" ,
69
68
"add r4, sp, #8" ,
70
69
"str r4, [sp]" ,
71
- bl! ( "__divmoddi4" ) ,
70
+ "bl {trampoline}" ,
72
71
"ldr r2, [sp, #8]" ,
73
72
"ldr r3, [sp, #12]" ,
74
73
"add sp, sp, #16" ,
75
74
"pop {{r4, pc}}" ,
75
+ trampoline = sym crate :: arm:: __divmoddi4,
76
76
) ;
77
77
}
78
78
0 commit comments