Debian Codegraph @

mpn/x86_64/coreihwl/mul_1.asm

raw
1 dnl AMD64 mpn_mul_1 using mulx optimised for Intel Haswell.
2
3 dnl Contributed to the GNU project by Torbjörn Granlund.
4
5 dnl Copyright 2012, 2013 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 bull -
39 C AMD pile -
40 C AMD steam -
41 C AMD excavator -
42 C AMD bobcat -
43 C AMD jaguar -
44 C Intel P4 -
45 C Intel core2 -
46 C Intel NHM -
47 C Intel SBR -
48 C Intel IBR -
49 C Intel HWL 1.59
50 C Intel BWL 1.76
51 C Intel SKL 1.54
52 C Intel atom -
53 C Intel SLM -
54 C VIA nano -
55
56 C The loop of this code is the result of running a code generation and
57 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
58
59 define(`rp', `%rdi') C rcx
60 define(`up', `%rsi') C rdx
61 define(`n_param', `%rdx') C r8
62 define(`v0_param',`%rcx') C r9
63
64 define(`n', `%rbp')
65 define(`v0', `%rdx')
66
67 ABI_SUPPORT(DOS64)
68 ABI_SUPPORT(STD64)
69
70 ASM_START()
71 TEXT
72 ALIGN(32)
73 PROLOGUE(mpn_mul_1)
74 FUNC_ENTRY(4)
75 push %rbx
76 push %rbp
77 push %r12
78
79 mov n_param, n
80 shr $2, n
81
82 test $1, R8(n_param)
83 jnz L(bx1)
84
85 L(bx0): test $2, R8(n_param)
86 mov v0_param, v0
87 jnz L(b10)
88
89 L(b00): mulx( (up), %r9, %r8)
90 mulx( 8,(up), %r11, %r10)
91 mulx( 16,(up), %rcx, %r12)
92 lea -32(rp), rp
93 jmp L(lo0)
94
95 L(b10): mulx( (up), %rcx, %r12)
96 mulx( 8,(up), %rbx, %rax)
97 lea -16(rp), rp
98 test n, n
99 jz L(cj2)
100 mulx( 16,(up), %r9, %r8)
101 lea 16(up), up
102 jmp L(lo2)
103
104 L(bx1): test $2, R8(n_param)
105 mov v0_param, v0
106 jnz L(b11)
107
108 L(b01): mulx( (up), %rbx, %rax)
109 lea -24(rp), rp
110 test n, n
111 jz L(cj1)
112 mulx( 8,(up), %r9, %r8)
113 lea 8(up), up
114 jmp L(lo1)
115
116 L(b11): mulx( (up), %r11, %r10)
117 mulx( 8,(up), %rcx, %r12)
118 mulx( 16,(up), %rbx, %rax)
119 lea -8(rp), rp
120 test n, n
121 jz L(cj3)
122 lea 24(up), up
123 jmp L(lo3)
124
125 ALIGN(32)
126 L(top): lea 32(rp), rp
127 mov %r9, (rp)
128 adc %r8, %r11
129 L(lo3): mulx( (up), %r9, %r8)
130 mov %r11, 8(rp)
131 adc %r10, %rcx
132 L(lo2): mov %rcx, 16(rp)
133 adc %r12, %rbx
134 L(lo1): mulx( 8,(up), %r11, %r10)
135 adc %rax, %r9
136 mulx( 16,(up), %rcx, %r12)
137 mov %rbx, 24(rp)
138 L(lo0): mulx( 24,(up), %rbx, %rax)
139 lea 32(up), up
140 dec n
141 jnz L(top)
142
143 L(end): lea 32(rp), rp
144 mov %r9, (rp)
145 adc %r8, %r11
146 L(cj3): mov %r11, 8(rp)
147 adc %r10, %rcx
148 L(cj2): mov %rcx, 16(rp)
149 adc %r12, %rbx
150 L(cj1): mov %rbx, 24(rp)
151 adc $0, %rax
152
153 pop %r12
154 pop %rbp
155 pop %rbx
156 FUNC_EXIT()
157 ret
158 EPILOGUE()
159 ASM_END()