1 //===-- divmodsi4.S - 32-bit signed integer divide and modulus ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the __divmodsi4 (32-bit signed integer divide and
10 // modulus) function for the ARM architecture. A naive digit-by-digit
11 // computation is employed for simplicity.
13 //===----------------------------------------------------------------------===//
15 #include "../assembly.h"
17 #define ESTABLISH_FRAME \
20 #define CLEAR_FRAME_AND_RETURN \
27 @ int __divmodsi4(int divident, int divisor, int *remainder)
28 @ Calculate the quotient and remainder of the (signed) division. The return
29 @ value is the quotient, the remainder is placed in the variable.
32 DEFINE_COMPILERRT_FUNCTION(__divmodsi4)
33 #if __ARM_ARCH_EXT_IDIV__
35 beq LOCAL_LABEL(divzero)
46 // Set aside the sign of the quotient and modulus, and the address for the
51 // Take the absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
52 eor ip, r0, r0, asr #31
53 eor lr, r1, r1, asr #31
54 sub r0, ip, r0, asr #31
55 sub r1, lr, r1, asr #31
57 bl SYMBOL_NAME(__udivmodsi4)
58 // Apply the sign of quotient and modulus
60 eor r0, r0, r4, asr #31
61 eor r1, r1, r5, asr #31
62 sub r0, r0, r4, asr #31
63 sub r1, r1, r5, asr #31
65 CLEAR_FRAME_AND_RETURN
67 END_COMPILERRT_FUNCTION(__divmodsi4)
69 NO_EXEC_STACK_DIRECTIVE