1 @ libgcc routines for ARM cpu.
2 @ Division routines, written by Richard Earnshaw, (rearnsha@armltd.co.uk)
4 /* Copyright (C) 1995-2015 Free Software Foundation, Inc.
6 This file is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This file is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* An executable stack is *not* required for these functions. */
26 #if defined(__ELF__) && defined(__linux__)
27 .section .note.GNU-stack,"",%progbits
29 #endif /* __ELF__ and __linux__ */
32 /* Some attributes that are common to all routines in this file. */
33 /* Tag_ABI_align_needed: This code does not require 8-byte
34 alignment from the caller. */
35 /* .eabi_attribute 24, 0 -- default setting. */
36 /* Tag_ABI_align_preserved: This code preserves 8-byte
37 alignment in any callee. */
39 #endif /* __ARM_EABI__ */
40 /* ------------------------------------------------------------------------ */
42 /* We need to know what prefix to add to function names. */
44 #ifndef __USER_LABEL_PREFIX__
45 #error __USER_LABEL_PREFIX__ not defined
48 /* ANSI concatenation macros. */
50 #define CONCAT1(a, b) CONCAT2(a, b)
51 #define CONCAT2(a, b) a ## b
53 /* Use the right prefix for global labels. */
55 #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
59 #define __PLT__ /* Not supported in Thumb assembler (for now). */
60 #elif defined __vxworks && !defined __PIC__
61 #define __PLT__ /* Not supported by the kernel loader. */
65 #define TYPE(x) .type SYM(x),function
66 #define SIZE(x) .size SYM(x), . - SYM(x)
75 /* Function end macros. Variants for interworking. */
77 #if defined(__ARM_ARCH_2__)
78 # define __ARM_ARCH__ 2
81 #if defined(__ARM_ARCH_3__)
82 # define __ARM_ARCH__ 3
85 #if defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) \
86 || defined(__ARM_ARCH_4T__)
87 /* We use __ARM_ARCH__ set to 4 here, but in reality it's any processor with
88 long multiply instructions. That includes v3M. */
89 # define __ARM_ARCH__ 4
92 #if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
93 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
94 || defined(__ARM_ARCH_5TEJ__)
95 # define __ARM_ARCH__ 5
98 #if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
99 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
100 || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
101 || defined(__ARM_ARCH_6M__)
102 # define __ARM_ARCH__ 6
105 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
106 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
107 || defined(__ARM_ARCH_7EM__)
108 # define __ARM_ARCH__ 7
111 #if defined(__ARM_ARCH_8A__)
112 # define __ARM_ARCH__ 8
116 #error Unable to determine architecture.
119 /* There are times when we might prefer Thumb1 code even if ARM code is
120 permitted, for example, the code might be smaller, or there might be
121 interworking problems with switching to ARM state if interworking is
123 #if (defined(__thumb__) \
124 && !defined(__thumb2__) \
125 && (!defined(__THUMB_INTERWORK__) \
126 || defined (__OPTIMIZE_SIZE__) \
127 || defined(__ARM_ARCH_6M__)))
128 # define __prefer_thumb__
131 /* How to return from a function call depends on the architecture variant. */
133 #if (__ARM_ARCH__ > 4) || defined(__ARM_ARCH_4T__)
136 # define RETc(x) bx##x lr
138 /* Special precautions for interworking on armv4t. */
139 # if (__ARM_ARCH__ == 4)
141 /* Always use bx, not ldr pc. */
142 # if (defined(__thumb__) || defined(__THUMB_INTERWORK__))
143 # define __INTERWORKING__
144 # endif /* __THUMB__ || __THUMB_INTERWORK__ */
146 /* Include thumb stub before arm mode code. */
147 # if defined(__thumb__) && !defined(__THUMB_INTERWORK__)
148 # define __INTERWORKING_STUBS__
149 # endif /* __thumb__ && !__THUMB_INTERWORK__ */
151 #endif /* __ARM_ARCH == 4 */
155 # define RET mov pc, lr
156 # define RETc(x) mov##x pc, lr
160 .macro cfi_pop advance, reg, cfa_offset
162 .pushsection .debug_frame
163 .byte 0x4 /* DW_CFA_advance_loc4 */
165 .byte (0xc0 | \reg) /* DW_CFA_restore */
166 .byte 0xe /* DW_CFA_def_cfa_offset */
171 .macro cfi_push advance, reg, offset, cfa_offset
173 .pushsection .debug_frame
174 .byte 0x4 /* DW_CFA_advance_loc4 */
176 .byte (0x80 | \reg) /* DW_CFA_offset */
177 .uleb128 (\offset / -4)
178 .byte 0xe /* DW_CFA_def_cfa_offset */
183 .macro cfi_start start_label, end_label
185 .pushsection .debug_frame
187 .4byte LSYM(Lend_cie) - LSYM(Lstart_cie) @ Length of CIE
189 .4byte 0xffffffff @ CIE Identifier Tag
190 .byte 0x1 @ CIE Version
191 .ascii "\0" @ CIE Augmentation
192 .uleb128 0x1 @ CIE Code Alignment Factor
193 .sleb128 -4 @ CIE Data Alignment Factor
194 .byte 0xe @ CIE RA Column
195 .byte 0xc @ DW_CFA_def_cfa
201 .4byte LSYM(Lend_fde)-LSYM(Lstart_fde) @ FDE Length
203 .4byte LSYM(Lstart_frame) @ FDE CIE offset
204 .4byte \start_label @ FDE initial location
205 .4byte \end_label-\start_label @ FDE address range
209 .macro cfi_end end_label
211 .pushsection .debug_frame
219 /* Don't pass dirn, it's there just to get token pasting right. */
221 .macro RETLDM regs=, cond=, unwind=, dirn=ia
222 #if defined (__INTERWORKING__)
224 ldr\cond lr, [sp], #8
226 # if defined(__thumb2__)
229 ldm\cond\dirn sp!, {\regs, lr}
233 /* Mark LR as restored. */
234 97: cfi_pop 97b - \unwind, 0xe, 0x0
238 /* Caller is responsible for providing IT instruction. */
240 ldr\cond pc, [sp], #8
242 # if defined(__thumb2__)
245 ldm\cond\dirn sp!, {\regs, pc}
251 /* The Unified assembly syntax allows the same code to be assembled for both
252 ARM and Thumb-2. However this is only supported by recent gas, so define
253 a set of macros to allow ARM code on older assemblers. */
254 #if defined(__thumb2__)
255 .macro do_it cond, suffix=""
258 .macro shift1 op, arg0, arg1, arg2
259 \op \arg0, \arg1, \arg2
263 #define COND(op1, op2, cond) op1 ## op2 ## cond
264 /* Perform an arithmetic operation with a variable shift operand. This
265 requires two instructions and a scratch register on Thumb-2. */
266 .macro shiftop name, dest, src1, src2, shiftop, shiftreg, tmp
267 \shiftop \tmp, \src2, \shiftreg
268 \name \dest, \src1, \tmp
271 .macro do_it cond, suffix=""
273 .macro shift1 op, arg0, arg1, arg2
274 mov \arg0, \arg1, \op \arg2
276 #define do_push stmfd sp!,
277 #define do_pop ldmfd sp!,
278 #define COND(op1, op2, cond) op1 ## cond ## op2
279 .macro shiftop name, dest, src1, src2, shiftop, shiftreg, tmp
280 \name \dest, \src1, \src2, \shiftop \shiftreg
285 .macro ARM_LDIV0 name signed
287 .ifc \signed, unsigned
288 movne r0, #0xffffffff
290 movgt r0, #0x7fffffff
291 movlt r0, #0x80000000
293 b SYM (__aeabi_idiv0) __PLT__
296 .macro ARM_LDIV0 name signed
298 98: cfi_push 98b - __\name, 0xe, -0x8, 0x8
299 bl SYM (__div0) __PLT__
300 mov r0, #0 @ About as wrong as it could be.
307 .macro THUMB_LDIV0 name signed
308 #if defined(__ARM_ARCH_6M__)
309 .ifc \signed, unsigned
313 mvn r0, r0 @ 0xffffffff
321 lsr r0, r0, #1 @ 0x7fffffff
324 lsl r0, r0, #24 @ 0x80000000
332 @ We know we are not on armv4t, so pop pc is safe.
336 .word __aeabi_idiv0 - 4b
337 #elif defined(__thumb2__)
339 .ifc \signed, unsigned
346 movgt r0, #0x7fffffff
348 movlt r0, #0x80000000
350 b.w SYM(__aeabi_idiv0) __PLT__
357 .ifc \signed, unsigned
358 movne r0, #0xffffffff
360 movgt r0, #0x7fffffff
361 movlt r0, #0x80000000
363 b SYM(__aeabi_idiv0) __PLT__
368 .macro THUMB_LDIV0 name signed
370 98: cfi_push 98b - __\name, 0xe, -0x4, 0x8
372 mov r0, #0 @ About as wrong as it could be.
373 #if defined (__INTERWORKING__)
386 .macro DIV_FUNC_END name signed
387 cfi_start __\name, LSYM(Lend_div0)
390 THUMB_LDIV0 \name \signed
392 ARM_LDIV0 \name \signed
394 cfi_end LSYM(Lend_div0)
398 .macro THUMB_FUNC_START name
405 /* Function start macros. Variants for ARM and Thumb. */
408 #define THUMB_FUNC .thumb_func
409 #define THUMB_CODE .force_thumb
410 # if defined(__thumb2__)
411 #define THUMB_SYNTAX .syntax divided
421 .macro FUNC_START name sp_section=
422 .ifc \sp_section, function_section
423 .section .text.__\name,"ax",%progbits
436 .macro ARM_SYM_START name
446 /* Special function that will always be coded in ARM assembly, even if
447 in Thumb-only compilation. */
449 #if defined(__thumb2__)
451 /* For Thumb-2 we build everything in thumb mode. */
452 .macro ARM_FUNC_START name sp_section=
453 FUNC_START \name \sp_section
456 #define EQUIV .thumb_set
461 #elif defined(__INTERWORKING_STUBS__)
463 .macro ARM_FUNC_START name
468 /* A hook to tell gdb that we've switched to ARM mode. Also used to call
469 directly from other local arm routines. */
472 #define EQUIV .thumb_set
473 /* Branch directly to a function declared with ARM_FUNC_START.
474 Must be called in arm mode. */
479 #else /* !(__INTERWORKING_STUBS__ || __thumb2__) */
481 #ifdef __ARM_ARCH_6M__
482 #define EQUIV .thumb_set
484 .macro ARM_FUNC_START name sp_section=
485 .ifc \sp_section, function_section
486 .section .text.__\name,"ax",%progbits
504 .macro FUNC_ALIAS new old
506 #if defined (__thumb__)
507 .thumb_set SYM (__\new), SYM (__\old)
509 .set SYM (__\new), SYM (__\old)
513 #ifndef __ARM_ARCH_6M__
514 .macro ARM_FUNC_ALIAS new old
516 EQUIV SYM (__\new), SYM (__\old)
517 #if defined(__INTERWORKING_STUBS__)
518 .set SYM (_L__\new), SYM (_L__\old)
542 /* Register aliases. */
544 work .req r4 @ XXXX is this safe ?
558 /* ------------------------------------------------------------------------ */
559 /* Bodies of the division and modulo routines. */
560 /* ------------------------------------------------------------------------ */
561 .macro ARM_DIV_BODY dividend, divisor, result, curbit
563 #if __ARM_ARCH__ >= 5 && ! defined (__OPTIMIZE_SIZE__)
565 #if defined (__thumb2__)
566 clz \curbit, \dividend
567 clz \result, \divisor
568 sub \curbit, \result, \curbit
569 rsb \curbit, \curbit, #31
571 add \curbit, \result, \curbit, lsl #4
578 .set shift, shift - 1
579 cmp.w \dividend, \divisor, lsl #shift
581 adc.w \result, \result, \result
583 subcs.w \dividend, \dividend, \divisor, lsl #shift
586 clz \curbit, \dividend
587 clz \result, \divisor
588 sub \curbit, \result, \curbit
589 rsbs \curbit, \curbit, #31
590 addne \curbit, \curbit, \curbit, lsl #1
592 addne pc, pc, \curbit, lsl #2
596 .set shift, shift - 1
597 cmp \dividend, \divisor, lsl #shift
598 adc \result, \result, \result
599 subcs \dividend, \dividend, \divisor, lsl #shift
603 #else /* __ARM_ARCH__ < 5 || defined (__OPTIMIZE_SIZE__) */
604 #if __ARM_ARCH__ >= 5
606 clz \curbit, \divisor
607 clz \result, \dividend
608 sub \result, \curbit, \result
610 mov \divisor, \divisor, lsl \result
611 mov \curbit, \curbit, lsl \result
614 #else /* __ARM_ARCH__ < 5 */
616 @ Initially shift the divisor left 3 bits if possible,
617 @ set curbit accordingly. This allows for curbit to be located
618 @ at the left end of each 4-bit nibbles in the division loop
619 @ to save one loop in most cases.
620 tst \divisor, #0xe0000000
621 moveq \divisor, \divisor, lsl #3
625 @ Unless the divisor is very big, shift it up in multiples of
626 @ four bits, since this is the amount of unwinding in the main
627 @ division loop. Continue shifting until the divisor is
628 @ larger than the dividend.
629 1: cmp \divisor, #0x10000000
630 cmplo \divisor, \dividend
631 movlo \divisor, \divisor, lsl #4
632 movlo \curbit, \curbit, lsl #4
635 @ For very big divisors, we must shift it a bit at a time, or
636 @ we will be in danger of overflowing.
637 1: cmp \divisor, #0x80000000
638 cmplo \divisor, \dividend
639 movlo \divisor, \divisor, lsl #1
640 movlo \curbit, \curbit, lsl #1
645 #endif /* __ARM_ARCH__ < 5 */
648 1: cmp \dividend, \divisor
650 subhs \dividend, \dividend, \divisor
651 orrhs \result, \result, \curbit
652 cmp \dividend, \divisor, lsr #1
654 subhs \dividend, \dividend, \divisor, lsr #1
655 orrhs \result, \result, \curbit, lsr #1
656 cmp \dividend, \divisor, lsr #2
658 subhs \dividend, \dividend, \divisor, lsr #2
659 orrhs \result, \result, \curbit, lsr #2
660 cmp \dividend, \divisor, lsr #3
662 subhs \dividend, \dividend, \divisor, lsr #3
663 orrhs \result, \result, \curbit, lsr #3
664 cmp \dividend, #0 @ Early termination?
666 movnes \curbit, \curbit, lsr #4 @ No, any more bits to do?
667 movne \divisor, \divisor, lsr #4
670 #endif /* __ARM_ARCH__ < 5 || defined (__OPTIMIZE_SIZE__) */
673 /* ------------------------------------------------------------------------ */
674 .macro ARM_DIV2_ORDER divisor, order
676 #if __ARM_ARCH__ >= 5
679 rsb \order, \order, #31
683 cmp \divisor, #(1 << 16)
684 movhs \divisor, \divisor, lsr #16
688 cmp \divisor, #(1 << 8)
689 movhs \divisor, \divisor, lsr #8
690 addhs \order, \order, #8
692 cmp \divisor, #(1 << 4)
693 movhs \divisor, \divisor, lsr #4
694 addhs \order, \order, #4
696 cmp \divisor, #(1 << 2)
697 addhi \order, \order, #3
698 addls \order, \order, \divisor, lsr #1
703 /* ------------------------------------------------------------------------ */
704 .macro ARM_MOD_BODY dividend, divisor, order, spare
706 #if __ARM_ARCH__ >= 5 && ! defined (__OPTIMIZE_SIZE__)
709 clz \spare, \dividend
710 sub \order, \order, \spare
711 rsbs \order, \order, #31
712 addne pc, pc, \order, lsl #3
716 .set shift, shift - 1
717 cmp \dividend, \divisor, lsl #shift
718 subcs \dividend, \dividend, \divisor, lsl #shift
721 #else /* __ARM_ARCH__ < 5 || defined (__OPTIMIZE_SIZE__) */
722 #if __ARM_ARCH__ >= 5
725 clz \spare, \dividend
726 sub \order, \order, \spare
727 mov \divisor, \divisor, lsl \order
729 #else /* __ARM_ARCH__ < 5 */
733 @ Unless the divisor is very big, shift it up in multiples of
734 @ four bits, since this is the amount of unwinding in the main
735 @ division loop. Continue shifting until the divisor is
736 @ larger than the dividend.
737 1: cmp \divisor, #0x10000000
738 cmplo \divisor, \dividend
739 movlo \divisor, \divisor, lsl #4
740 addlo \order, \order, #4
743 @ For very big divisors, we must shift it a bit at a time, or
744 @ we will be in danger of overflowing.
745 1: cmp \divisor, #0x80000000
746 cmplo \divisor, \dividend
747 movlo \divisor, \divisor, lsl #1
748 addlo \order, \order, #1
751 #endif /* __ARM_ARCH__ < 5 */
753 @ Perform all needed substractions to keep only the reminder.
754 @ Do comparisons in batch of 4 first.
755 subs \order, \order, #3 @ yes, 3 is intended here
758 1: cmp \dividend, \divisor
759 subhs \dividend, \dividend, \divisor
760 cmp \dividend, \divisor, lsr #1
761 subhs \dividend, \dividend, \divisor, lsr #1
762 cmp \dividend, \divisor, lsr #2
763 subhs \dividend, \dividend, \divisor, lsr #2
764 cmp \dividend, \divisor, lsr #3
765 subhs \dividend, \dividend, \divisor, lsr #3
767 mov \divisor, \divisor, lsr #4
768 subges \order, \order, #4
775 @ Either 1, 2 or 3 comparison/substractions are left.
779 cmp \dividend, \divisor
780 subhs \dividend, \dividend, \divisor
781 mov \divisor, \divisor, lsr #1
782 3: cmp \dividend, \divisor
783 subhs \dividend, \dividend, \divisor
784 mov \divisor, \divisor, lsr #1
785 4: cmp \dividend, \divisor
786 subhs \dividend, \dividend, \divisor
789 #endif /* __ARM_ARCH__ < 5 || defined (__OPTIMIZE_SIZE__) */
792 /* ------------------------------------------------------------------------ */
793 .macro THUMB_DIV_MOD_BODY modulo
794 @ Load the constant 0x10000000 into our work register.
798 @ Unless the divisor is very big, shift it up in multiples of
799 @ four bits, since this is the amount of unwinding in the main
800 @ division loop. Continue shifting until the divisor is
801 @ larger than the dividend.
804 cmp divisor, dividend
810 @ Set work to 0x80000000
813 @ For very big divisors, we must shift it a bit at a time, or
814 @ we will be in danger of overflowing.
817 cmp divisor, dividend
823 @ Test for possible subtractions ...
825 @ ... On the final pass, this may subtract too much from the dividend,
826 @ so keep track of which subtractions are done, we can fix them up
829 cmp dividend, divisor
831 sub dividend, dividend, divisor
833 lsr work, divisor, #1
836 sub dividend, dividend, work
843 lsr work, divisor, #2
846 sub dividend, dividend, work
853 lsr work, divisor, #3
856 sub dividend, dividend, work
865 @ ... and note which bits are done in the result. On the final pass,
866 @ this may subtract too much from the dividend, but the result will be ok,
867 @ since the "bit" will have been shifted out at the bottom.
868 cmp dividend, divisor
870 sub dividend, dividend, divisor
871 orr result, result, curbit
873 lsr work, divisor, #1
876 sub dividend, dividend, work
880 lsr work, divisor, #2
883 sub dividend, dividend, work
887 lsr work, divisor, #3
890 sub dividend, dividend, work
896 cmp dividend, #0 @ Early termination?
898 lsr curbit, #4 @ No, any more bits to do?
904 @ Any subtractions that we should not have done will be recorded in
905 @ the top three bits of "overdone". Exactly which were not needed
906 @ are governed by the position of the bit, stored in ip.
910 beq LSYM(Lgot_result)
912 @ If we terminated early, because dividend became zero, then the
913 @ bit in ip will not be in the bottom nibble, and we should not
914 @ perform the additions below. We must test for this though
915 @ (rather relying upon the TSTs to prevent the additions) since
916 @ the bit in ip could be in the top two bits which might then match
917 @ with one of the smaller RORs.
921 beq LSYM(Lgot_result)
928 lsr work, divisor, #3
936 lsr work, divisor, #2
943 beq LSYM(Lgot_result)
944 lsr work, divisor, #1
949 /* ------------------------------------------------------------------------ */
950 /* Start of the Real Functions */
951 /* ------------------------------------------------------------------------ */
954 #if defined(__prefer_thumb__)
957 FUNC_ALIAS aeabi_uidiv udivsi3
961 LSYM(udivsi3_skip_div0_test):
966 cmp dividend, divisor
967 blo LSYM(Lgot_result)
975 #elif defined(__ARM_ARCH_EXT_IDIV__)
977 ARM_FUNC_START udivsi3
978 ARM_FUNC_ALIAS aeabi_uidiv udivsi3
986 #else /* ARM version/Thumb-2. */
988 ARM_FUNC_START udivsi3
989 ARM_FUNC_ALIAS aeabi_uidiv udivsi3
991 /* Note: if called via udivsi3_skip_div0_test, this will unnecessarily
992 check for division-by-zero a second time. */
993 LSYM(udivsi3_skip_div0_test):
1003 ARM_DIV_BODY r0, r1, r2, r3
1013 12: ARM_DIV2_ORDER r1, r2
1018 #endif /* ARM version */
1020 DIV_FUNC_END udivsi3 unsigned
1022 #if defined(__prefer_thumb__)
1023 FUNC_START aeabi_uidivmod
1027 bl LSYM(udivsi3_skip_div0_test)
1032 #elif defined(__ARM_ARCH_EXT_IDIV__)
1033 ARM_FUNC_START aeabi_uidivmod
1041 ARM_FUNC_START aeabi_uidivmod
1044 stmfd sp!, { r0, r1, lr }
1045 bl LSYM(udivsi3_skip_div0_test)
1046 ldmfd sp!, { r1, r2, lr }
1051 FUNC_END aeabi_uidivmod
1053 #endif /* L_udivsi3 */
1054 /* ------------------------------------------------------------------------ */
1057 #ifdef __ARM_ARCH_EXT_IDIV__
1059 ARM_FUNC_START umodsi3
1067 #elif defined(__thumb__)
1074 cmp dividend, divisor
1081 THUMB_DIV_MOD_BODY 1
1086 #else /* ARM version. */
1090 subs r2, r1, #1 @ compare divisor with 1
1092 cmpne r0, r1 @ compare dividend with divisor
1094 tsthi r1, r2 @ see if divisor is power of 2
1098 ARM_MOD_BODY r0, r1, r2, r3
1102 #endif /* ARM version. */
1104 DIV_FUNC_END umodsi3 unsigned
1106 #endif /* L_umodsi3 */
1107 /* ------------------------------------------------------------------------ */
1110 #if defined(__prefer_thumb__)
1113 FUNC_ALIAS aeabi_idiv divsi3
1117 LSYM(divsi3_skip_div0_test):
1120 eor work, divisor @ Save the sign of the result.
1126 neg divisor, divisor @ Loops below use unsigned.
1130 neg dividend, dividend
1132 cmp dividend, divisor
1133 blo LSYM(Lgot_result)
1135 THUMB_DIV_MOD_BODY 0
1146 #elif defined(__ARM_ARCH_EXT_IDIV__)
1148 ARM_FUNC_START divsi3
1149 ARM_FUNC_ALIAS aeabi_idiv divsi3
1156 #else /* ARM/Thumb-2 version. */
1158 ARM_FUNC_START divsi3
1159 ARM_FUNC_ALIAS aeabi_idiv divsi3
1163 LSYM(divsi3_skip_div0_test):
1164 eor ip, r0, r1 @ save the sign of the result.
1166 rsbmi r1, r1, #0 @ loops below use unsigned.
1167 subs r2, r1, #1 @ division by 1 or -1 ?
1171 rsbmi r3, r0, #0 @ positive dividend value
1174 tst r1, r2 @ divisor is power of 2 ?
1177 ARM_DIV_BODY r3, r1, r0, r2
1184 10: teq ip, r0 @ same sign ?
1192 moveq r0, ip, asr #31
1196 12: ARM_DIV2_ORDER r1, r2
1204 #endif /* ARM version */
1206 DIV_FUNC_END divsi3 signed
1208 #if defined(__prefer_thumb__)
1209 FUNC_START aeabi_idivmod
1213 bl LSYM(divsi3_skip_div0_test)
1218 #elif defined(__ARM_ARCH_EXT_IDIV__)
1219 ARM_FUNC_START aeabi_idivmod
1227 ARM_FUNC_START aeabi_idivmod
1230 stmfd sp!, { r0, r1, lr }
1231 bl LSYM(divsi3_skip_div0_test)
1232 ldmfd sp!, { r1, r2, lr }
1237 FUNC_END aeabi_idivmod
1239 #endif /* L_divsi3 */
1240 /* ------------------------------------------------------------------------ */
1243 #if defined(__ARM_ARCH_EXT_IDIV__)
1245 ARM_FUNC_START modsi3
1254 #elif defined(__thumb__)
1262 neg divisor, divisor @ Loops below use unsigned.
1265 @ Need to save the sign of the dividend, unfortunately, we need
1266 @ work later on. Must do this after saving the original value of
1267 @ the work register, because we will pop this value off first.
1271 neg dividend, dividend
1273 cmp dividend, divisor
1274 blo LSYM(Lgot_result)
1276 THUMB_DIV_MOD_BODY 1
1281 neg dividend, dividend
1286 #else /* ARM version. */
1292 rsbmi r1, r1, #0 @ loops below use unsigned.
1293 movs ip, r0 @ preserve sign of dividend
1294 rsbmi r0, r0, #0 @ if negative make positive
1295 subs r2, r1, #1 @ compare divisor with 1
1296 cmpne r0, r1 @ compare dividend with divisor
1298 tsthi r1, r2 @ see if divisor is power of 2
1302 ARM_MOD_BODY r0, r1, r2, r3
1308 #endif /* ARM version */
1310 DIV_FUNC_END modsi3 signed
1312 #endif /* L_modsi3 */
1313 /* ------------------------------------------------------------------------ */
1319 FUNC_START aeabi_idiv0
1320 FUNC_START aeabi_ldiv0
1322 FUNC_END aeabi_ldiv0
1323 FUNC_END aeabi_idiv0
1330 #endif /* L_divmodsi_tools */
1331 /* ------------------------------------------------------------------------ */
1333 @ GNU/Linux division-by zero handler. Used in place of L_dvmd_tls
1335 /* Constant taken from <asm/signal.h>. */
1341 ARM_FUNC_START aeabi_idiv0
1342 ARM_FUNC_START aeabi_ldiv0
1349 bl SYM(raise) __PLT__
1353 FUNC_END aeabi_ldiv0
1354 FUNC_END aeabi_idiv0
1359 #endif /* L_dvmd_lnx */
1360 #ifdef L_clear_cache
1361 #if defined __ARM_EABI__ && defined __linux__
1362 @ EABI GNU/Linux call to cacheflush syscall.
1363 ARM_FUNC_START clear_cache
1365 #if __ARM_ARCH__ >= 7 || defined(__ARM_ARCH_6T2__)
1376 FUNC_END clear_cache
1378 #error "This is only for ARM EABI GNU/Linux"
1380 #endif /* L_clear_cache */
1381 /* ------------------------------------------------------------------------ */
1382 /* Dword shift operations. */
1383 /* All the following Dword shift variants rely on the fact that
1386 shft xxx, (Reg & 255)
1387 so for Reg value in (32...63) and (-1...-31) we will get zero (in the
1388 case of logical shifts) or the sign (for asr). */
1398 /* Prevent __aeabi double-word shifts from being produced on SymbianOS. */
1404 FUNC_ALIAS aeabi_llsr lshrdi3
1422 movmi al, al, lsr r2
1423 movpl al, ah, lsr r3
1424 orrmi al, al, ah, lsl ip
1436 FUNC_ALIAS aeabi_lasr ashrdi3
1443 @ If r2 is negative at this point the following step would OR
1444 @ the sign bit into all of AL. That's not what we want...
1458 movmi al, al, lsr r2
1459 movpl al, ah, asr r3
1460 orrmi al, al, ah, lsl ip
1473 FUNC_ALIAS aeabi_llsl ashldi3
1491 movmi ah, ah, lsl r2
1492 movpl ah, al, lsl r3
1493 orrmi ah, ah, al, lsr ip
1502 #endif /* __symbian__ */
1504 #if ((__ARM_ARCH__ > 5) && !defined(__ARM_ARCH_6M__)) \
1505 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
1506 || defined(__ARM_ARCH_5TEJ__)
1507 #define HAVE_ARM_CLZ 1
1511 #if defined(__ARM_ARCH_6M__)
1516 cmp r0, r3 /* 0x10000 */
1521 cmp r0, r3 /* #0x100 */
1526 cmp r0, r3 /* #0x10 */
1536 .byte 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0
1539 ARM_FUNC_START clzsi2
1540 # if defined(HAVE_ARM_CLZ)
1547 movcs r0, r0, lsr #16
1551 movcs r0, r0, lsr #8
1555 movcs r0, r0, lsr #4
1563 .byte 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0
1564 # endif /* !HAVE_ARM_CLZ */
1567 #endif /* L_clzsi2 */
1570 #if !defined(HAVE_ARM_CLZ)
1572 # if defined(__ARM_ARCH_6M__)
1576 ARM_FUNC_START clzdi2
1597 # if defined(__ARM_ARCH_6M__)
1604 #else /* HAVE_ARM_CLZ */
1606 ARM_FUNC_START clzdi2
1616 #endif /* L_clzdi2 */
1619 #if defined(__ARM_ARCH_6M__)
1626 cmp r0, r3 /* 0x10000 */
1631 cmp r0, r3 /* #0x100 */
1636 cmp r0, r3 /* #0x10 */
1646 .byte 27, 28, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31
1649 ARM_FUNC_START ctzsi2
1652 # if defined(HAVE_ARM_CLZ)
1660 movcs r0, r0, lsr #16
1664 movcs r0, r0, lsr #8
1668 movcs r0, r0, lsr #4
1676 .byte 27, 28, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31
1677 # endif /* !HAVE_ARM_CLZ */
1680 #endif /* L_clzsi2 */
1682 /* ------------------------------------------------------------------------ */
1683 /* These next two sections are here despite the fact that they contain Thumb
1684 assembler because their presence allows interworked code to be linked even
1685 when the GCC library is this one. */
1687 /* Do not build the interworking functions when the target architecture does
1688 not support Thumb instructions. (This can be a multilib option). */
1689 #if defined __ARM_ARCH_4T__ || defined __ARM_ARCH_5T__\
1690 || defined __ARM_ARCH_5TE__ || defined __ARM_ARCH_5TEJ__ \
1691 || __ARM_ARCH__ >= 6
1693 #if defined L_call_via_rX
1695 /* These labels & instructions are used by the Arm/Thumb interworking code.
1696 The address of function to be called is loaded into a register and then
1697 one of these labels is called via a BL instruction. This puts the
1698 return address into the link register with the bottom bit set, and the
1699 code here switches to the correct mode before executing the function. */
1705 .macro call_via register
1706 THUMB_FUNC_START _call_via_\register
1711 SIZE (_call_via_\register)
1730 #endif /* L_call_via_rX */
1732 /* Don't bother with the old interworking routines for Thumb-2. */
1733 /* ??? Maybe only omit these on "m" variants. */
1734 #if !defined(__thumb2__) && !defined(__ARM_ARCH_6M__)
1736 #if defined L_interwork_call_via_rX
1738 /* These labels & instructions are used by the Arm/Thumb interworking code,
1739 when the target address is in an unknown instruction set. The address
1740 of function to be called is loaded into a register and then one of these
1741 labels is called via a BL instruction. This puts the return address
1742 into the link register with the bottom bit set, and the code here
1743 switches to the correct mode before executing the function. Unfortunately
1744 the target code cannot be relied upon to return via a BX instruction, so
1745 instead we have to store the resturn address on the stack and allow the
1746 called function to return here instead. Upon return we recover the real
1747 return address and use a BX to get back to Thumb mode.
1749 There are three variations of this code. The first,
1750 _interwork_call_via_rN(), will push the return address onto the
1751 stack and pop it in _arm_return(). It should only be used if all
1752 arguments are passed in registers.
1754 The second, _interwork_r7_call_via_rN(), instead stores the return
1755 address at [r7, #-4]. It is the caller's responsibility to ensure
1756 that this address is valid and contains no useful data.
1758 The third, _interwork_r11_call_via_rN(), works in the same way but
1759 uses r11 instead of r7. It is useful if the caller does not really
1760 need a frame pointer. */
1767 LSYM(Lstart_arm_return):
1768 cfi_start LSYM(Lstart_arm_return) LSYM(Lend_arm_return)
1769 cfi_push 0, 0xe, -0x8, 0x8
1770 nop @ This nop is for the benefit of debuggers, so that
1771 @ backtraces will use the correct unwind information.
1773 RETLDM unwind=LSYM(Lstart_arm_return)
1774 cfi_end LSYM(Lend_arm_return)
1776 .globl _arm_return_r7
1781 .globl _arm_return_r11
1786 .macro interwork_with_frame frame, register, name, return
1789 THUMB_FUNC_START \name
1796 streq lr, [\frame, #-4]
1797 adreq lr, _arm_return_\frame
1803 .macro interwork register
1806 THUMB_FUNC_START _interwork_call_via_\register
1812 .globl LSYM(Lchange_\register)
1813 LSYM(Lchange_\register):
1815 streq lr, [sp, #-8]!
1816 adreq lr, _arm_return
1819 SIZE (_interwork_call_via_\register)
1821 interwork_with_frame r7,\register,_interwork_r7_call_via_\register
1822 interwork_with_frame r11,\register,_interwork_r11_call_via_\register
1840 /* The LR case has to be handled a little differently... */
1843 THUMB_FUNC_START _interwork_call_via_lr
1852 stmeqdb r13!, {lr, pc}
1854 adreq lr, _arm_return
1857 SIZE (_interwork_call_via_lr)
1859 #endif /* L_interwork_call_via_rX */
1860 #endif /* !__thumb2__ */
1862 /* Functions to support compact pic switch tables in thumb1 state.
1863 All these routines take an index into the table in r0. The
1864 table is at LR & ~1 (but this must be rounded up in the case
1865 of 32-bit entires). They are only permitted to clobber r12
1866 and r14 and r0 must be preserved on exit. */
1867 #ifdef L_thumb1_case_sqi
1873 THUMB_FUNC_START __gnu_thumb1_case_sqi
1883 SIZE (__gnu_thumb1_case_sqi)
1886 #ifdef L_thumb1_case_uqi
1892 THUMB_FUNC_START __gnu_thumb1_case_uqi
1902 SIZE (__gnu_thumb1_case_uqi)
1905 #ifdef L_thumb1_case_shi
1911 THUMB_FUNC_START __gnu_thumb1_case_shi
1922 SIZE (__gnu_thumb1_case_shi)
1925 #ifdef L_thumb1_case_uhi
1931 THUMB_FUNC_START __gnu_thumb1_case_uhi
1942 SIZE (__gnu_thumb1_case_uhi)
1945 #ifdef L_thumb1_case_si
1951 THUMB_FUNC_START __gnu_thumb1_case_si
1954 adds.n r1, r1, #2 /* Align to word. */
1962 mov pc, lr /* We know we were called from thumb code. */
1963 SIZE (__gnu_thumb1_case_si)
1966 #endif /* Arch supports thumb. */
1969 #ifndef __ARM_ARCH_6M__
1970 #include "ieee754-df.S"
1971 #include "ieee754-sf.S"
1973 #else /* __ARM_ARCH_6M__ */
1974 #include "bpabi-v6m.S"
1975 #endif /* __ARM_ARCH_6M__ */
1976 #endif /* !__symbian__ */