11#![ cfg( not( feature = "no-asm" ) ) ]
2- #![ allow( unused_imports) ]
32
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 ;
129}
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 ;
1813}
1914
2015intrinsics ! {
@@ -27,10 +22,11 @@ intrinsics! {
2722 "push {{lr}}" ,
2823 "sub sp, sp, #4" ,
2924 "mov r2, sp" ,
30- bl! ( "__udivmodsi4" ) ,
25+ "bl {trampoline}" ,
3126 "ldr r1, [sp]" ,
3227 "add sp, sp, #4" ,
3328 "pop {{pc}}" ,
29+ trampoline = sym crate :: arm:: __udivmodsi4
3430 ) ;
3531 }
3632
@@ -41,23 +37,25 @@ intrinsics! {
4137 "sub sp, sp, #16" ,
4238 "add r4, sp, #8" ,
4339 "str r4, [sp]" ,
44- bl! ( "__udivmoddi4" ) ,
40+ "bl {trampoline}" ,
4541 "ldr r2, [sp, #8]" ,
4642 "ldr r3, [sp, #12]" ,
4743 "add sp, sp, #16" ,
4844 "pop {{r4, pc}}" ,
45+ trampoline = sym crate :: arm:: __udivmoddi4
4946 ) ;
5047 }
5148
5249 #[ unsafe ( naked) ]
5350 pub unsafe extern "C" fn __aeabi_idivmod( ) {
5451 core:: arch:: naked_asm!(
5552 "push {{r0, r1, r4, lr}}" ,
56- bl! ( "__aeabi_idiv" ) ,
53+ "bl {trampoline}" ,
5754 "pop {{r1, r2}}" ,
5855 "muls r2, r2, r0" ,
5956 "subs r1, r1, r2" ,
6057 "pop {{r4, pc}}" ,
58+ trampoline = sym crate :: arm:: __aeabi_idiv,
6159 ) ;
6260 }
6361
@@ -68,11 +66,12 @@ intrinsics! {
6866 "sub sp, sp, #16" ,
6967 "add r4, sp, #8" ,
7068 "str r4, [sp]" ,
71- bl! ( "__divmoddi4" ) ,
69+ "bl {trampoline}" ,
7270 "ldr r2, [sp, #8]" ,
7371 "ldr r3, [sp, #12]" ,
7472 "add sp, sp, #16" ,
7573 "pop {{r4, pc}}" ,
74+ trampoline = sym crate :: arm:: __divmoddi4,
7675 ) ;
7776 }
7877
0 commit comments