Debian Codegraph @

gmp4/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
38 C AMD K10
39 C AMD bull 1.82 average over 400-600
40 C AMD pile 1.83 average over 400-600
41 C AMD bobcat
42 C AMD jaguar
43 C Intel P4
44 C Intel core
45 C Intel NHM
46 C Intel SBR 1.55 fluctuates
47 C Intel IBR 1.55 fluctuates
48 C Intel HWL 1.33 fluctuates
49 C Intel BWL
50 C Intel atom
51 C VIA nano
52
53 C The loop of this code was manually written. It runs close to optimally on
54 C Intel SBR, IBR, and HWL far as we know, except for the fluctuation problems.
55 C It also runs slightly faster on average on AMD bull and pile.
56 C
57 C No micro-optimisation has been done.
58 C
59 C N.B.! The loop alignment padding insns are executed. If editing the code,
60 C make sure the padding does not become excessive. It is now a 4-byte nop.
61
62 define(`rp', `%rdi') C rcx
63 define(`up', `%rsi') C rdx
64 define(`vp', `%rdx') C r8
65 define(`n', `%rcx') C r9
66 define(`cy', `%r8') C rsp+40 (mpn_add_nc and mpn_sub_nc)
67
68 ifdef(`OPERATION_add_n', `
69 define(ADCSBB, adc)
70 define(func, mpn_add_n)
71 define(func_nc, mpn_add_nc)')
72 ifdef(`OPERATION_sub_n', `
73 define(ADCSBB, sbb)
74 define(func, mpn_sub_n)
75 define(func_nc, mpn_sub_nc)')
76
77 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
78
79 ABI_SUPPORT(DOS64)
80 ABI_SUPPORT(STD64)
81
82 ASM_START()
83 TEXT
84 ALIGN(32)
85 PROLOGUE(func)
86 FUNC_ENTRY(4)
87 xor %r8, %r8
88
89 L(ent): mov R32(n), R32(%rax)
90 shr $2, n
91
92 test $1, R8(%rax)
93 jnz L(bx1)
94
95 L(bx0): test $2, R8(%rax)
96 jnz L(b10)
97
98 L(b00): neg %r8
99 mov (up), %r8
100 mov 8(up), %r9
101 ADCSBB (vp), %r8
102 ADCSBB 8(vp), %r9
103 mov 16(up), %r10
104 mov 24(up), %r11
105 lea 32(up), up
106 ADCSBB 16(vp), %r10
107 ADCSBB 24(vp), %r11
108 lea 32(vp), vp
109 lea -16(rp), rp
110 jmp L(lo0)
111
112 L(b10): neg %r8
113 mov (up), %r10
114 mov 8(up), %r11
115 ADCSBB 0(vp), %r10
116 ADCSBB 8(vp), %r11
117 jrcxz L(e2)
118 mov 16(up), %r8
119 mov 24(up), %r9
120 lea 16(up), up
121 ADCSBB 16(vp), %r8
122 ADCSBB 24(vp), %r9
123 lea 16(vp), vp
124 lea (rp), rp
125 jmp L(lo2)
126
127 L(e2): mov %r10, (rp)
128 mov %r11, 8(rp)
129 setc R8(%rax)
130 FUNC_EXIT()
131 ret
132
133 L(bx1): test $2, R8(%rax)
134 jnz L(b11)
135
136 L(b01): neg %r8
137 mov (up), %r11
138 ADCSBB (vp), %r11
139 jrcxz L(e1)
140 mov 8(up), %r8
141 mov 16(up), %r9
142 lea 8(up), up
143 lea -8(rp), rp
144 ADCSBB 8(vp), %r8
145 ADCSBB 16(vp), %r9
146 lea 8(vp), vp
147 jmp L(lo1)
148
149 L(e1): mov %r11, (rp)
150 setc R8(%rax)
151 FUNC_EXIT()
152 ret
153
154 L(b11): neg %r8
155 mov (up), %r9
156 ADCSBB (vp), %r9
157 mov 8(up), %r10
158 mov 16(up), %r11
159 lea 24(up), up
160 ADCSBB 8(vp), %r10
161 ADCSBB 16(vp), %r11
162 lea 24(vp), vp
163 mov %r9, (rp)
164 lea 8(rp), rp
165 jrcxz L(end)
166
167 ALIGN(32)
168 L(top): mov (up), %r8
169 mov 8(up), %r9
170 ADCSBB (vp), %r8
171 ADCSBB 8(vp), %r9
172 L(lo2): mov %r10, (rp)
173 L(lo1): mov %r11, 8(rp)
174 mov 16(up), %r10
175 mov 24(up), %r11
176 lea 32(up), up
177 ADCSBB 16(vp), %r10
178 ADCSBB 24(vp), %r11
179 lea 32(vp), vp
180 L(lo0): mov %r8, 16(rp)
181 L(lo3): mov %r9, 24(rp)
182 lea 32(rp), rp
183 dec n
184 jnz L(top)
185
186 L(end): mov R32(n), R32(%rax) C zero rax
187 mov %r10, (rp)
188 mov %r11, 8(rp)
189 setc R8(%rax)
190 FUNC_EXIT()
191 ret
192 EPILOGUE()
193 ALIGN(16)
194 PROLOGUE(func_nc)
195 FUNC_ENTRY(4)
196 IFDOS(` mov 56(%rsp), %r8 ')
197 jmp L(ent)
198 EPILOGUE()