blob: 00e61815ab4fdf83687d9df5eaa3ca23be88fcf9 [file] [log] [blame]
Stephen Canon5abb5c12011-03-18 16:35:02 +00001/*===-- divsi3.S - 32-bit signed integer divide ---------------------------===//
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
7 *
8 *===----------------------------------------------------------------------===//
9 *
10 * This file implements the __divsi3 (32-bit signed integer divide) function
11 * for the ARM architecture as a wrapper around the unsigned routine.
12 *
13 *===----------------------------------------------------------------------===*/
14
15#include "../assembly.h"
16
17#define ESTABLISH_FRAME \
18 push {r4, r7, lr} ;\
19 add r7, sp, #4
20#define CLEAR_FRAME_AND_RETURN \
21 pop {r4, r7, pc}
22
23.syntax unified
24.align 3
Anton Korobeynikov75e3c192011-04-19 17:51:24 +000025// Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.
26DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)
Stephen Canon5abb5c12011-03-18 16:35:02 +000027DEFINE_COMPILERRT_FUNCTION(__divsi3)
28 ESTABLISH_FRAME
29// Set aside the sign of the quotient.
30 eor r4, r0, r1
31// Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
32 eor r2, r0, r0, asr #31
33 eor r3, r1, r1, asr #31
34 sub r0, r2, r0, asr #31
35 sub r1, r3, r1, asr #31
36// abs(a) / abs(b)
Anton Korobeynikov16536102011-04-19 17:50:09 +000037 bl SYMBOL_NAME(__udivsi3)
Stephen Canon5abb5c12011-03-18 16:35:02 +000038// Apply sign of quotient to result and return.
39 eor r0, r0, r4, asr #31
40 sub r0, r0, r4, asr #31
41 CLEAR_FRAME_AND_RETURN