Debian Codegraph @

mpn/x86_64/coreibwl/addmul_1.asm

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