Debian Codegraph @

mpn/x86_64/coreisbr/aors_n.asm

raw
1 dnl AMD64 mpn_add_n, mpn_sub_n optimised for Sandy bridge, Ivy bridge, and
2 dnl Haswell.
3
4 dnl Contributed to the GNU project by Torbjörn Granlund.
5
6 dnl Copyright 2003-2005, 2007, 2008, 2010-2013 Free Software Foundation, Inc.
7
8 dnl This file is part of the GNU MP Library.
9 dnl
10 dnl The GNU MP Library is free software; you can redistribute it and/or modify
11 dnl it under the terms of either:
12 dnl
13 dnl * the GNU Lesser General Public License as published by the Free
14 dnl Software Foundation; either version 3 of the License, or (at your
15 dnl option) any later version.
16 dnl
17 dnl or
18 dnl
19 dnl * the GNU General Public License as published by the Free Software
20 dnl Foundation; either version 2 of the License, or (at your option) any
21 dnl later version.
22 dnl
23 dnl or both in parallel, as here.
24 dnl
25 dnl The GNU MP Library is distributed in the hope that it will be useful, but
26 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 dnl for more details.
29 dnl
30 dnl You should have received copies of the GNU General Public License and the
31 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
32 dnl see https://www.gnu.org/licenses/.
33
34 include(`../config.m4')
35
36 C cycles/limb
37 C AMD K8,K9 1.75\2.52
38 C AMD K10 1.5
39 C AMD bd1 1.69\2.25
40 C AMD bd2 1.65
41 C AMD bd3 ?
42 C AMD bd4 ?
43 C AMD zen 1.5
44 C AMD bt1 2.67
45 C AMD bt2 2.16
46 C Intel P4 11.54
47 C Intel PNR 5
48 C Intel NHM 5.5
49 C Intel SBR 1.54
50 C Intel IBR 1.5
51 C Intel HWL 1.32
52 C Intel BWL 1.07
53 C Intel SKL 1.21
54 C Intel atom 4.3
55 C Intel SLM 3
56 C VIA nano ?
57
58 C The loop of this code was manually written. It runs close to optimally on
59 C Intel SBR, IBR, and HWL far as we know, except for the fluctuation problems.
60 C It also runs slightly faster on average on AMD bd1 and bd2.
61 C
62 C No micro-optimisation has been done.
63 C
64 C N.B.! The loop alignment padding insns are executed. If editing the code,
65 C make sure the padding does not become excessive. It is now a 4-byte nop.
66
67 define(`rp', `%rdi') C rcx
68 define(`up', `%rsi') C rdx
69 define(`vp', `%rdx') C r8
70 define(`n', `%rcx') C r9
71 define(`cy', `%r8') C rsp+40 (mpn_add_nc and mpn_sub_nc)
72
73 ifdef(`OPERATION_add_n', `
74 define(ADCSBB, adc)
75 define(func, mpn_add_n)
76 define(func_nc, mpn_add_nc)')
77 ifdef(`OPERATION_sub_n', `
78 define(ADCSBB, sbb)
79 define(func, mpn_sub_n)
80 define(func_nc, mpn_sub_nc)')
81
82 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
83
84 ABI_SUPPORT(DOS64)
85 ABI_SUPPORT(STD64)
86
87 ASM_START()
88 TEXT
89 ALIGN(32)
90 PROLOGUE(func)
91 FUNC_ENTRY(4)
92 xor %r8, %r8
93
94 L(ent): mov R32(n), R32(%rax)
95 shr $2, n
96
97 test $1, R8(%rax)
98 jnz L(bx1)
99
100 L(bx0): test $2, R8(%rax)
101 jnz L(b10)
102
103 L(b00): neg %r8
104 mov (up), %r8
105 mov 8(up), %r9
106 ADCSBB (vp), %r8
107 ADCSBB 8(vp), %r9
108 mov 16(up), %r10
109 mov 24(up), %r11
110 lea 32(up), up
111 ADCSBB 16(vp), %r10
112 ADCSBB 24(vp), %r11
113 lea 32(vp), vp
114 lea -16(rp), rp
115 jmp L(lo0)
116
117 L(b10): neg %r8
118 mov (up), %r10
119 mov 8(up), %r11
120 ADCSBB 0(vp), %r10
121 ADCSBB 8(vp), %r11
122 jrcxz L(e2)
123 mov 16(up), %r8
124 mov 24(up), %r9
125 lea 16(up), up
126 ADCSBB 16(vp), %r8
127 ADCSBB 24(vp), %r9
128 lea 16(vp), vp
129 C lea (rp), rp
130 jmp L(lo2)
131
132 L(e2): mov %r10, (rp)
133 mov %r11, 8(rp)
134 setc R8(%rax)
135 FUNC_EXIT()
136 ret
137
138 L(bx1): test $2, R8(%rax)
139 jnz L(b11)
140
141 L(b01): neg %r8
142 mov (up), %r11
143 ADCSBB (vp), %r11
144 jrcxz L(e1)
145 mov 8(up), %r8
146 mov 16(up), %r9
147 lea 8(up), up
148 lea -8(rp), rp
149 ADCSBB 8(vp), %r8
150 ADCSBB 16(vp), %r9
151 lea 8(vp), vp
152 jmp L(lo1)
153
154 L(e1): mov %r11, (rp)
155 setc R8(%rax)
156 FUNC_EXIT()
157 ret
158
159 L(b11): neg %r8
160 mov (up), %r9
161 ADCSBB (vp), %r9
162 mov 8(up), %r10
163 mov 16(up), %r11
164 lea 24(up), up
165 ADCSBB 8(vp), %r10
166 ADCSBB 16(vp), %r11
167 lea 24(vp), vp
168 mov %r9, (rp)
169 lea 8(rp), rp
170 jrcxz L(end)
171
172 ALIGN(32)
173 L(top): mov (up), %r8
174 mov 8(up), %r9
175 ADCSBB (vp), %r8
176 ADCSBB 8(vp), %r9
177 L(lo2): mov %r10, (rp)
178 L(lo1): mov %r11, 8(rp)
179 mov 16(up), %r10
180 mov 24(up), %r11
181 lea 32(up), up
182 ADCSBB 16(vp), %r10
183 ADCSBB 24(vp), %r11
184 lea 32(vp), vp
185 L(lo0): mov %r8, 16(rp)
186 L(lo3): mov %r9, 24(rp)
187 lea 32(rp), rp
188 dec n
189 jnz L(top)
190
191 L(end): mov R32(n), R32(%rax) C zero rax
192 mov %r10, (rp)
193 mov %r11, 8(rp)
194 setc R8(%rax)
195 FUNC_EXIT()
196 ret
197 EPILOGUE()
198 ALIGN(16)
199 PROLOGUE(func_nc)
200 FUNC_ENTRY(4)
201 IFDOS(` mov 56(%rsp), %r8 ')
202 jmp L(ent)
203 EPILOGUE()