Debian Codegraph @

mpn/x86_64/coreihwl/aors_n.asm

raw
1 dnl AMD64 mpn_add_n, mpn_sub_n
2
3 dnl Copyright 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
35 C AMD K10
36 C AMD bd1 1.5 with fluctuations
37 C AMD bd2 1.5 with fluctuations
38 C AMD bd3
39 C AMD bd4 1.6
40 C AMD zen
41 C AMD bt1
42 C AMD bt2
43 C Intel P4
44 C Intel PNR
45 C Intel NHM
46 C Intel SBR
47 C Intel IBR
48 C Intel HWL 1.21
49 C Intel BWL 1.04
50 C Intel SKL
51 C Intel atom
52 C Intel SLM
53 C VIA nano
54
55 C The loop of this code is the result of running a code generation and
56 C optimization tool suite written by David Harvey and Torbjorn Granlund.
57
58 C INPUT PARAMETERS
59 define(`rp', `%rdi') C rcx
60 define(`up', `%rsi') C rdx
61 define(`vp', `%rdx') C r8
62 define(`n', `%rcx') C r9
63 define(`cy', `%r8') C rsp+40 (mpn_add_nc and mpn_sub_nc)
64
65 ifdef(`OPERATION_add_n', `
66 define(ADCSBB, adc)
67 define(func, mpn_add_n)
68 define(func_nc, mpn_add_nc)')
69 ifdef(`OPERATION_sub_n', `
70 define(ADCSBB, sbb)
71 define(func, mpn_sub_n)
72 define(func_nc, mpn_sub_nc)')
73
74 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
75
76 ABI_SUPPORT(DOS64)
77 ABI_SUPPORT(STD64)
78
79 ASM_START()
80 TEXT
81 ALIGN(16)
82 PROLOGUE(func_nc)
83 FUNC_ENTRY(4)
84 IFDOS(` mov 56(%rsp), %r8 ')
85
86 mov R32(n), R32(%rax)
87 shr $3, n
88 and $7, R32(%rax)
89
90 lea L(tab)(%rip), %r9
91 neg %r8 C set carry
92 ifdef(`PIC',`
93 movslq (%r9,%rax,4), %rax
94 lea (%r9,%rax), %rax C lea not add to preserve carry
95 jmp *%rax
96 ',`
97 jmp *(%r9,%rax,8)
98 ')
99 EPILOGUE()
100
101 ALIGN(16)
102 PROLOGUE(func)
103 FUNC_ENTRY(4)
104
105 mov R32(n), R32(%rax)
106 shr $3, n
107 and $7, R32(%rax) C clear cy as side-effect
108
109 lea L(tab)(%rip), %r9
110 ifdef(`PIC',`
111 movslq (%r9,%rax,4), %rax
112 lea (%r9,%rax), %rax C lea not add to preserve carry
113 jmp *%rax
114 ',`
115 jmp *(%r9,%rax,8)
116 ')
117
118 L(0): mov (up), %r8
119 mov 8(up), %r9
120 ADCSBB (vp), %r8
121 jmp L(e0)
122
123 L(4): mov (up), %r8
124 mov 8(up), %r9
125 ADCSBB (vp), %r8
126 lea -32(up), up
127 lea -32(vp), vp
128 lea -32(rp), rp
129 inc n
130 jmp L(e4)
131
132 L(5): mov (up), %r11
133 mov 8(up), %r8
134 mov 16(up), %r9
135 ADCSBB (vp), %r11
136 lea -24(up), up
137 lea -24(vp), vp
138 lea -24(rp), rp
139 inc n
140 jmp L(e5)
141
142 L(6): mov (up), %r10
143 ADCSBB (vp), %r10
144 mov 8(up), %r11
145 lea -16(up), up
146 lea -16(vp), vp
147 lea -16(rp), rp
148 inc n
149 jmp L(e6)
150
151 L(7): mov (up), %r9
152 mov 8(up), %r10
153 ADCSBB (vp), %r9
154 ADCSBB 8(vp), %r10
155 lea -8(up), up
156 lea -8(vp), vp
157 lea -8(rp), rp
158 inc n
159 jmp L(e7)
160
161 ALIGN(16)
162 L(top):
163 L(e3): mov %r9, 40(rp)
164 L(e2): mov %r10, 48(rp)
165 L(e1): mov (up), %r8
166 mov 8(up), %r9
167 ADCSBB (vp), %r8
168 mov %r11, 56(rp)
169 lea 64(rp), rp
170 L(e0): mov 16(up), %r10
171 ADCSBB 8(vp), %r9
172 ADCSBB 16(vp), %r10
173 mov %r8, (rp)
174 L(e7): mov 24(up), %r11
175 mov %r9, 8(rp)
176 L(e6): mov 32(up), %r8
177 mov 40(up), %r9
178 ADCSBB 24(vp), %r11
179 mov %r10, 16(rp)
180 L(e5): ADCSBB 32(vp), %r8
181 mov %r11, 24(rp)
182 L(e4): mov 48(up), %r10
183 mov 56(up), %r11
184 mov %r8, 32(rp)
185 lea 64(up), up
186 ADCSBB 40(vp), %r9
187 ADCSBB 48(vp), %r10
188 ADCSBB 56(vp), %r11
189 lea 64(vp), vp
190 dec n
191 jnz L(top)
192
193 L(end): mov %r9, 40(rp)
194 mov %r10, 48(rp)
195 mov %r11, 56(rp)
196 mov R32(n), R32(%rax)
197 adc R32(n), R32(%rax)
198 FUNC_EXIT()
199 ret
200
201 ALIGN(16)
202 L(3): mov (up), %r9
203 mov 8(up), %r10
204 mov 16(up), %r11
205 ADCSBB (vp), %r9
206 ADCSBB 8(vp), %r10
207 ADCSBB 16(vp), %r11
208 jrcxz L(x3)
209 lea 24(up), up
210 lea 24(vp), vp
211 lea -40(rp), rp
212 jmp L(e3)
213 L(x3): mov %r9, (rp)
214 mov %r10, 8(rp)
215 mov %r11, 16(rp)
216 mov R32(n), R32(%rax)
217 adc R32(n), R32(%rax)
218 FUNC_EXIT()
219 ret
220
221 ALIGN(16)
222 L(1): mov (up), %r11
223 ADCSBB (vp), %r11
224 jrcxz L(x1)
225 lea 8(up), up
226 lea 8(vp), vp
227 lea -56(rp), rp
228 jmp L(e1)
229 L(x1): mov %r11, (rp)
230 mov R32(n), R32(%rax)
231 adc R32(n), R32(%rax)
232 FUNC_EXIT()
233 ret
234
235 ALIGN(16)
236 L(2): mov (up), %r10
237 mov 8(up), %r11
238 ADCSBB (vp), %r10
239 ADCSBB 8(vp), %r11
240 jrcxz L(x2)
241 lea 16(up), up
242 lea 16(vp), vp
243 lea -48(rp), rp
244 jmp L(e2)
245 L(x2): mov %r10, (rp)
246 mov %r11, 8(rp)
247 mov R32(n), R32(%rax)
248 adc R32(n), R32(%rax)
249 FUNC_EXIT()
250 ret
251 EPILOGUE()
252 JUMPTABSECT
253 ALIGN(8)
254 L(tab): JMPENT( L(0), L(tab))
255 JMPENT( L(1), L(tab))
256 JMPENT( L(2), L(tab))
257 JMPENT( L(3), L(tab))
258 JMPENT( L(4), L(tab))
259 JMPENT( L(5), L(tab))
260 JMPENT( L(6), L(tab))
261 JMPENT( L(7), L(tab))