1 /*===-- modsi3.S - 32-bit signed integer 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 __modsi3 (32-bit signed integer modulus) 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
29 @ int __modsi3(int divident, int divisor)
30 @ Calculate and return the remainder of the (signed) division.
33 #if __ARM_ARCH_ISA_THUMB == 2
34 DEFINE_COMPILERRT_THUMB_FUNCTION(__modsi3)
36 DEFINE_COMPILERRT_FUNCTION(__modsi3)
38 #if __ARM_ARCH_EXT_IDIV__
40 beq LOCAL_LABEL(divzero)
49 // Set aside the sign of the dividend.
51 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
52 eor r2, r0, r0, asr #31
53 eor r3, r1, r1, asr #31
54 sub r0, r2, r0, asr #31
55 sub r1, r3, r1, asr #31
57 bl SYMBOL_NAME(__umodsi3)
58 // Apply sign of dividend to result and return.
59 eor r0, r0, r4, asr #31
60 sub r0, r0, r4, asr #31
61 CLEAR_FRAME_AND_RETURN
63 END_COMPILERRT_FUNCTION(__modsi3)