Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/arm/divsi3.S
35291 views
//===-- divsi3.S - 32-bit signed integer divide ---------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the __divsi3 (32-bit signed integer divide) function9// for the ARM architecture as a wrapper around the unsigned routine.10//11//===----------------------------------------------------------------------===//1213#include "../assembly.h"1415#define ESTABLISH_FRAME \16push {r4, r7, lr} ;\17add r7, sp, #418#define CLEAR_FRAME_AND_RETURN \19pop {r4, r7, pc}2021.syntax unified22.text23DEFINE_CODE_STATE2425.p2align 326// Ok, APCS and AAPCS agree on 32 bit args, so it's safe to use the same routine.27DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_idiv, __divsi3)2829@ int __divsi3(int divident, int divisor)30@ Calculate and return the quotient of the (signed) division.3132DEFINE_COMPILERRT_FUNCTION(__divsi3)33#if __ARM_ARCH_EXT_IDIV__34tst r1,r135beq LOCAL_LABEL(divzero)36sdiv r0, r0, r137bx lr38LOCAL_LABEL(divzero):39// Use movs for compatibility with v8-m.base.40movs r0,#041bx lr42#else43ESTABLISH_FRAME44// Set aside the sign of the quotient.45# if defined(USE_THUMB_1)46movs r4, r047eors r4, r148# else49eor r4, r0, r150# endif51// Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).52# if defined(USE_THUMB_1)53asrs r2, r0, #3154asrs r3, r1, #3155eors r0, r256eors r1, r357subs r0, r0, r258subs r1, r1, r359# else60eor r2, r0, r0, asr #3161eor r3, r1, r1, asr #3162sub r0, r2, r0, asr #3163sub r1, r3, r1, asr #3164# endif65// abs(a) / abs(b)66bl SYMBOL_NAME(__udivsi3)67// Apply sign of quotient to result and return.68# if defined(USE_THUMB_1)69asrs r4, #3170eors r0, r471subs r0, r0, r472# else73eor r0, r0, r4, asr #3174sub r0, r0, r4, asr #3175# endif76CLEAR_FRAME_AND_RETURN77#endif78END_COMPILERRT_FUNCTION(__divsi3)7980NO_EXEC_STACK_DIRECTIVE81828384