Debian Codegraph @

mpn/loongarch/64/aorsmul_1.asm

raw
1 dnl Loongarch mpn_addmul_1 and mpn_submul_1
2
3 dnl Contributed to the GNU project by Torbjorn Granlund.
4
5 dnl Copyright 2023 Free Software Foundation, Inc.
6
7 dnl This file is part of the GNU MP Library.
8 dnl
9 dnl The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl it under the terms of either:
11 dnl
12 dnl * the GNU Lesser General Public License as published by the Free
13 dnl Software Foundation; either version 3 of the License, or (at your
14 dnl option) any later version.
15 dnl
16 dnl or
17 dnl
18 dnl * the GNU General Public License as published by the Free Software
19 dnl Foundation; either version 2 of the License, or (at your option) any
20 dnl later version.
21 dnl
22 dnl or both in parallel, as here.
23 dnl
24 dnl The GNU MP Library is distributed in the hope that it will be useful, but
25 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 dnl for more details.
28 dnl
29 dnl You should have received copies of the GNU General Public License and the
30 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
31 dnl see https://www.gnu.org/licenses/.
32
33 include(`../config.m4')
34
35 C INPUT PARAMETERS
36 define(`rp', `$a0')
37 define(`ap', `$a1')
38 define(`n', `$a2')
39 define(`b0', `$a3')
40
41 define(`cy', `$a4')
42 define(`i', `$a5')
43
44 ifdef(`OPERATION_addmul_1',`
45 define(`ADDSUB', `add.d')
46 define(`CMPCY', `sltu $1, $2, $3')
47 define(`func', `mpn_addmul_1')
48 ')
49 ifdef(`OPERATION_submul_1',`
50 define(`ADDSUB', `sub.d')
51 define(`CMPCY', `sltu $1, $3, $2')
52 define(`func', `mpn_submul_1')
53 ')
54
55 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_addmul_1c mpn_submul_1)
56
57 define(`BLOCK', `
58 mul.d $t1, $t2, b0
59 mulh.du $t0, $t2, b0
60 ld.d $t2, ap, $1
61 ADDSUB $t5, $t3, $t1
62 CMPCY( $t4, $t5, $t3)
63 ld.d $t3, rp, $1
64 ADDSUB $t6, $t5, cy
65 add.d $t4, $t4, $t0
66 CMPCY( $t5, $t6, $t5)
67 st.d $t6, rp, eval($1-8)
68 add.d cy, $t4, $t5')
69
70 ASM_START()
71
72 ifdef(`OPERATION_addmul_1', `
73 PROLOGUE(mpn_addmul_1c)
74 srli.d i, n, 2
75 b L(ent)
76 EPILOGUE()
77 ')
78
79 PROLOGUE(func)
80 srli.d i, n, 2
81 or cy, $r0, $r0
82 L(ent): ld.d $t2, ap, 0
83 ld.d $t3, rp, 0
84
85 andi $t0, n, 1
86 andi $t1, n, 2
87 bnez $t0, L(bx1)
88 L(bx0): beqz $t1, L(b0)
89 L(b10): addi.d ap, ap, -16
90 addi.d rp, rp, -16
91 b L(b2)
92 L(bx1): beqz $t1, L(b01)
93 L(b11): addi.d ap, ap, -8
94 addi.d rp, rp, -8
95 b L(b3)
96 L(b01): addi.d ap, ap, 8
97 addi.d rp, rp, 8
98 beqz i, L(end)
99
100 L(top):
101 L(b1): BLOCK(0)
102 L(b0): BLOCK(8)
103 addi.d i, i, -1
104 L(b3): BLOCK(16)
105 L(b2): BLOCK(24)
106 addi.d ap, ap, 32
107 addi.d rp, rp, 32
108 bnez i, L(top)
109
110 L(end): mul.d $t1, $t2, b0
111 mulh.du $t0, $t2, b0
112 ADDSUB $t5, $t3, $t1
113 CMPCY( $t4, $t5, $t3)
114 ADDSUB $t6, $t5, cy
115 add.d $t4, $t4, $t0
116 CMPCY( $t5, $t6, $t5)
117 st.d $t6, rp, -8
118 add.d $a0, $t4, $t5
119 jr $r1
120 EPILOGUE()