divsi3.S revision 1.1.1.4.34.1 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, lr}
19 #define CLEAR_FRAME_AND_RETURN \
20 pop {r4, pc}
21
22 .syntax unified
23 .text
24 #if __ARM_ARCH_ISA_THUMB == 2
25 .thumb
26 #endif
27
28 .p2align 3
29 // Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.
30 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)
31
32 @ int __divsi3(int divident, int divisor)
33 @ Calculate and return the quotient of the (signed) division.
34
35 #if __ARM_ARCH_ISA_THUMB == 2
36 DEFINE_COMPILERRT_THUMB_FUNCTION(__divsi3)
37 #else
38 DEFINE_COMPILERRT_FUNCTION(__divsi3)
39 #endif
40 #if __ARM_ARCH_EXT_IDIV__
41 tst r1,r1
42 beq LOCAL_LABEL(divzero)
43 sdiv r0, r0, r1
44 bx lr
45 LOCAL_LABEL(divzero):
46 mov r0,#0
47 bx lr
48 #else
49 ESTABLISH_FRAME
50 // Set aside the sign of the quotient.
51 eor r4, r0, r1
52 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
53 eor r2, r0, r0, asr #31
54 eor r3, r1, r1, asr #31
55 sub r0, r2, r0, asr #31
56 sub r1, r3, r1, asr #31
57 // abs(a) / abs(b)
58 bl SYMBOL_NAME(__udivsi3)
59 // Apply sign of quotient to result and return.
60 eor r0, r0, r4, asr #31
61 sub r0, r0, r4, asr #31
62 CLEAR_FRAME_AND_RETURN
63 #endif
64 END_COMPILERRT_FUNCTION(__divsi3)
65