aeabi_thumb2.S (7775B)
1 // Consolidated AEABI helpers for kit's libkit_rt.a (ARM Thumb2 mode). 2 // The build assembles only this one file for the Thumb2 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 // Thumb2-specific helpers 139 // ---- aeabi_idivmod.S ---- 140 #include "assembly.h" 141 142 // struct { int quot, int rem} __aeabi_idivmod(int numerator, int denominator) { 143 // int rem, quot; 144 // quot = __divmodsi4(numerator, denominator, &rem); 145 // return {quot, rem}; 146 // } 147 148 149 .syntax unified 150 .text 151 DEFINE_CODE_STATE 152 .p2align 2 153 DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod) 154 push { lr } 155 sub sp, sp, #4 156 mov r2, sp 157 bl SYMBOL_NAME(__divmodsi4) 158 ldr r1, [sp] 159 add sp, sp, #4 160 pop { pc } 161 END_COMPILERRT_FUNCTION(__aeabi_idivmod) 162 163 NO_EXEC_STACK_DIRECTIVE 164 165 // ---- aeabi_uidivmod.S ---- 166 #include "assembly.h" 167 168 // struct { unsigned quot, unsigned rem} 169 // __aeabi_uidivmod(unsigned numerator, unsigned denominator) { 170 // unsigned rem, quot; 171 // quot = __udivmodsi4(numerator, denominator, &rem); 172 // return {quot, rem}; 173 // } 174 175 176 .syntax unified 177 .text 178 DEFINE_CODE_STATE 179 .p2align 2 180 DEFINE_COMPILERRT_FUNCTION(__aeabi_uidivmod) 181 push { lr } 182 sub sp, sp, #4 183 mov r2, sp 184 bl SYMBOL_NAME(__udivmodsi4) 185 ldr r1, [sp] 186 add sp, sp, #4 187 pop { pc } 188 END_COMPILERRT_FUNCTION(__aeabi_uidivmod) 189 190 NO_EXEC_STACK_DIRECTIVE 191 192 // ---- aeabi_memcpy.S ---- 193 #include "assembly.h" 194 195 // void __aeabi_memcpy(void *dest, void *src, size_t n) { memcpy(dest, src, n); } 196 197 .syntax unified 198 .p2align 2 199 DEFINE_COMPILERRT_FUNCTION(__aeabi_memcpy) 200 b memcpy 201 END_COMPILERRT_FUNCTION(__aeabi_memcpy) 202 203 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy4, __aeabi_memcpy) 204 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy8, __aeabi_memcpy) 205 206 NO_EXEC_STACK_DIRECTIVE 207 208 // ---- aeabi_memmove.S ---- 209 #include "assembly.h" 210 211 // void __aeabi_memmove(void *dest, void *src, size_t n) { memmove(dest, src, n); } 212 213 .p2align 2 214 DEFINE_COMPILERRT_FUNCTION(__aeabi_memmove) 215 b memmove 216 END_COMPILERRT_FUNCTION(__aeabi_memmove) 217 218 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove4, __aeabi_memmove) 219 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove8, __aeabi_memmove) 220 221 NO_EXEC_STACK_DIRECTIVE 222 223 // ---- aeabi_memset.S ---- 224 #include "assembly.h" 225 226 // void __aeabi_memset(void *dest, size_t n, int c) { memset(dest, c, n); } 227 // void __aeabi_memclr(void *dest, size_t n) { __aeabi_memset(dest, n, 0); } 228 229 .syntax unified 230 .p2align 2 231 DEFINE_COMPILERRT_FUNCTION(__aeabi_memset) 232 mov r3, r1 233 mov r1, r2 234 mov r2, r3 235 b memset 236 END_COMPILERRT_FUNCTION(__aeabi_memset) 237 238 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memset4, __aeabi_memset) 239 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memset8, __aeabi_memset) 240 241 .p2align 2 242 DEFINE_COMPILERRT_FUNCTION(__aeabi_memclr) 243 mov r2, r1 244 movs r1, #0 245 b memset 246 END_COMPILERRT_FUNCTION(__aeabi_memclr) 247 248 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memclr4, __aeabi_memclr) 249 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memclr8, __aeabi_memclr) 250 251 NO_EXEC_STACK_DIRECTIVE 252 253 // ---- aeabi_memcmp.S ---- 254 #include "assembly.h" 255 256 // void __aeabi_memcmp(void *dest, void *src, size_t n) { memcmp(dest, src, n); } 257 258 .syntax unified 259 .p2align 2 260 DEFINE_COMPILERRT_FUNCTION(__aeabi_memcmp) 261 b memcmp 262 END_COMPILERRT_FUNCTION(__aeabi_memcmp) 263 264 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp4, __aeabi_memcmp) 265 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp8, __aeabi_memcmp) 266 267 NO_EXEC_STACK_DIRECTIVE 268