]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/builtins/arm/divsi3.S
Merge compiler-rt r291274.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / builtins / arm / divsi3.S
1 /*===-- divsi3.S - 32-bit signed integer divide ---------------------------===//
2  *
3  *                     The LLVM Compiler Infrastructure
4  *
5  * This file is dual licensed under the MIT and the University of Illinois Open
6  * Source Licenses. See LICENSE.TXT for details.
7  *
8  *===----------------------------------------------------------------------===//
9  *
10  * This file implements the __divsi3 (32-bit signed integer divide) function
11  * for the ARM architecture as a wrapper around the unsigned routine.
12  *
13  *===----------------------------------------------------------------------===*/
14
15 #include "../assembly.h"
16
17 #define ESTABLISH_FRAME \
18     push   {r4, r7, lr}    ;\
19     add     r7,     sp, #4
20 #define CLEAR_FRAME_AND_RETURN \
21     pop    {r4, r7, pc}
22
23         .syntax unified
24         .text
25 #if __ARM_ARCH_ISA_THUMB == 2
26         .thumb
27 #endif
28
29         .p2align 3
30 // Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.
31 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)
32
33 @ int __divsi3(int divident, int divisor)
34 @   Calculate and return the quotient of the (signed) division.
35
36 #if __ARM_ARCH_ISA_THUMB == 2
37 DEFINE_COMPILERRT_THUMB_FUNCTION(__divsi3)
38 #else
39 DEFINE_COMPILERRT_FUNCTION(__divsi3)
40 #endif
41 #if __ARM_ARCH_EXT_IDIV__
42    tst     r1,r1
43    beq     LOCAL_LABEL(divzero)
44    sdiv    r0, r0, r1
45    bx      lr
46 LOCAL_LABEL(divzero):
47    mov     r0,#0
48    bx      lr
49 #else
50 ESTABLISH_FRAME
51 //  Set aside the sign of the quotient.
52 #  if __ARM_ARCH_ISA_THUMB == 1
53     movs    r4,     r0
54     eors    r4,     r1
55 #  else
56     eor     r4,     r0, r1
57 #  endif
58 //  Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
59 #  if   __ARM_ARCH_ISA_THUMB == 1
60     asrs    r2,     r0, #31
61     asrs    r3,     r1, #31
62     eors    r0,     r2
63     eors    r1,     r3
64     subs    r0,     r0, r2
65     subs    r1,     r1, r3
66 #  else
67     eor     r2,     r0, r0, asr #31
68     eor     r3,     r1, r1, asr #31
69     sub     r0,     r2, r0, asr #31
70     sub     r1,     r3, r1, asr #31
71 #  endif
72 //  abs(a) / abs(b)
73     bl      SYMBOL_NAME(__udivsi3)
74 //  Apply sign of quotient to result and return.
75 #  if __ARM_ARCH_ISA_THUMB == 1
76     asrs    r4,     #31
77     eors    r0,     r4
78     subs    r0,     r0, r4
79 #  else
80     eor     r0,     r0, r4, asr #31
81     sub     r0,     r0, r4, asr #31
82 #  endif
83     CLEAR_FRAME_AND_RETURN
84 #endif
85 END_COMPILERRT_FUNCTION(__divsi3)
86
87 NO_EXEC_STACK_DIRECTIVE
88