1 //===-- divsi3.S - 32-bit signed integer divide ---------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the __divsi3 (32-bit signed integer divide) function
10 // for the ARM architecture as a wrapper around the unsigned routine.
12 //===----------------------------------------------------------------------===//
14 #include "../assembly.h"
16 #define ESTABLISH_FRAME \
19 #define CLEAR_FRAME_AND_RETURN \
27 // Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.
28 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)
30 @ int __divsi3(int divident, int divisor)
31 @ Calculate and return the quotient of the (signed) division.
33 DEFINE_COMPILERRT_FUNCTION(__divsi3)
34 #if __ARM_ARCH_EXT_IDIV__
36 beq LOCAL_LABEL(divzero)
40 // Use movs for compatibility with v8-m.base.
45 // Set aside the sign of the quotient.
46 # if defined(USE_THUMB_1)
52 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
53 # if defined(USE_THUMB_1)
61 eor r2, r0, r0, asr #31
62 eor r3, r1, r1, asr #31
63 sub r0, r2, r0, asr #31
64 sub r1, r3, r1, asr #31
67 bl SYMBOL_NAME(__udivsi3)
68 // Apply sign of quotient to result and return.
69 # if defined(USE_THUMB_1)
74 eor r0, r0, r4, asr #31
75 sub r0, r0, r4, asr #31
77 CLEAR_FRAME_AND_RETURN
79 END_COMPILERRT_FUNCTION(__divsi3)
81 NO_EXEC_STACK_DIRECTIVE