Debian Codegraph @

mpn/x86_64/alderlake/mul_basecase.asm

raw
1 dnl AMD64 mpn_mul_basecase.
2
3 dnl Contributed to the GNU project by Torbjörn Granlund.
4
5 dnl Copyright 2012, 2013, 2022 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 AMD K8,K9 -
37 C AMD K10 -
38 C AMD bd1 -
39 C AMD bd2 -
40 C AMD bd3 -
41 C AMD bd4 -
42 C AMD zn1 ?
43 C AMD zn2 ?
44 C AMD zn3 ?
45 C AMD bt1 -
46 C AMD bt2 -
47 C Intel P4 -
48 C Intel CNR -
49 C Intel PNR -
50 C Intel NHM -
51 C Intel WSM -
52 C Intel SBR -
53 C Intel IBR -
54 C Intel HWL -
55 C Intel BWL ?
56 C Intel SKL ?
57 C Intel RKL ?
58 C Intel ALD 1.29
59 C Intel atom -
60 C Intel SLM -
61 C Intel GLM -
62 C VIA nano -
63
64 C TODO
65 C * Do overlapped software pipelining.
66 C * Try shallower pipeline, which would result in using fewer registers.
67 C * There are false dependencies on CF/OF between iterations. Try breaking
68 C them to see if it helps.
69
70 define(`rp', `%rdi') dnl rcx
71 define(`up', `%rsi') dnl rdx
72 define(`un_arg',`%rdx') dnl r8
73 define(`vp_arg',`%rcx') dnl r9
74 define(`vn_arg',`%r8') dnl stack
75
76 define(`un', `%r14')
77 define(`vp', `%r15')
78 define(`vn', `%rbp')
79
80 define(`n', `%rcx')
81 define(`v0', `%rdx')
82
83
84 ASM_START()
85 TEXT
86 ALIGN(16)
87 PROLOGUE(mpn_mul_basecase)
88 cmp $2, un_arg
89 ja L(gen)
90 mov (vp_arg), %rdx
91 mulx( (up), %rax, %r9)
92 mov %rax, (rp)
93 je L(s2x)
94
95 mov %r9, 8(rp)
96 ret
97
98 L(s2x): mulx( 8,(up), %rax, %r10)
99 add %r9, %rax
100 adc $0, %r10
101 cmp $2, R32(vn_arg)
102 je L(s22)
103
104 L(s21): mov %rax, 8(rp)
105 mov %r10, 16(rp)
106 ret
107
108 L(s22): mov 8(vp_arg), %rdx
109 mulx( (up), %r8, %r9)
110 add %r8, %rax
111 adc %r10, %r9
112 mov %rax, 8(rp)
113 mulx( 8,(up), %rax, %r10)
114 adc $0, %r10
115 adc %r9, %rax
116 mov %rax, 16(rp)
117 adc $0, %r10
118 mov %r10, 24(rp)
119 ret
120
121 L(gen): push %rbx
122 push %rbp
123 push %r12
124 push %r13
125 push %r14
126 push %r15
127
128 mov un_arg, un
129 neg un
130 shl $3, un
131 mov vp_arg, vp
132 mov vn_arg, vn
133
134 test $1, R8(un_arg)
135 mov (vp), %rdx
136 jz L(bx0)
137
138 L(bx1): test $16, R8(un)
139 jnz L(b01)
140
141 L(b11): lea 24(un), n
142 mulx( (up), %r11, %r10)
143 mulx( 8,(up), %r13, %r12)
144 mulx( 16,(up), %rbx, %rax)
145 lea 8(rp), rp
146 lea 24(up), up
147 jrcxz L(med3)
148 L(mtp3):mulx( (up), %r9, %r8)
149 adcx( %r10, %r13)
150 mov %r11, -8(rp)
151 mulx( 8,(up), %r11, %r10)
152 adcx( %r12, %rbx)
153 mov %r13, (rp)
154 mulx( 16,(up), %r13, %r12)
155 adcx( %rax, %r9)
156 mov %rbx, 8(rp)
157 mulx( 24,(up), %rbx, %rax)
158 adcx( %r8, %r11)
159 mov %r9, 16(rp)
160 lea 32(up), up
161 lea 32(rp), rp
162 lea 32(n), n
163 jrcxz L(med3)
164 jmp L(mtp3)
165 L(med3):adcx( %r10, %r13)
166 mov %r11, -8(rp)
167 adcx( %r12, %rbx)
168 mov %r13, (rp)
169 adcx( %rcx, %rax)
170 mov %rbx, 8(rp)
171 mov %rax, 16(rp)
172 dec vn
173 jz L(ret)
174 L(out3):lea 32(rp,un), rp
175 lea 24(up,un), up
176 lea 8(vp), vp
177 xor R32(%rdx), R32(%rdx)
178 mov (vp), %rdx
179 mulx( -24,(up), %r11, %r10)
180 mulx( -16,(up), %r13, %r12)
181 mulx( -8,(up), %rbx, %rax)
182 lea 24(un), n
183 adox( -8,(rp), %r11)
184 jrcxz L(ed3)
185 L(tp3): mulx( (up), %r9, %r8)
186 adcx( %r10, %r13)
187 mov %r11, -8(rp)
188 adox( (rp), %r13)
189 mulx( 8,(up), %r11, %r10)
190 adcx( %r12, %rbx)
191 mov %r13, (rp)
192 adox( 8,(rp), %rbx)
193 mulx( 16,(up), %r13, %r12)
194 adcx( %rax, %r9)
195 mov %rbx, 8(rp)
196 adox( 16,(rp), %r9)
197 mulx( 24,(up), %rbx, %rax)
198 adcx( %r8, %r11)
199 mov %r9, 16(rp)
200 adox( 24,(rp), %r11)
201 lea 32(up), up
202 lea 32(rp), rp
203 lea 32(n), n
204 jrcxz L(ed3)
205 jmp L(tp3)
206 L(ed3): adcx( %r10, %r13)
207 mov %r11, -8(rp)
208 adox( (rp), %r13)
209 adcx( %r12, %rbx)
210 mov %r13, (rp)
211 adox( 8,(rp), %rbx)
212 adcx( %rcx, %rax)
213 adox( %rcx, %rax)
214 mov %rbx, 8(rp)
215 mov %rax, 16(rp)
216 dec vn
217 jnz L(out3)
218 jmp L(ret)
219
220
221 L(b01): mulx( (up), %rbx, %rax)
222 lea 8(un), n
223 mulx( 8,(up), %r9, %r8)
224 mulx( 16,(up), %r11, %r10)
225 lea 8(up), up
226 lea -8(rp), rp
227 jmp L(ml1)
228 L(mtp1):mulx( (up), %r9, %r8)
229 adcx( %r10, %r13)
230 mov %r11, -8(rp)
231 mulx( 8,(up), %r11, %r10)
232 adcx( %r12, %rbx)
233 mov %r13, (rp)
234 L(ml1): mulx( 16,(up), %r13, %r12)
235 adcx( %rax, %r9)
236 mov %rbx, 8(rp)
237 mulx( 24,(up), %rbx, %rax)
238 adcx( %r8, %r11)
239 mov %r9, 16(rp)
240 lea 32(up), up
241 lea 32(rp), rp
242 lea 32(n), n
243 jrcxz L(med1)
244 jmp L(mtp1)
245 L(med1):adcx( %r10, %r13)
246 mov %r11, -8(rp)
247 adcx( %r12, %rbx)
248 mov %r13, (rp)
249 adcx( %rcx, %rax)
250 mov %rbx, 8(rp)
251 mov %rax, 16(rp)
252 dec vn
253 jz L(ret)
254 L(out1):lea 16(rp,un), rp
255 lea 8(up,un), up
256 lea 8(vp), vp
257 xor R32(%rdx), R32(%rdx)
258 mov (vp), %rdx
259 lea 8(un), n
260 mulx( -8,(up), %rbx, %rax)
261 mulx( (up), %r9, %r8)
262 mulx( 8,(up), %r11, %r10)
263 jmp L(lo1)
264 L(tp1): mulx( (up), %r9, %r8)
265 adcx( %r10, %r13)
266 mov %r11, -8(rp)
267 adox( (rp), %r13)
268 mulx( 8,(up), %r11, %r10)
269 adcx( %r12, %rbx)
270 mov %r13, (rp)
271 L(lo1): adox( 8,(rp), %rbx)
272 mulx( 16,(up), %r13, %r12)
273 adcx( %rax, %r9)
274 mov %rbx, 8(rp)
275 adox( 16,(rp), %r9)
276 mulx( 24,(up), %rbx, %rax)
277 adcx( %r8, %r11)
278 mov %r9, 16(rp)
279 adox( 24,(rp), %r11)
280 lea 32(up), up
281 lea 32(rp), rp
282 lea 32(n), n
283 jrcxz L(ed1)
284 jmp L(tp1)
285 L(ed1): adcx( %r10, %r13)
286 mov %r11, -8(rp)
287 adox( (rp), %r13)
288 adcx( %r12, %rbx)
289 mov %r13, (rp)
290 adox( 8,(rp), %rbx)
291 adcx( %rcx, %rax)
292 adox( %rcx, %rax)
293 mov %rbx, 8(rp)
294 mov %rax, 16(rp)
295 dec vn
296 jnz L(out1)
297 jmp L(ret)
298
299
300 L(bx0): test $16, R8(un)
301 jz L(b00)
302
303 L(b10): mulx( (up), %r13, %r12)
304 mulx( 8,(up), %rbx, %rax)
305 lea 16(un), n
306 mulx( 16,(up), %r9, %r8)
307 lea 16(up), up
308 jmp L(ml2)
309 L(mtp2):mulx( (up), %r9, %r8)
310 adcx( %r10, %r13)
311 mov %r11, -8(rp)
312 L(ml2): mulx( 8,(up), %r11, %r10)
313 adcx( %r12, %rbx)
314 mov %r13, (rp)
315 mulx( 16,(up), %r13, %r12)
316 adcx( %rax, %r9)
317 mov %rbx, 8(rp)
318 mulx( 24,(up), %rbx, %rax)
319 adcx( %r8, %r11)
320 mov %r9, 16(rp)
321 lea 32(up), up
322 lea 32(rp), rp
323 lea 32(n), n
324 jrcxz L(med2)
325 jmp L(mtp2)
326 L(med2):adcx( %r10, %r13)
327 mov %r11, -8(rp)
328 adcx( %r12, %rbx)
329 mov %r13, (rp)
330 adcx( %rcx, %rax)
331 mov %rbx, 8(rp)
332 mov %rax, 16(rp)
333 dec vn
334 jz L(ret)
335 L(out2):lea 24(rp,un), rp
336 lea 16(up,un), up
337 lea 8(vp), vp
338 xor R32(%rdx), R32(%rdx)
339 mov (vp), %rdx
340 mulx( -16,(up), %r13, %r12)
341 mulx( -8,(up), %rbx, %rax)
342 lea 16(un), n
343 mulx( (up), %r9, %r8)
344 jmp L(lo2)
345 L(tp2): mulx( (up), %r9, %r8)
346 adcx( %r10, %r13)
347 mov %r11, -8(rp)
348 L(lo2): adox( (rp), %r13)
349 mulx( 8,(up), %r11, %r10)
350 adcx( %r12, %rbx)
351 mov %r13, (rp)
352 adox( 8,(rp), %rbx)
353 mulx( 16,(up), %r13, %r12)
354 adcx( %rax, %r9)
355 mov %rbx, 8(rp)
356 adox( 16,(rp), %r9)
357 mulx( 24,(up), %rbx, %rax)
358 adcx( %r8, %r11)
359 mov %r9, 16(rp)
360 adox( 24,(rp), %r11)
361 lea 32(up), up
362 lea 32(rp), rp
363 lea 32(n), n
364 jrcxz L(ed2)
365 jmp L(tp2)
366 L(ed2): adcx( %r10, %r13)
367 mov %r11, -8(rp)
368 adox( (rp), %r13)
369 adcx( %r12, %rbx)
370 mov %r13, (rp)
371 adox( 8,(rp), %rbx)
372 adcx( %rcx, %rax)
373 adox( %rcx, %rax)
374 mov %rbx, 8(rp)
375 mov %rax, 16(rp)
376 dec vn
377 jnz L(out2)
378 jmp L(ret)
379
380
381 L(b00): lea 32(un), n
382 mulx( (up), %r9, %r8)
383 mulx( 8,(up), %r11, %r10)
384 mulx( 16,(up), %r13, %r12)
385 mulx( 24,(up), %rbx, %rax)
386 adcx( %r8, %r11)
387 mov %r9, (rp)
388 lea 32(up), up
389 lea 16(rp), rp
390 jrcxz L(med0)
391 L(mtp0):mulx( (up), %r9, %r8)
392 adcx( %r10, %r13)
393 mov %r11, -8(rp)
394 mulx( 8,(up), %r11, %r10)
395 adcx( %r12, %rbx)
396 mov %r13, (rp)
397 mulx( 16,(up), %r13, %r12)
398 adcx( %rax, %r9)
399 mov %rbx, 8(rp)
400 mulx( 24,(up), %rbx, %rax)
401 adcx( %r8, %r11)
402 mov %r9, 16(rp)
403 lea 32(up), up
404 lea 32(rp), rp
405 lea 32(n), n
406 jrcxz L(med0)
407 jmp L(mtp0)
408 L(med0):adcx( %r10, %r13)
409 mov %r11, -8(rp)
410 adcx( %r12, %rbx)
411 mov %r13, (rp)
412 adcx( %rcx, %rax)
413 mov %rbx, 8(rp)
414 mov %rax, 16(rp)
415 dec vn
416 jz L(ret)
417 L(out0):lea 40(rp,un), rp
418 lea 32(up,un), up
419 lea 8(vp), vp
420 xor R32(%rdx), R32(%rdx)
421 mov (vp), %rdx
422 lea 32(un), n
423 mulx( -32,(up), %r9, %r8)
424 mulx( -24,(up), %r11, %r10)
425 mulx( -16,(up), %r13, %r12)
426 adox( -16,(rp), %r9)
427 mulx( -8,(up), %rbx, %rax)
428 adcx( %r8, %r11)
429 mov %r9, -16(rp)
430 adox( -8,(rp), %r11)
431 jrcxz L(ed0)
432 L(tp0): mulx( (up), %r9, %r8)
433 adcx( %r10, %r13)
434 mov %r11, -8(rp)
435 adox( (rp), %r13)
436 mulx( 8,(up), %r11, %r10)
437 adcx( %r12, %rbx)
438 mov %r13, (rp)
439 adox( 8,(rp), %rbx)
440 mulx( 16,(up), %r13, %r12)
441 adcx( %rax, %r9)
442 mov %rbx, 8(rp)
443 adox( 16,(rp), %r9)
444 mulx( 24,(up), %rbx, %rax)
445 adcx( %r8, %r11)
446 mov %r9, 16(rp)
447 adox( 24,(rp), %r11)
448 lea 32(up), up
449 lea 32(rp), rp
450 lea 32(n), n
451 jrcxz L(ed0)
452 jmp L(tp0)
453 L(ed0): adcx( %r10, %r13)
454 mov %r11, -8(rp)
455 adox( (rp), %r13)
456 adcx( %r12, %rbx)
457 mov %r13, (rp)
458 adox( 8,(rp), %rbx)
459 adcx( %rcx, %rax)
460 adox( %rcx, %rax)
461 mov %rbx, 8(rp)
462 mov %rax, 16(rp)
463 dec vn
464 jnz L(out0)
465
466 L(ret): pop %r15
467 pop %r14
468 pop %r13
469 pop %r12
470 pop %rbp
471 pop %rbx
472 ret
473 EPILOGUE()
474 ASM_END()