60 lines · plain
1//===-- modsi3.S - 32-bit signed integer modulus --------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the __modsi3 (32-bit signed integer modulus) function10// for the ARM architecture as a wrapper around the unsigned routine.11//12//===----------------------------------------------------------------------===//13 14#include "../assembly.h"15 16#define ESTABLISH_FRAME \17 push {r4, r7, lr} ;\18 add r7, sp, #419#define CLEAR_FRAME_AND_RETURN \20 pop {r4, r7, pc}21 22 .syntax unified23 .text24 DEFINE_CODE_STATE25 26@ int __modsi3(int divident, int divisor)27@ Calculate and return the remainder of the (signed) division.28 29 .p2align 330DEFINE_COMPILERRT_FUNCTION(__modsi3)31#if __ARM_ARCH_EXT_IDIV__32 tst r1, r133 beq LOCAL_LABEL(divzero)34 sdiv r2, r0, r135 mls r0, r2, r1, r036 bx lr37LOCAL_LABEL(divzero):38 mov r0, #039 bx lr40#else41 ESTABLISH_FRAME42 // Set aside the sign of the dividend.43 mov r4, r044 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).45 eor r2, r0, r0, asr #3146 eor r3, r1, r1, asr #3147 sub r0, r2, r0, asr #3148 sub r1, r3, r1, asr #3149 // abs(a) % abs(b)50 bl SYMBOL_NAME(__umodsi3)51 // Apply sign of dividend to result and return.52 eor r0, r0, r4, asr #3153 sub r0, r0, r4, asr #3154 CLEAR_FRAME_AND_RETURN55#endif56END_COMPILERRT_FUNCTION(__modsi3)57 58NO_EXEC_STACK_DIRECTIVE59 60