• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
24.syntax unified
25.align 3
26DEFINE_COMPILERRT_FUNCTION(__divmodsi4)
27    ESTABLISH_FRAME
28//  Set aside the sign of the quotient and modulus, and the address for the
29//  modulus.
30    eor     r4,     r0, r1
31    mov     r5,     r0
32    mov     r6,     r2
33//  Take the absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
34    eor     ip,     r0, r0, asr #31
35    eor     lr,     r1, r1, asr #31
36    sub     r0,     ip, r0, asr #31
37    sub     r1,     lr, r1, asr #31
38//  Unsigned divmod:
39    bl      SYMBOL_NAME(__udivmodsi4)
40//  Apply the sign of quotient and modulus
41    ldr     r1,    [r6]
42    eor     r0,     r0, r4, asr #31
43    eor     r1,     r1, r5, asr #31
44    sub     r0,     r0, r4, asr #31
45    sub     r1,     r1, r5, asr #31
46    str     r1,    [r6]
47    CLEAR_FRAME_AND_RETURN
48