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