1222656Sed/*===-- modsi3.S - 32-bit signed integer modulus --------------------------===//
2222656Sed *
3222656Sed *                     The LLVM Compiler Infrastructure
4222656Sed *
5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open
6222656Sed * Source Licenses. See LICENSE.TXT for details.
7222656Sed *
8222656Sed *===----------------------------------------------------------------------===//
9222656Sed *
10222656Sed * This file implements the __modsi3 (32-bit signed integer modulus) function
11222656Sed * for the ARM architecture as a wrapper around the unsigned routine.
12222656Sed *
13222656Sed *===----------------------------------------------------------------------===*/
14214152Sed
15214152Sed#include "../assembly.h"
16214152Sed
17222656Sed#define ESTABLISH_FRAME \
18222656Sed    push   {r4, r7, lr}    ;\
19222656Sed    add     r7,     sp, #4
20222656Sed#define CLEAR_FRAME_AND_RETURN \
21222656Sed    pop    {r4, r7, pc}
22222656Sed
23222656Sed.syntax unified
24222656Sed.align 3
25214152SedDEFINE_COMPILERRT_FUNCTION(__modsi3)
26222656Sed    ESTABLISH_FRAME
27222656Sed    //  Set aside the sign of the dividend.
28222656Sed    mov     r4,     r0
29222656Sed    //  Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
30222656Sed    eor     r2,     r0, r0, asr #31
31222656Sed    eor     r3,     r1, r1, asr #31
32222656Sed    sub     r0,     r2, r0, asr #31
33222656Sed    sub     r1,     r3, r1, asr #31
34222656Sed    //  abs(a) % abs(b)
35222656Sed    bl     SYMBOL_NAME(__umodsi3)
36222656Sed    //  Apply sign of dividend to result and return.
37222656Sed    eor     r0,     r0, r4, asr #31
38222656Sed    sub     r0,     r0, r4, asr #31
39222656Sed    CLEAR_FRAME_AND_RETURN
40