xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_idivmod.S (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1//===-- aeabi_idivmod.S - EABI idivmod implementation ---------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "../assembly.h"
10
11// struct { int quot, int rem} __aeabi_idivmod(int numerator, int denominator) {
12//   int rem, quot;
13//   quot = __divmodsi4(numerator, denominator, &rem);
14//   return {quot, rem};
15// }
16
17#if defined(__MINGW32__)
18#define __aeabi_idivmod __rt_sdiv
19#endif
20
21        .syntax unified
22        .text
23        DEFINE_CODE_STATE
24        .p2align 2
25DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
26#if defined(USE_THUMB_1)
27        push    {r0, r1, lr}
28        bl      SYMBOL_NAME(__divsi3)
29        pop     {r1, r2, r3} // now r0 = quot, r1 = num, r2 = denom
30        muls    r2, r0, r2   // r2 = quot * denom
31        subs    r1, r1, r2
32        JMP     (r3)
33#else  // defined(USE_THUMB_1)
34        push    { lr }
35        sub     sp, sp, #4
36        mov     r2, sp
37#if defined(__MINGW32__)
38        mov     r3, r0
39        mov     r0, r1
40        mov     r1, r3
41#endif
42        bl      SYMBOL_NAME(__divmodsi4)
43        ldr     r1, [sp]
44        add     sp, sp, #4
45        pop     { pc }
46#endif //  defined(USE_THUMB_1)
47END_COMPILERRT_FUNCTION(__aeabi_idivmod)
48
49NO_EXEC_STACK_DIRECTIVE
50
51