1 /*===-- divmodsi4.S - 32-bit signed integer divide and modulus ------------===//
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 __divmodsi4 (32-bit signed integer divide and
11 * modulus) function for the ARM architecture. A naive digit-by-digit
12 * computation is employed for simplicity.
14 *===----------------------------------------------------------------------===*/
16 #include "../assembly.h"
18 #define ESTABLISH_FRAME \
21 #define CLEAR_FRAME_AND_RETURN \
26 #if __ARM_ARCH_ISA_THUMB == 2
30 @ int __divmodsi4(int divident, int divisor, int *remainder)
31 @ Calculate the quotient and remainder of the (signed) division. The return
32 @ value is the quotient, the remainder is placed in the variable.
35 #if __ARM_ARCH_ISA_THUMB == 2
36 DEFINE_COMPILERRT_THUMB_FUNCTION(__divmodsi4)
38 DEFINE_COMPILERRT_FUNCTION(__divmodsi4)
40 #if __ARM_ARCH_EXT_IDIV__
42 beq LOCAL_LABEL(divzero)
53 // Set aside the sign of the quotient and modulus, and the address for the
58 // Take the absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
59 eor ip, r0, r0, asr #31
60 eor lr, r1, r1, asr #31
61 sub r0, ip, r0, asr #31
62 sub r1, lr, r1, asr #31
64 bl SYMBOL_NAME(__udivmodsi4)
65 // Apply the sign of quotient and modulus
67 eor r0, r0, r4, asr #31
68 eor r1, r1, r5, asr #31
69 sub r0, r0, r4, asr #31
70 sub r1, r1, r5, asr #31
72 CLEAR_FRAME_AND_RETURN
74 END_COMPILERRT_FUNCTION(__divmodsi4)