1222625Sed/*===-- divsi3.S - 32-bit signed integer divide ---------------------------===// 2222625Sed * 3222625Sed * The LLVM Compiler Infrastructure 4222625Sed * 5222625Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222625Sed * Source Licenses. See LICENSE.TXT for details. 7222625Sed * 8222625Sed *===----------------------------------------------------------------------===// 9222625Sed * 10222625Sed * This file implements the __divsi3 (32-bit signed integer divide) function 11222625Sed * for the ARM architecture as a wrapper around the unsigned routine. 12222625Sed * 13222625Sed *===----------------------------------------------------------------------===*/ 14222625Sed 15222625Sed#include "../assembly.h" 16222625Sed 17222625Sed#define ESTABLISH_FRAME \ 18222625Sed push {r4, r7, lr} ;\ 19222625Sed add r7, sp, #4 20222625Sed#define CLEAR_FRAME_AND_RETURN \ 21222625Sed pop {r4, r7, pc} 22222625Sed 23222625Sed.syntax unified 24222625Sed.align 3 25222625Sed// Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine. 26222625SedDEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3) 27222625SedDEFINE_COMPILERRT_FUNCTION(__divsi3) 28245628Sandrew#if __ARM_ARCH_7S__ 29245628Sandrew tst r1,r1 30245628Sandrew beq LOCAL_LABEL(divzero) 31245628Sandrew sdiv r0, r0, r1 32245628Sandrew bx lr 33245628SandrewLOCAL_LABEL(divzero): 34245628Sandrew mov r0,#0 35245628Sandrew bx lr 36245628Sandrew#else 37245628SandrewESTABLISH_FRAME 38222625Sed// Set aside the sign of the quotient. 39222625Sed eor r4, r0, r1 40222625Sed// Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). 41222625Sed eor r2, r0, r0, asr #31 42222625Sed eor r3, r1, r1, asr #31 43222625Sed sub r0, r2, r0, asr #31 44222625Sed sub r1, r3, r1, asr #31 45222625Sed// abs(a) / abs(b) 46222625Sed bl SYMBOL_NAME(__udivsi3) 47222625Sed// Apply sign of quotient to result and return. 48222625Sed eor r0, r0, r4, asr #31 49222625Sed sub r0, r0, r4, asr #31 50222625Sed CLEAR_FRAME_AND_RETURN 51245628Sandrew#endif 52