1 /*===-- divsi3.S - 32-bit signed integer divide ---------------------------===//
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===//
10 * This file implements the __divsi3 (32-bit signed integer divide) function
11 * for the ARM architecture as a wrapper around the unsigned routine.
13 *===----------------------------------------------------------------------===*/
15 #include "../assembly.h"
17 #define ESTABLISH_FRAME \
20 #define CLEAR_FRAME_AND_RETURN \
25 // Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.
26 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)
27 DEFINE_COMPILERRT_FUNCTION(__divsi3)
30 beq LOCAL_LABEL(divzero)
38 // Set aside the sign of the quotient.
40 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
41 eor r2, r0, r0, asr #31
42 eor r3, r1, r1, asr #31
43 sub r0, r2, r0, asr #31
44 sub r1, r3, r1, asr #31
46 bl SYMBOL_NAME(__udivsi3)
47 // Apply sign of quotient to result and return.
48 eor r0, r0, r4, asr #31
49 sub r0, r0, r4, asr #31
50 CLEAR_FRAME_AND_RETURN