]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | /*===-- modsi3.S - 32-bit signed integer modulus --------------------------===// |
2 | * | |
3 | * The LLVM Compiler Infrastructure | |
4 | * | |
5 | * This file is dual licensed under the MIT and the University of Illinois Open | |
6 | * Source Licenses. See LICENSE.TXT for details. | |
7 | * | |
8 | *===----------------------------------------------------------------------===// | |
9 | * | |
10 | * This file implements the __modsi3 (32-bit signed integer modulus) function | |
11 | * for the ARM architecture as a wrapper around the unsigned routine. | |
12 | * | |
13 | *===----------------------------------------------------------------------===*/ | |
14 | ||
15 | #include "../assembly.h" | |
16 | ||
17 | #define ESTABLISH_FRAME \ | |
18 | push {r4, r7, lr} ;\ | |
19 | add r7, sp, #4 | |
20 | #define CLEAR_FRAME_AND_RETURN \ | |
21 | pop {r4, r7, pc} | |
22 | ||
92a42be0 SL |
23 | .syntax unified |
24 | .text | |
2c00a5a8 | 25 | DEFINE_CODE_STATE |
92a42be0 SL |
26 | |
27 | @ int __modsi3(int divident, int divisor) | |
28 | @ Calculate and return the remainder of the (signed) division. | |
29 | ||
30 | .p2align 3 | |
1a4d82fc JJ |
31 | DEFINE_COMPILERRT_FUNCTION(__modsi3) |
32 | #if __ARM_ARCH_EXT_IDIV__ | |
33 | tst r1, r1 | |
34 | beq LOCAL_LABEL(divzero) | |
35 | sdiv r2, r0, r1 | |
36 | mls r0, r2, r1, r0 | |
37 | bx lr | |
38 | LOCAL_LABEL(divzero): | |
39 | mov r0, #0 | |
40 | bx lr | |
41 | #else | |
42 | ESTABLISH_FRAME | |
43 | // Set aside the sign of the dividend. | |
44 | mov r4, r0 | |
45 | // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). | |
46 | eor r2, r0, r0, asr #31 | |
47 | eor r3, r1, r1, asr #31 | |
48 | sub r0, r2, r0, asr #31 | |
49 | sub r1, r3, r1, asr #31 | |
50 | // abs(a) % abs(b) | |
51 | bl SYMBOL_NAME(__umodsi3) | |
52 | // Apply sign of dividend to result and return. | |
53 | eor r0, r0, r4, asr #31 | |
54 | sub r0, r0, r4, asr #31 | |
55 | CLEAR_FRAME_AND_RETURN | |
56 | #endif | |
57 | END_COMPILERRT_FUNCTION(__modsi3) | |
3157f602 XL |
58 | |
59 | NO_EXEC_STACK_DIRECTIVE | |
60 |