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.
53 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
54 eor r2, r0, r0, asr #31
55 eor r3, r1, r1, asr #31
56 sub r0, r2, r0, asr #31
57 sub r1, r3, r1, asr #31
59 bl SYMBOL_NAME(__udivsi3)
60 // Apply sign of quotient to result and return.
61 eor r0, r0, r4, asr #31
62 sub r0, r0, r4, asr #31
63 CLEAR_FRAME_AND_RETURN
65 END_COMPILERRT_FUNCTION(__divsi3)
67 NO_EXEC_STACK_DIRECTIVE