aeabi_thumb1.S (7868B)
1 // Consolidated AEABI helpers for kit's libkit_rt.a (ARM Thumb1 mode). 2 // The build assembles only this one file for the Thumb1 ISA mode; the per-op 3 // files are #included as snippets and not directly built. 4 // License: Apache-2.0 WITH LLVM-exception (see lib/LICENSE-compiler-rt.txt). 5 6 // ISA-agnostic helpers 7 // ---- aeabi_ldivmod.S ---- 8 #include "assembly.h" 9 10 // struct { int64_t quot, int64_t rem} 11 // __aeabi_ldivmod(int64_t numerator, int64_t denominator) { 12 // int64_t rem, quot; 13 // quot = __divmoddi4(numerator, denominator, &rem); 14 // return {quot, rem}; 15 // } 16 17 18 .syntax unified 19 .p2align 2 20 DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod) 21 push {r6, lr} 22 sub sp, sp, #16 23 add r6, sp, #8 24 str r6, [sp] 25 bl SYMBOL_NAME(__divmoddi4) 26 ldr r2, [sp, #8] 27 ldr r3, [sp, #12] 28 add sp, sp, #16 29 pop {r6, pc} 30 END_COMPILERRT_FUNCTION(__aeabi_ldivmod) 31 32 NO_EXEC_STACK_DIRECTIVE 33 34 // ---- aeabi_uldivmod.S ---- 35 #include "assembly.h" 36 37 // struct { uint64_t quot, uint64_t rem} 38 // __aeabi_uldivmod(uint64_t numerator, uint64_t denominator) { 39 // uint64_t rem, quot; 40 // quot = __udivmoddi4(numerator, denominator, &rem); 41 // return {quot, rem}; 42 // } 43 44 45 .syntax unified 46 .p2align 2 47 DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod) 48 push {r6, lr} 49 sub sp, sp, #16 50 add r6, sp, #8 51 str r6, [sp] 52 bl SYMBOL_NAME(__udivmoddi4) 53 ldr r2, [sp, #8] 54 ldr r3, [sp, #12] 55 add sp, sp, #16 56 pop {r6, pc} 57 END_COMPILERRT_FUNCTION(__aeabi_uldivmod) 58 59 NO_EXEC_STACK_DIRECTIVE 60 61 // ---- aeabi_dcmp.S ---- 62 #include "assembly.h" 63 64 // int __aeabi_dcmp{eq,lt,le,ge,gt}(double a, double b) { 65 // int result = __{eq,lt,le,ge,gt}df2(a, b); 66 // if (result {==,<,<=,>=,>} 0) { 67 // return 1; 68 // } else { 69 // return 0; 70 // } 71 // } 72 73 # define CONVERT_DCMP_ARGS_TO_DF2_ARGS 74 75 #define DEFINE_AEABI_DCMP(cond) \ 76 .syntax unified SEPARATOR \ 77 .p2align 2 SEPARATOR \ 78 DEFINE_COMPILERRT_FUNCTION(__aeabi_dcmp ## cond) \ 79 push { r4, lr } SEPARATOR \ 80 CONVERT_DCMP_ARGS_TO_DF2_ARGS SEPARATOR \ 81 bl SYMBOL_NAME(__ ## cond ## df2) SEPARATOR \ 82 cmp r0, #0 SEPARATOR \ 83 b ## cond 1f SEPARATOR \ 84 movs r0, #0 SEPARATOR \ 85 pop { r4, pc } SEPARATOR \ 86 1: SEPARATOR \ 87 movs r0, #1 SEPARATOR \ 88 pop { r4, pc } SEPARATOR \ 89 END_COMPILERRT_FUNCTION(__aeabi_dcmp ## cond) 90 91 DEFINE_AEABI_DCMP(eq) 92 DEFINE_AEABI_DCMP(lt) 93 DEFINE_AEABI_DCMP(le) 94 DEFINE_AEABI_DCMP(ge) 95 DEFINE_AEABI_DCMP(gt) 96 97 NO_EXEC_STACK_DIRECTIVE 98 99 // ---- aeabi_fcmp.S ---- 100 #include "assembly.h" 101 102 // int __aeabi_fcmp{eq,lt,le,ge,gt}(float a, float b) { 103 // int result = __{eq,lt,le,ge,gt}sf2(a, b); 104 // if (result {==,<,<=,>=,>} 0) { 105 // return 1; 106 // } else { 107 // return 0; 108 // } 109 // } 110 111 # define CONVERT_FCMP_ARGS_TO_SF2_ARGS 112 113 #define DEFINE_AEABI_FCMP(cond) \ 114 .syntax unified SEPARATOR \ 115 .p2align 2 SEPARATOR \ 116 DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond) \ 117 push { r4, lr } SEPARATOR \ 118 CONVERT_FCMP_ARGS_TO_SF2_ARGS SEPARATOR \ 119 bl SYMBOL_NAME(__ ## cond ## sf2) SEPARATOR \ 120 cmp r0, #0 SEPARATOR \ 121 b ## cond 1f SEPARATOR \ 122 movs r0, #0 SEPARATOR \ 123 pop { r4, pc } SEPARATOR \ 124 1: SEPARATOR \ 125 movs r0, #1 SEPARATOR \ 126 pop { r4, pc } SEPARATOR \ 127 END_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond) 128 129 DEFINE_AEABI_FCMP(eq) 130 DEFINE_AEABI_FCMP(lt) 131 DEFINE_AEABI_FCMP(le) 132 DEFINE_AEABI_FCMP(ge) 133 DEFINE_AEABI_FCMP(gt) 134 135 NO_EXEC_STACK_DIRECTIVE 136 137 138 // Thumb1-specific helpers 139 // ---- aeabi_idivmod_thumb1.S ---- 140 #include "assembly.h" 141 142 .syntax unified 143 .text 144 DEFINE_CODE_STATE 145 .p2align 2 146 DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod) 147 push {r0, r1, lr} 148 bl SYMBOL_NAME(__divsi3) 149 pop {r1, r2, r3} // now r0 = quot, r1 = num, r2 = denom 150 muls r2, r0, r2 // r2 = quot * denom 151 subs r1, r1, r2 152 JMP (r3) 153 END_COMPILERRT_FUNCTION(__aeabi_idivmod) 154 155 NO_EXEC_STACK_DIRECTIVE 156 // ---- aeabi_uidivmod_thumb1.S ---- 157 #include "assembly.h" 158 159 .syntax unified 160 .text 161 DEFINE_CODE_STATE 162 .p2align 2 163 DEFINE_COMPILERRT_FUNCTION(__aeabi_uidivmod) 164 cmp r0, r1 165 bcc LOCAL_LABEL(case_denom_larger) 166 push {r0, r1, lr} 167 bl SYMBOL_NAME(__aeabi_uidiv) 168 pop {r1, r2, r3} 169 muls r2, r0, r2 // r2 = quot * denom 170 subs r1, r1, r2 171 JMP (r3) 172 LOCAL_LABEL(case_denom_larger): 173 movs r1, r0 174 movs r0, #0 175 JMP (lr) 176 END_COMPILERRT_FUNCTION(__aeabi_uidivmod) 177 178 NO_EXEC_STACK_DIRECTIVE 179 // ---- aeabi_memcpy_thumb1.S ---- 180 #include "assembly.h" 181 182 // void __aeabi_memcpy(void *dest, void *src, size_t n) { memcpy(dest, src, n); } 183 184 .syntax unified 185 .p2align 2 186 DEFINE_COMPILERRT_FUNCTION(__aeabi_memcpy) 187 push {r7, lr} 188 bl memcpy 189 pop {r7, pc} 190 END_COMPILERRT_FUNCTION(__aeabi_memcpy) 191 192 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy4, __aeabi_memcpy) 193 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy8, __aeabi_memcpy) 194 195 NO_EXEC_STACK_DIRECTIVE 196 // ---- aeabi_memmove_thumb1.S ---- 197 #include "assembly.h" 198 199 // void __aeabi_memmove(void *dest, void *src, size_t n) { memmove(dest, src, n); } 200 201 .p2align 2 202 DEFINE_COMPILERRT_FUNCTION(__aeabi_memmove) 203 push {r7, lr} 204 bl memmove 205 pop {r7, pc} 206 END_COMPILERRT_FUNCTION(__aeabi_memmove) 207 208 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove4, __aeabi_memmove) 209 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove8, __aeabi_memmove) 210 211 NO_EXEC_STACK_DIRECTIVE 212 // ---- aeabi_memset_thumb1.S ---- 213 #include "assembly.h" 214 215 // void __aeabi_memset(void *dest, size_t n, int c) { memset(dest, c, n); } 216 // void __aeabi_memclr(void *dest, size_t n) { __aeabi_memset(dest, n, 0); } 217 218 .syntax unified 219 .p2align 2 220 DEFINE_COMPILERRT_FUNCTION(__aeabi_memset) 221 mov r3, r1 222 mov r1, r2 223 mov r2, r3 224 push {r7, lr} 225 bl memset 226 pop {r7, pc} 227 END_COMPILERRT_FUNCTION(__aeabi_memset) 228 229 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memset4, __aeabi_memset) 230 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memset8, __aeabi_memset) 231 232 .p2align 2 233 DEFINE_COMPILERRT_FUNCTION(__aeabi_memclr) 234 mov r2, r1 235 movs r1, #0 236 push {r7, lr} 237 bl memset 238 pop {r7, pc} 239 END_COMPILERRT_FUNCTION(__aeabi_memclr) 240 241 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memclr4, __aeabi_memclr) 242 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memclr8, __aeabi_memclr) 243 244 NO_EXEC_STACK_DIRECTIVE 245 // ---- aeabi_memcmp_thumb1.S ---- 246 #include "assembly.h" 247 248 // void __aeabi_memcmp(void *dest, void *src, size_t n) { memcmp(dest, src, n); } 249 250 .syntax unified 251 .p2align 2 252 DEFINE_COMPILERRT_FUNCTION(__aeabi_memcmp) 253 push {r7, lr} 254 bl memcmp 255 pop {r7, pc} 256 END_COMPILERRT_FUNCTION(__aeabi_memcmp) 257 258 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp4, __aeabi_memcmp) 259 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp8, __aeabi_memcmp) 260 261 NO_EXEC_STACK_DIRECTIVE