]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/lib/builtins/arm/divmodsi4.S
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / builtins / arm / divmodsi4.S
CommitLineData
1a4d82fc
JJ
1/*===-- divmodsi4.S - 32-bit signed integer divide and 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 __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.
13 *
14 *===----------------------------------------------------------------------===*/
15
16#include "../assembly.h"
17
18#define ESTABLISH_FRAME \
19 push {r4-r7, lr} ;\
20 add r7, sp, #12
21#define CLEAR_FRAME_AND_RETURN \
22 pop {r4-r7, pc}
23
92a42be0
SL
24 .syntax unified
25 .text
2c00a5a8 26 DEFINE_CODE_STATE
92a42be0
SL
27
28@ int __divmodsi4(int divident, int divisor, int *remainder)
29@ Calculate the quotient and remainder of the (signed) division. The return
30@ value is the quotient, the remainder is placed in the variable.
31
32 .p2align 3
1a4d82fc
JJ
33DEFINE_COMPILERRT_FUNCTION(__divmodsi4)
34#if __ARM_ARCH_EXT_IDIV__
35 tst r1, r1
36 beq LOCAL_LABEL(divzero)
37 mov r3, r0
38 sdiv r0, r3, r1
39 mls r1, r0, r1, r3
40 str r1, [r2]
41 bx lr
42LOCAL_LABEL(divzero):
43 mov r0, #0
44 bx lr
45#else
46 ESTABLISH_FRAME
47// Set aside the sign of the quotient and modulus, and the address for the
48// modulus.
49 eor r4, r0, r1
50 mov r5, r0
51 mov r6, r2
52// Take the absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
53 eor ip, r0, r0, asr #31
54 eor lr, r1, r1, asr #31
55 sub r0, ip, r0, asr #31
56 sub r1, lr, r1, asr #31
57// Unsigned divmod:
58 bl SYMBOL_NAME(__udivmodsi4)
59// Apply the sign of quotient and modulus
60 ldr r1, [r6]
61 eor r0, r0, r4, asr #31
62 eor r1, r1, r5, asr #31
63 sub r0, r0, r4, asr #31
64 sub r1, r1, r5, asr #31
65 str r1, [r6]
66 CLEAR_FRAME_AND_RETURN
67#endif
68END_COMPILERRT_FUNCTION(__divmodsi4)
3157f602
XL
69
70NO_EXEC_STACK_DIRECTIVE
71