Debian Codegraph @

mpn/x86_64/coreibwl/mul_basecase.asm

raw
1 dnl AMD64 mpn_mul_basecase optimised for Intel Broadwell.
2
3 dnl Copyright 2015 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 mul_1 addmul_1
34 C AMD K8,K9 n/a n/a
35 C AMD K10 n/a n/a
36 C AMD bd1 n/a n/a
37 C AMD bd2 n/a n/a
38 C AMD bd3 n/a n/a
39 C AMD bd4 ? ?
40 C AMD zen ? ?
41 C AMD bt1 n/a n/a
42 C AMD bt2 n/a n/a
43 C Intel P4 n/a n/a
44 C Intel PNR n/a n/a
45 C Intel NHM n/a n/a
46 C Intel SBR n/a n/a
47 C Intel IBR n/a n/a
48 C Intel HWL 1.68 n/a
49 C Intel BWL 1.51 1.67-1.74
50 C Intel SKL 1.52 1.63-1.71
51 C Intel atom n/a n/a
52 C Intel SLM n/a n/a
53 C VIA nano n/a n/a
54
55 C The inner loops of this code are the result of running a code generation and
56 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
57
58 C TODO
59 C * Do overlapped software pipelining.
60 C * When changing this, make sure the code which falls into the inner loops
61 C does not execute too many no-ops (for both PIC and non-PIC).
62
63 define(`rp', `%rdi')
64 define(`up', `%rsi')
65 define(`un_param',`%rdx')
66 define(`vp_param',`%rcx')
67 define(`vn', `%r8')
68
69 define(`n', `%rcx')
70 define(`n_save', `%rbp')
71 define(`vp', `%r14')
72 define(`unneg', `%rbx')
73 define(`v0', `%rdx')
74 define(`jaddr', `%rax')
75
76 define(`w0', `%r12')
77 define(`w1', `%r9')
78 define(`w2', `%r10')
79 define(`w3', `%r11')
80
81 ABI_SUPPORT(DOS64)
82 ABI_SUPPORT(STD64)
83
84 ASM_START()
85 TEXT
86 ALIGN(16)
87 PROLOGUE(mpn_mul_basecase)
88 FUNC_ENTRY(4)
89 IFDOS(` mov 56(%rsp), %r8d ')
90
91 cmp $2, un_param
92 ja L(gen)
93 mov (vp_param), %rdx
94 mulx( (up), %rax, %r9) C 0 1
95 je L(s2x)
96
97 L(s11): mov %rax, (rp)
98 mov %r9, 8(rp)
99 FUNC_EXIT()
100 ret
101
102 L(s2x): cmp $2, vn
103 mulx( 8,(up), %r8, %r10) C 1 2
104 je L(s22)
105
106 L(s21): add %r8, %r9
107 adc $0, %r10
108 mov %rax, (rp)
109 mov %r9, 8(rp)
110 mov %r10, 16(rp)
111 FUNC_EXIT()
112 ret
113
114 L(s22): add %r8, %r9 C 1
115 adc $0, %r10 C 2
116 mov 8(vp_param), %rdx
117 mov %rax, (rp)
118 mulx( (up), %r8, %r11) C 1 2
119 mulx( 8,(up), %rax, %rdx) C 2 3
120 add %r11, %rax C 2
121 adc $0, %rdx C 3
122 add %r8, %r9 C 1
123 adc %rax, %r10 C 2
124 adc $0, %rdx C 3
125 mov %r9, 8(rp)
126 mov %r10, 16(rp)
127 mov %rdx, 24(rp)
128 FUNC_EXIT()
129 ret
130
131 ALIGN(16)
132 L(gen):
133 push %rbx
134 push %rbp
135 push %r12
136 push %r14
137
138 mov vp_param, vp
139 lea 1(un_param), unneg
140 mov un_param, n_save
141 mov R32(un_param), R32(%rax)
142 and $-8, unneg
143 shr $3, n_save C loop count
144 neg unneg
145 and $7, R32(%rax) C clear CF for adc as side-effect
146 C note that rax lives very long
147 mov n_save, n
148 mov (vp), v0
149 lea 8(vp), vp
150
151 lea L(mtab)(%rip), %r10
152 ifdef(`PIC',
153 ` movslq (%r10,%rax,4), %r11
154 lea (%r11, %r10), %r10
155 jmp *%r10
156 ',`
157 jmp *(%r10,%rax,8)
158 ')
159
160 L(mf0): mulx( (up), w2, w3)
161 lea 56(up), up
162 lea -8(rp), rp
163 jmp L(mb0)
164
165 L(mf3): mulx( (up), w0, w1)
166 lea 16(up), up
167 lea 16(rp), rp
168 inc n
169 jmp L(mb3)
170
171 L(mf4): mulx( (up), w2, w3)
172 lea 24(up), up
173 lea 24(rp), rp
174 inc n
175 jmp L(mb4)
176
177 L(mf5): mulx( (up), w0, w1)
178 lea 32(up), up
179 lea 32(rp), rp
180 inc n
181 jmp L(mb5)
182
183 L(mf6): mulx( (up), w2, w3)
184 lea 40(up), up
185 lea 40(rp), rp
186 inc n
187 jmp L(mb6)
188
189 L(mf7): mulx( (up), w0, w1)
190 lea 48(up), up
191 lea 48(rp), rp
192 inc n
193 jmp L(mb7)
194
195 L(mf1): mulx( (up), w0, w1)
196 jmp L(mb1)
197
198 L(mf2): mulx( (up), w2, w3)
199 lea 8(up), up
200 lea 8(rp), rp
201 mulx( (up), w0, w1)
202
203 ALIGN(16)
204 L(m1top):
205 mov w2, -8(rp)
206 adc w3, w0
207 L(mb1): mulx( 8,(up), w2, w3)
208 adc w1, w2
209 lea 64(up), up
210 mov w0, (rp)
211 L(mb0): mov w2, 8(rp)
212 mulx( -48,(up), w0, w1)
213 lea 64(rp), rp
214 adc w3, w0
215 L(mb7): mulx( -40,(up), w2, w3)
216 mov w0, -48(rp)
217 adc w1, w2
218 L(mb6): mov w2, -40(rp)
219 mulx( -32,(up), w0, w1)
220 adc w3, w0
221 L(mb5): mulx( -24,(up), w2, w3)
222 mov w0, -32(rp)
223 adc w1, w2
224 L(mb4): mulx( -16,(up), w0, w1)
225 mov w2, -24(rp)
226 adc w3, w0
227 L(mb3): mulx( -8,(up), w2, w3)
228 adc w1, w2
229 mov w0, -16(rp)
230 dec n
231 mulx( (up), w0, w1)
232 jnz L(m1top)
233
234 L(m1end):
235 mov w2, -8(rp)
236 adc w3, w0
237 mov w0, (rp)
238 adc %rcx, w1 C relies on rcx = 0
239 mov w1, 8(rp)
240
241 dec vn
242 jz L(done)
243
244 lea L(atab)(%rip), %r10
245 ifdef(`PIC',
246 ` movslq (%r10,%rax,4), %rax
247 lea (%rax, %r10), jaddr
248 ',`
249 mov (%r10,%rax,8), jaddr
250 ')
251
252 L(outer):
253 lea (up,unneg,8), up
254 mov n_save, n
255 mov (vp), v0
256 lea 8(vp), vp
257 jmp *jaddr
258
259 L(f0): mulx( 8,(up), w2, w3)
260 lea 8(rp,unneg,8), rp
261 lea -1(n), n
262 jmp L(b0)
263
264 L(f3): mulx( -16,(up), w0, w1)
265 lea -56(rp,unneg,8), rp
266 jmp L(b3)
267
268 L(f4): mulx( -24,(up), w2, w3)
269 lea -56(rp,unneg,8), rp
270 jmp L(b4)
271
272 L(f5): mulx( -32,(up), w0, w1)
273 lea -56(rp,unneg,8), rp
274 jmp L(b5)
275
276 L(f6): mulx( -40,(up), w2, w3)
277 lea -56(rp,unneg,8), rp
278 jmp L(b6)
279
280 L(f7): mulx( 16,(up), w0, w1)
281 lea 8(rp,unneg,8), rp
282 jmp L(b7)
283
284 L(f1): mulx( (up), w0, w1)
285 lea 8(rp,unneg,8), rp
286 jmp L(b1)
287
288 L(am1end):
289 adox( (rp), w0)
290 adox( %rcx, w1) C relies on rcx = 0
291 mov w0, (rp)
292 adc %rcx, w1 C relies on rcx = 0
293 mov w1, 8(rp)
294
295 dec vn C clear OF as side-effect
296 jnz L(outer)
297 L(done):
298 pop %r14
299 pop %r12
300 pop %rbp
301 pop %rbx
302 FUNC_EXIT()
303 ret
304
305 L(f2): mulx( -8,(up), w2, w3)
306 lea 8(rp,unneg,8), rp
307 mulx( (up), w0, w1)
308
309 ALIGN(16)
310 L(am1top):
311 adox( -8,(rp), w2)
312 adcx( w3, w0)
313 mov w2, -8(rp)
314 jrcxz L(am1end)
315 L(b1): mulx( 8,(up), w2, w3)
316 adox( (rp), w0)
317 lea -1(n), n
318 mov w0, (rp)
319 adcx( w1, w2)
320 L(b0): mulx( 16,(up), w0, w1)
321 adcx( w3, w0)
322 adox( 8,(rp), w2)
323 mov w2, 8(rp)
324 L(b7): mulx( 24,(up), w2, w3)
325 lea 64(up), up
326 adcx( w1, w2)
327 adox( 16,(rp), w0)
328 mov w0, 16(rp)
329 L(b6): mulx( -32,(up), w0, w1)
330 adox( 24,(rp), w2)
331 adcx( w3, w0)
332 mov w2, 24(rp)
333 L(b5): mulx( -24,(up), w2, w3)
334 adcx( w1, w2)
335 adox( 32,(rp), w0)
336 mov w0, 32(rp)
337 L(b4): mulx( -16,(up), w0, w1)
338 adox( 40,(rp), w2)
339 adcx( w3, w0)
340 mov w2, 40(rp)
341 L(b3): adox( 48,(rp), w0)
342 mulx( -8,(up), w2, w3)
343 mov w0, 48(rp)
344 lea 64(rp), rp
345 adcx( w1, w2)
346 mulx( (up), w0, w1)
347 jmp L(am1top)
348
349 JUMPTABSECT
350 ALIGN(8)
351 L(mtab):JMPENT( L(mf0), L(mtab))
352 JMPENT( L(mf1), L(mtab))
353 JMPENT( L(mf2), L(mtab))
354 JMPENT( L(mf3), L(mtab))
355 JMPENT( L(mf4), L(mtab))
356 JMPENT( L(mf5), L(mtab))
357 JMPENT( L(mf6), L(mtab))
358 JMPENT( L(mf7), L(mtab))
359 L(atab):JMPENT( L(f0), L(atab))
360 JMPENT( L(f1), L(atab))
361 JMPENT( L(f2), L(atab))
362 JMPENT( L(f3), L(atab))
363 JMPENT( L(f4), L(atab))
364 JMPENT( L(f5), L(atab))
365 JMPENT( L(f6), L(atab))
366 JMPENT( L(f7), L(atab))
367 TEXT
368 EPILOGUE()