xref: /openbmc/linux/arch/hexagon/lib/modsi3.S (revision 63705da3)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
4 */
5
6#include <linux/linkage.h>
7
8SYM_FUNC_START(__hexagon_modsi3)
9        {
10                p2 = cmp.ge(r0,#0)
11                r2 = abs(r0)
12                r1 = abs(r1)
13        }
14        {
15                r3 = cl0(r2)
16                r4 = cl0(r1)
17                p0 = cmp.gtu(r1,r2)
18        }
19        {
20                r3 = sub(r4,r3)
21                if (p0) jumpr r31
22        }
23        {
24                p1 = cmp.eq(r3,#0)
25                loop0(1f,r3)
26                r0 = r2
27                r2 = lsl(r1,r3)
28        }
29        .falign
301:
31        {
32                p0 = cmp.gtu(r2,r0)
33                if (!p0.new) r0 = sub(r0,r2)
34                r2 = lsr(r2,#1)
35                if (p1) r1 = #0
36        }:endloop0
37        {
38                p0 = cmp.gtu(r2,r0)
39                if (!p0.new) r0 = sub(r0,r1)
40                if (p2) jumpr r31
41        }
42        {
43                r0 = neg(r0)
44                jumpr r31
45        }
46SYM_FUNC_END(__hexagon_modsi3)
47