1 1.1 joerg /*===-- divsi3.S - 32-bit signed integer divide ---------------------------===// 2 1.1 joerg * 3 1.1 joerg * The LLVM Compiler Infrastructure 4 1.1 joerg * 5 1.1 joerg * This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg * Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg * 8 1.1 joerg *===----------------------------------------------------------------------===// 9 1.1 joerg * 10 1.1 joerg * This file implements the __divsi3 (32-bit signed integer divide) function 11 1.1 joerg * for the ARM architecture as a wrapper around the unsigned routine. 12 1.1 joerg * 13 1.1 joerg *===----------------------------------------------------------------------===*/ 14 1.1 joerg 15 1.1 joerg #include "../assembly.h" 16 1.1 joerg 17 1.1 joerg #define ESTABLISH_FRAME \ 18 1.3 skrll push {r4, lr} 19 1.1 joerg #define CLEAR_FRAME_AND_RETURN \ 20 1.3 skrll pop {r4, pc} 21 1.1 joerg 22 1.2 rin .syntax unified 23 1.2 rin .text 24 1.2 rin #if __ARM_ARCH_ISA_THUMB == 2 25 1.2 rin .thumb 26 1.2 rin #endif 27 1.2 rin 28 1.2 rin .p2align 3 29 1.1 joerg // Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine. 30 1.1 joerg DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3) 31 1.2 rin 32 1.2 rin @ int __divsi3(int divident, int divisor) 33 1.2 rin @ Calculate and return the quotient of the (signed) division. 34 1.2 rin 35 1.2 rin #if __ARM_ARCH_ISA_THUMB == 2 36 1.2 rin DEFINE_COMPILERRT_THUMB_FUNCTION(__divsi3) 37 1.2 rin #else 38 1.1 joerg DEFINE_COMPILERRT_FUNCTION(__divsi3) 39 1.2 rin #endif 40 1.1 joerg #if __ARM_ARCH_EXT_IDIV__ 41 1.1 joerg tst r1,r1 42 1.1 joerg beq LOCAL_LABEL(divzero) 43 1.1 joerg sdiv r0, r0, r1 44 1.1 joerg bx lr 45 1.1 joerg LOCAL_LABEL(divzero): 46 1.1 joerg mov r0,#0 47 1.1 joerg bx lr 48 1.1 joerg #else 49 1.1 joerg ESTABLISH_FRAME 50 1.1 joerg // Set aside the sign of the quotient. 51 1.1 joerg eor r4, r0, r1 52 1.1 joerg // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). 53 1.1 joerg eor r2, r0, r0, asr #31 54 1.1 joerg eor r3, r1, r1, asr #31 55 1.1 joerg sub r0, r2, r0, asr #31 56 1.1 joerg sub r1, r3, r1, asr #31 57 1.1 joerg // abs(a) / abs(b) 58 1.1 joerg bl SYMBOL_NAME(__udivsi3) 59 1.1 joerg // Apply sign of quotient to result and return. 60 1.1 joerg eor r0, r0, r4, asr #31 61 1.1 joerg sub r0, r0, r4, asr #31 62 1.1 joerg CLEAR_FRAME_AND_RETURN 63 1.1 joerg #endif 64 1.1 joerg END_COMPILERRT_FUNCTION(__divsi3) 65