1//===-------- modsi3.S - Implement modsi3 ---------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===//
| 1/*===-- modsi3.S - 32-bit signed integer modulus --------------------------===// 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 __modsi3 (32-bit signed integer modulus) function 11 * for the ARM architecture as a wrapper around the unsigned routine. 12 * 13 *===----------------------------------------------------------------------===*/
|
9 10#include "../assembly.h" 11
| 14 15#include "../assembly.h" 16
|
12// 13// extern int32_t __modsi3(int32_t a, int32_t b); 14// 15// Returns the remainder when dividing two 32-bit signed integers. 16// Conceptually, the function is: { return a - (a / b) * b; } 17// But if you write that in C, llvm compiles it to a call to __modsi3... 18// 19 .align 2 20DEFINE_COMPILERRT_FUNCTION(__modsi3) 21 push {r4, r5, r7, lr} 22 add r7, sp, #8 // set stack frame 23 mov r5, r0 // save a 24 mov r4, r1 // save b 25 bl ___divsi3 // compute a/b 26#if __ARM_ARCH_7A__ 27 mls r0, r4, r0, r5 // mulitple result * b and subtract from a 28#else 29 // before armv7, does not have "mls" instruction 30 mul r3, r0, r4 // multiple result * b 31 sub r0, r5, r3 // a - result 32#endif 33 pop {r4, r5, r7, pc} 34
| 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}
|
35
| 22
|
36
| 23.syntax unified 24.align 3 25DEFINE_COMPILERRT_FUNCTION(__modsi3) 26 ESTABLISH_FRAME 27 // Set aside the sign of the dividend. 28 mov r4, r0 29 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). 30 eor r2, r0, r0, asr #31 31 eor r3, r1, r1, asr #31 32 sub r0, r2, r0, asr #31 33 sub r1, r3, r1, asr #31 34 // abs(a) % abs(b) 35 bl SYMBOL_NAME(__umodsi3) 36 // Apply sign of dividend to result and return. 37 eor r0, r0, r4, asr #31 38 sub r0, r0, r4, asr #31 39 CLEAR_FRAME_AND_RETURN
|
| |