Debian Codegraph @

mpn/x86_64/zen3/mul_1.asm

raw
1 dnl AMD64 mpn_mul_1 optimised for Intel Broadwell.
2
3 dnl Copyright 2015, 2017, 2020 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 n/a
35 C AMD K10 n/a
36 C AMD bd1 n/a
37 C AMD bd2 n/a
38 C AMD bd3 n/a
39 C AMD bd4 ?
40 C AMD zn1 ?
41 C AMD zn2 1.6
42 C AMD zn3 1.5
43 C AMD bt1 n/a
44 C AMD bt2 n/a
45 C Intel P4 n/a
46 C Intel PNR n/a
47 C Intel NHM n/a
48 C Intel WSM n/a
49 C Intel SBR n/a
50 C Intel IBR n/a
51 C Intel HWL n/a
52 C Intel BWL ?
53 C Intel SKL ?
54 C Intel atom n/a
55 C Intel SLM n/a
56 C Intel GLM n/a
57 C VIA nano n/a
58
59 C The loop of this code is the result of running a code generation and
60 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
61
62 C TODO
63 C * Put an initial mulx before switching, targeting some free registers.
64 C * Tune feed-in code.
65
66 define(`rp', `%rdi') C rcx
67 define(`up', `%rsi') C rdx
68 define(`n_param', `%rdx') C r8
69 define(`v0_param',`%rcx') C r9
70 define(`ci', `%r8') C stack
71
72 define(`n', `%rcx')
73
74 ABI_SUPPORT(DOS64)
75 ABI_SUPPORT(STD64)
76
77 dnl IFDOS(` define(`up', ``%rsi'') ') dnl
78 dnl IFDOS(` define(`rp', ``%rcx'') ') dnl
79 dnl IFDOS(` define(`vl', ``%r9'') ') dnl
80 dnl IFDOS(` define(`r9', ``rdi'') ') dnl
81 dnl IFDOS(` define(`n', ``%r8'') ') dnl
82 dnl IFDOS(` define(`r8', ``r11'') ') dnl
83
84 ASM_START()
85 TEXT
86 ALIGN(32)
87 PROLOGUE(mpn_mul_1c)
88 FUNC_ENTRY(4)
89 IFDOS(` mov 56(%rsp), %r11 ')
90 IFSTD(` mov %r8, %r11 ')
91 jmp L(com)
92 EPILOGUE()
93
94 PROLOGUE(mpn_mul_1)
95 FUNC_ENTRY(4)
96 xor R32(%r11), R32(%r11)
97 L(com):
98 mov v0_param, %r10
99 mov n_param, n
100 mov R32(n_param), R32(%rax)
101 shr $3, n
102 and $7, R32(%rax) C clear OF, CF as side-effect
103 mov %r10, %rdx
104 lea L(tab)(%rip), %r10
105 ifdef(`PIC',
106 ` movslq (%r10,%rax,4), %rax
107 lea (%rax, %r10), %r10
108 jmp *%r10
109 ',`
110 jmp *(%r10,%rax,8)
111 ')
112 JUMPTABSECT
113 ALIGN(8)
114 L(tab): JMPENT( L(f0), L(tab))
115 JMPENT( L(f1), L(tab))
116 JMPENT( L(f2), L(tab))
117 JMPENT( L(f3), L(tab))
118 JMPENT( L(f4), L(tab))
119 JMPENT( L(f5), L(tab))
120 JMPENT( L(f6), L(tab))
121 JMPENT( L(f7), L(tab))
122 TEXT
123
124 L(f0): mulx( (up), %r10, %r8)
125 lea -8(up), up
126 lea -8(rp), rp
127 lea -1(n), n
128 adc %r11, %r10
129 jmp L(b0)
130
131 L(f3): mulx( (up), %r9, %rax)
132 lea 16(up), up
133 lea -48(rp), rp
134 adc %r11, %r9
135 jmp L(b3)
136
137 L(f4): mulx( (up), %r10, %r8)
138 lea 24(up), up
139 lea -40(rp), rp
140 adc %r11, %r10
141 jmp L(b4)
142
143 L(f5): mulx( (up), %r9, %rax)
144 lea 32(up), up
145 lea -32(rp), rp
146 adc %r11, %r9
147 jmp L(b5)
148
149 L(f6): mulx( (up), %r10, %r8)
150 lea 40(up), up
151 lea -24(rp), rp
152 adc %r11, %r10
153 jmp L(b6)
154
155 L(f1): mulx( (up), %r9, %rax)
156 adc %r11, %r9
157 jrcxz L(end)
158 jmp L(b1)
159
160 L(end): mov %r9, (rp)
161 adc %rcx, %rax C relies on rcx = 0
162 FUNC_EXIT()
163 ret
164
165 L(f2): mulx( (up), %r10, %r8)
166 lea 8(up), up
167 lea 8(rp), rp
168 mulx( (up), %r9, %rax)
169 adc %r11, %r10
170
171 ALIGN(32)
172 L(top): adcx( %r8, %r9)
173 mov %r10, -8(rp)
174 jrcxz L(end)
175 L(b1): mulx( 8,(up), %r10, %r8)
176 lea -1(n), n
177 mov %r9, (rp)
178 adcx( %rax, %r10)
179 L(b0): mulx( 16,(up), %r9, %rax)
180 adcx( %r8, %r9)
181 mov %r10, 8(rp)
182 L(b7): mulx( 24,(up), %r10, %r8)
183 lea 64(up), up
184 adcx( %rax, %r10)
185 mov %r9, 16(rp)
186 L(b6): mulx( -32,(up), %r9, %rax)
187 adcx( %r8, %r9)
188 mov %r10, 24(rp)
189 L(b5): mulx( -24,(up), %r10, %r8)
190 adcx( %rax, %r10)
191 mov %r9, 32(rp)
192 L(b4): mulx( -16,(up), %r9, %rax)
193 adcx( %r8, %r9)
194 mov %r10, 40(rp)
195 L(b3): mulx( -8,(up), %r10, %r8)
196 mov %r9, 48(rp)
197 lea 64(rp), rp
198 adcx( %rax, %r10)
199 mulx( (up), %r9, %rax)
200 jmp L(top)
201
202 L(f7): mulx( (up), %r9, %rax)
203 lea -16(up), up
204 lea -16(rp), rp
205 adc %r11, %r9
206 jmp L(b7)
207 EPILOGUE()
208 ASM_END()