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.
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 ;
128}
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 ;
1814}
1915
2016intrinsics ! {
@@ -27,10 +23,11 @@ intrinsics! {
2723 "push {{lr}}" ,
2824 "sub sp, sp, #4" ,
2925 "mov r2, sp" ,
30- bl! ( "__udivmodsi4" ) ,
26+ "bl {trampoline}" ,
3127 "ldr r1, [sp]" ,
3228 "add sp, sp, #4" ,
3329 "pop {{pc}}" ,
30+ trampoline = sym crate :: arm:: __udivmodsi4
3431 ) ;
3532 }
3633
@@ -41,23 +38,25 @@ intrinsics! {
4138 "sub sp, sp, #16" ,
4239 "add r4, sp, #8" ,
4340 "str r4, [sp]" ,
44- bl! ( "__udivmoddi4" ) ,
41+ "bl {trampoline}" ,
4542 "ldr r2, [sp, #8]" ,
4643 "ldr r3, [sp, #12]" ,
4744 "add sp, sp, #16" ,
4845 "pop {{r4, pc}}" ,
46+ trampoline = sym crate :: arm:: __udivmoddi4
4947 ) ;
5048 }
5149
5250 #[ unsafe ( naked) ]
5351 pub unsafe extern "C" fn __aeabi_idivmod( ) {
5452 core:: arch:: naked_asm!(
5553 "push {{r0, r1, r4, lr}}" ,
56- bl! ( "__aeabi_idiv" ) ,
54+ "bl {trampoline}" ,
5755 "pop {{r1, r2}}" ,
5856 "muls r2, r2, r0" ,
5957 "subs r1, r1, r2" ,
6058 "pop {{r4, pc}}" ,
59+ trampoline = sym crate :: arm:: __aeabi_idiv,
6160 ) ;
6261 }
6362
@@ -68,11 +67,12 @@ intrinsics! {
6867 "sub sp, sp, #16" ,
6968 "add r4, sp, #8" ,
7069 "str r4, [sp]" ,
71- bl! ( "__divmoddi4" ) ,
70+ "bl {trampoline}" ,
7271 "ldr r2, [sp, #8]" ,
7372 "ldr r3, [sp, #12]" ,
7473 "add sp, sp, #16" ,
7574 "pop {{r4, pc}}" ,
75+ trampoline = sym crate :: arm:: __divmoddi4,
7676 ) ;
7777 }
7878
0 commit comments