1
1
use core:: intrinsics;
2
2
3
3
// NOTE This function and the ones below are implemented using assembly because they using a custom
4
- // calling convention which can't be implemented using a normal Rust function
4
+ // calling convention which can't be implemented using a normal Rust function.
5
+ // NOTE The only difference between the iOS and non-iOS versions of those functions is that the iOS
6
+ // versions use 3 leading underscores in the names of called functions instead of 2.
7
+ #[ cfg( not( target_os = "ios" ) ) ]
5
8
#[ naked]
6
9
#[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
7
10
pub unsafe fn __aeabi_uidivmod ( ) {
@@ -15,6 +18,21 @@ pub unsafe fn __aeabi_uidivmod() {
15
18
intrinsics:: unreachable ( ) ;
16
19
}
17
20
21
+ #[ cfg( target_os = "ios" ) ]
22
+ #[ naked]
23
+ #[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
24
+ pub unsafe fn __aeabi_uidivmod ( ) {
25
+ asm ! ( "push {lr}
26
+ sub sp, sp, #4
27
+ mov r2, sp
28
+ bl ___udivmodsi4
29
+ ldr r1, [sp]
30
+ add sp, sp, #4
31
+ pop {pc}" :: : "memory" : "volatile" ) ;
32
+ intrinsics:: unreachable ( ) ;
33
+ }
34
+
35
+ #[ cfg( not( target_os = "ios" ) ) ]
18
36
#[ naked]
19
37
#[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
20
38
pub unsafe fn __aeabi_uldivmod ( ) {
@@ -30,6 +48,23 @@ pub unsafe fn __aeabi_uldivmod() {
30
48
intrinsics:: unreachable ( ) ;
31
49
}
32
50
51
+ #[ cfg( target_os = "ios" ) ]
52
+ #[ naked]
53
+ #[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
54
+ pub unsafe fn __aeabi_uldivmod ( ) {
55
+ asm ! ( "push {r4, lr}
56
+ sub sp, sp, #16
57
+ add r4, sp, #8
58
+ str r4, [sp]
59
+ bl ___udivmoddi4
60
+ ldr r2, [sp, #8]
61
+ ldr r3, [sp, #12]
62
+ add sp, sp, #16
63
+ pop {r4, pc}" :: : "memory" : "volatile" ) ;
64
+ intrinsics:: unreachable ( ) ;
65
+ }
66
+
67
+ #[ cfg( not( target_os = "ios" ) ) ]
33
68
#[ naked]
34
69
#[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
35
70
pub unsafe fn __aeabi_idivmod ( ) {
@@ -42,6 +77,20 @@ pub unsafe fn __aeabi_idivmod() {
42
77
intrinsics:: unreachable ( ) ;
43
78
}
44
79
80
+ #[ cfg( target_os = "ios" ) ]
81
+ #[ naked]
82
+ #[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
83
+ pub unsafe fn __aeabi_idivmod ( ) {
84
+ asm ! ( "push {r0, r1, r4, lr}
85
+ bl ___aeabi_idiv
86
+ pop {r1, r2}
87
+ muls r2, r2, r0
88
+ subs r1, r1, r2
89
+ pop {r4, pc}" :: : "memory" : "volatile" ) ;
90
+ intrinsics:: unreachable ( ) ;
91
+ }
92
+
93
+ #[ cfg( not( target_os = "ios" ) ) ]
45
94
#[ naked]
46
95
#[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
47
96
pub unsafe fn __aeabi_ldivmod ( ) {
@@ -57,6 +106,22 @@ pub unsafe fn __aeabi_ldivmod() {
57
106
intrinsics:: unreachable ( ) ;
58
107
}
59
108
109
+ #[ cfg( target_os = "ios" ) ]
110
+ #[ naked]
111
+ #[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
112
+ pub unsafe fn __aeabi_ldivmod ( ) {
113
+ asm ! ( "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}" :: : "memory" : "volatile" ) ;
122
+ intrinsics:: unreachable ( ) ;
123
+ }
124
+
60
125
// FIXME: The `*4` and `*8` variants should be defined as aliases.
61
126
62
127
#[ cfg( not( target_os = "ios" ) ) ]
0 commit comments