1 /*===-- divsi3.S - 32-bit signed integer divide ---------------------------===//
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===//
10 * This file implements the __divsi3 (32-bit signed integer divide) function
11 * for the ARM architecture as a wrapper around the unsigned routine.
13 *===----------------------------------------------------------------------===*/
15 #include "../assembly.h"
17 #define ESTABLISH_FRAME \
20 #define CLEAR_FRAME_AND_RETURN \
25 #if __ARM_ARCH_ISA_THUMB == 2
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)
33 @ int __divsi3(int divident, int divisor)
34 @ Calculate and return the quotient of the (signed) division.
36 #if __ARM_ARCH_ISA_THUMB == 2
37 DEFINE_COMPILERRT_THUMB_FUNCTION(__divsi3)
39 DEFINE_COMPILERRT_FUNCTION(__divsi3)
41 #if __ARM_ARCH_EXT_IDIV__
43 beq LOCAL_LABEL(divzero)
51 // Set aside the sign of the quotient.
52 # if __ARM_ARCH_ISA_THUMB == 1
58 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
59 # if __ARM_ARCH_ISA_THUMB == 1
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
73 bl SYMBOL_NAME(__udivsi3)
74 // Apply sign of quotient to result and return.
75 # if __ARM_ARCH_ISA_THUMB == 1
80 eor r0, r0, r4, asr #31
81 sub r0, r0, r4, asr #31
83 CLEAR_FRAME_AND_RETURN
85 END_COMPILERRT_FUNCTION(__divsi3)
87 NO_EXEC_STACK_DIRECTIVE