Debian Codegraph @

mpn/arm64/applem1/aorsmul_1.asm

raw
1 dnl ARM64 mpn_addmul_1 and mpn_submul_1.
2
3 dnl Contributed to the GNU project by Torbjörn Granlund.
4
5 dnl Copyright 2020 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 cycles/limb
36 C Cortex-A53
37 C Cortex-A55
38 C Cortex-A57
39 C Cortex-A72
40 C Cortex-A73
41 C X-Gene
42 C Apple M1 1.25
43
44 changecom(blah)
45
46 define(`rp', x0)
47 define(`up', x1)
48 define(`n', x2)
49 define(`v0', x3)
50 define(`cin',x4)
51
52 define(`CY',x17)
53
54 ifdef(`OPERATION_addmul_1', `
55 define(`ADDSUB', adds)
56 define(`ADDSUBC', adcs)
57 define(`COND', `cc')
58 define(`func', mpn_addmul_1)')
59 ifdef(`OPERATION_submul_1', `
60 define(`ADDSUB', subs)
61 define(`ADDSUBC', sbcs)
62 define(`COND', `cs')
63 define(`func', mpn_submul_1)')
64
65 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1 mpn_addmul_1c)
66
67 ifdef(`OPERATION_addmul_1', `
68 PROLOGUE(mpn_addmul_1c)
69 mov CY, cin
70 b L(ent)
71 EPILOGUE()
72 ')
73
74 PROLOGUE(func)
75 mov CY, #0 C W0
76 L(ent): lsr x16, n, #2
77 tbz n, #0, L(bx0)
78
79 L(bx1): ldr x4, [up], #8
80 mul x8, x4, v0
81 umulh x4, x4, v0
82 tbz n, #1, L(b01)
83
84 L(b11): ldp x5,x6, [up], #16
85 ldp x12,x13, [rp]
86 ldr x14, [rp,#16]
87 mul x9, x5, v0
88 umulh x5, x5, v0
89 mul x10, x6, v0
90 umulh x6, x6, v0
91 ADDSUB x8, x12, x8
92 ADDSUBC x4, x13, x4
93 ADDSUBC x5, x14, x5
94 csinc x6, x6, x6, COND
95 ADDSUB x8, x8, CY
96 ADDSUBC x4, x4, x9
97 ADDSUBC x5, x5, x10
98 csinc CY, x6, x6, COND
99 stp x8, x4, [rp], #16
100 str x5, [rp], #8
101 cbnz x16, L(top)
102 mov x0, CY
103 ret
104
105 L(b01): ldr x12, [rp]
106 ADDSUB x8, x12, x8
107 csinc x4, x4, x4, COND
108 ADDSUB x8, x8, CY
109 csinc CY, x4, x4, COND
110 str x8, [rp], #8
111 cbnz x16, L(top)
112 mov x0, CY
113 ret
114
115 L(bx0): ldp x4,x5, [up], #16
116 tbz n, #1, L(top)+4
117
118 L(b10): ldp x12,x13, [rp]
119 mul x8, x4, v0
120 umulh x4, x4, v0
121 mul x9, x5, v0
122 umulh x5, x5, v0
123 ADDSUB x8, x12, x8
124 ADDSUBC x4, x13, x4
125 csinc x5, x5, x5, COND
126 ADDSUB x8, x8, CY
127 ADDSUBC x4, x4, x9
128 csinc CY, x5, x5, COND
129 stp x8, x4, [rp], #16
130 cbz x16, L(done)
131
132 L(top): ldp x4,x5, [up], #16 C W0 W1
133 ldp x6,x7, [up], #16 C W2 W3
134 ldp x12,x13, [rp] C W0 W1
135 ldp x14,x15, [rp,#16] C W2 W3
136 mul x8, x4, v0 C W0
137 umulh x4, x4, v0 C W1
138 mul x9, x5, v0 C W1
139 umulh x5, x5, v0 C W2
140 mul x10, x6, v0 C W2
141 umulh x6, x6, v0 C W3
142 mul x11, x7, v0 C W3
143 umulh x7, x7, v0 C W4
144 ADDSUB x8, x12, x8 C W0
145 ADDSUBC x4, x13, x4 C W1
146 ADDSUBC x5, x14, x5 C W2
147 ADDSUBC x6, x15, x6 C W3
148 csinc x7, x7, x7, COND C W4
149 ADDSUB x8, x8, CY C W0 carry-in
150 ADDSUBC x4, x4, x9 C W1
151 ADDSUBC x5, x5, x10 C W2
152 ADDSUBC x6, x6, x11 C W2
153 csinc CY, x7, x7, COND C W3 carry-out
154 stp x8, x4, [rp], #16
155 stp x5, x6, [rp], #16
156 sub x16, x16, #1
157 cbnz x16, L(top)
158
159 L(done):mov x0, CY
160 ret
161 EPILOGUE()