Debian Codegraph @

mpn/x86_64/bd1/addmul_2.asm

raw
1 dnl AMD64 mpn_addmul_2 optimised for AMD Bulldozer.
2
3 dnl Copyright 2017 Free Software Foundation, Inc.
4
5 dnl This file is part of the GNU MP Library.
6 dnl
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of either:
9 dnl
10 dnl * the GNU Lesser General Public License as published by the Free
11 dnl Software Foundation; either version 3 of the License, or (at your
12 dnl option) any later version.
13 dnl
14 dnl or
15 dnl
16 dnl * the GNU General Public License as published by the Free Software
17 dnl Foundation; either version 2 of the License, or (at your option) any
18 dnl later version.
19 dnl
20 dnl or both in parallel, as here.
21 dnl
22 dnl The GNU MP Library is distributed in the hope that it will be useful, but
23 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 dnl for more details.
26 dnl
27 dnl You should have received copies of the GNU General Public License and the
28 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29 dnl see https://www.gnu.org/licenses/.
30
31 include(`../config.m4')
32
33 C cycles/limb
34 C AMD K8,K9
35 C AMD K10
36 C AMD bd1 4.2
37 C AMD bd2 4.4
38 C AMD bd3
39 C AMD bd4
40 C AMD zen
41 C AMD bt1
42 C AMD bt2
43 C Intel P4
44 C Intel PNR
45 C Intel NHM
46 C Intel SBR
47 C Intel IBR
48 C Intel HWL
49 C Intel BWL
50 C Intel SKL
51 C Intel atom
52 C Intel SLM
53 C VIA nano
54
55 C The loop of this code is the result of running a code generation and
56 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
57
58 define(`rp', `%rdi') C rcx
59 define(`up', `%rsi') C rdx
60 define(`n_param', `%rdx') C r8
61 define(`vp', `%rcx') C r9
62
63 define(`n', `%rcx')
64 define(`v0', `%rbx')
65 define(`v1', `%rbp')
66 define(`X0', `%r12')
67 define(`X1', `%r13')
68
69 define(`w0', `%r8')
70 define(`w1', `%r9')
71 define(`w2', `%r10')
72 define(`w3', `%r11')
73
74 ABI_SUPPORT(DOS64)
75 ABI_SUPPORT(STD64)
76
77 ASM_START()
78 TEXT
79 ALIGN(32)
80 PROLOGUE(mpn_addmul_2)
81 FUNC_ENTRY(4)
82 push %rbx
83 push %rbp
84 push %r12
85 push %r13
86
87 mov (vp), v0
88 mov 8(vp), v1
89
90 mov (up), %rax
91 mov $0, R32(w2) C abuse w2
92
93 lea (up,n_param,8), up
94 lea (rp,n_param,8), rp
95 sub n_param, w2
96 mul v0
97
98 test $1, R8(w2)
99 jnz L(bx1)
100
101 L(bx0): mov %rdx, X0
102 mov %rax, X1
103 test $2, R8(w2)
104 jnz L(b10)
105
106 L(b00): lea (w2), n C un = 4, 8, 12, ...
107 mov (up,w2,8), %rax
108 mov (rp,w2,8), w3
109 mul v1
110 mov %rax, w0
111 mov 8(up,w2,8), %rax
112 mov %rdx, w1
113 jmp L(lo0)
114
115 L(b10): lea 2(w2), n C un = 2, 6, 10, ...
116 mov (up,w2,8), %rax
117 mov (rp,w2,8), w1
118 mul v1
119 mov %rdx, w3
120 mov %rax, w2
121 mov -8(up,n,8), %rax
122 test n, n
123 jz L(end)
124 jmp L(top)
125
126 L(bx1): mov %rax, X0
127 mov %rdx, X1
128 test $2, R8(w2)
129 jz L(b11)
130
131 L(b01): lea 1(w2), n C un = 1, 5, 9, ...
132 mov (up,w2,8), %rax
133 mul v1
134 mov (rp,w2,8), w2
135 mov %rdx, w0
136 mov %rax, w3
137 jmp L(lo1)
138
139 L(b11): lea -1(w2), n C un = 3, 7, 11, ...
140 mov (up,w2,8), %rax
141 mul v1
142 mov (rp,w2,8), w0
143 mov %rax, w1
144 mov 8(up,w2,8), %rax
145 mov %rdx, w2
146 jmp L(lo3)
147
148 ALIGN(32)
149 L(top):
150 L(lo2): mul v0
151 add w1, X1
152 mov X1, -16(rp,n,8)
153 mov %rdx, X1
154 adc %rax, X0
155 adc $0, X1
156 mov -8(up,n,8), %rax
157 mul v1
158 mov -8(rp,n,8), w1
159 mov %rdx, w0
160 add w1, w2
161 adc %rax, w3
162 adc $0, w0
163 L(lo1): mov (up,n,8), %rax
164 mul v0
165 add w2, X0
166 mov X0, -8(rp,n,8)
167 mov %rdx, X0
168 adc %rax, X1
169 mov (up,n,8), %rax
170 adc $0, X0
171 mov (rp,n,8), w2
172 mul v1
173 add w2, w3
174 adc %rax, w0
175 mov 8(up,n,8), %rax
176 mov %rdx, w1
177 adc $0, w1
178 L(lo0): mul v0
179 add w3, X1
180 mov X1, (rp,n,8)
181 adc %rax, X0
182 mov 8(up,n,8), %rax
183 mov %rdx, X1
184 adc $0, X1
185 mov 8(rp,n,8), w3
186 mul v1
187 add w3, w0
188 adc %rax, w1
189 mov 16(up,n,8), %rax
190 mov %rdx, w2
191 adc $0, w2
192 L(lo3): mul v0
193 add w0, X0
194 mov X0, 8(rp,n,8)
195 mov %rdx, X0
196 adc %rax, X1
197 adc $0, X0
198 mov 16(up,n,8), %rax
199 mov 16(rp,n,8), w0
200 mul v1
201 mov %rdx, w3
202 add w0, w1
203 adc %rax, w2
204 adc $0, w3
205 mov 24(up,n,8), %rax
206 add $4, n
207 jnc L(top)
208
209 L(end): mul v0
210 add w1, X1
211 mov X1, -16(rp)
212 mov %rdx, X1
213 adc %rax, X0
214 adc $0, X1
215 mov -8(up), %rax
216 mul v1
217 mov -8(rp), w1
218 add w1, w2
219 adc %rax, w3
220 adc $0, %rdx
221 add w2, X0
222 adc $0, X1
223 mov X0, -8(rp)
224 add w3, X1
225 mov X1, (rp)
226 adc $0, %rdx
227 mov %rdx, %rax
228
229 pop %r13
230 pop %r12
231 pop %rbp
232 pop %rbx
233 FUNC_EXIT()
234 ret
235 EPILOGUE()