Debian Codegraph @

mpn/x86_64/coreisbr/aorsmul_1.asm

raw
1 dnl X86-64 mpn_addmul_1 and mpn_submul_1 optimised for Intel Sandy Bridge.
2
3 dnl Contributed to the GNU project by Torbjörn Granlund.
4
5 dnl Copyright 2003-2005, 2007, 2008, 2011-2013 Free Software Foundation, Inc.
6
7 dnl This file is part of the GNU MP Library.
8 dnl
9 dnl The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl it under the terms of either:
11 dnl
12 dnl * the GNU Lesser General Public License as published by the Free
13 dnl Software Foundation; either version 3 of the License, or (at your
14 dnl option) any later version.
15 dnl
16 dnl or
17 dnl
18 dnl * the GNU General Public License as published by the Free Software
19 dnl Foundation; either version 2 of the License, or (at your option) any
20 dnl later version.
21 dnl
22 dnl or both in parallel, as here.
23 dnl
24 dnl The GNU MP Library is distributed in the hope that it will be useful, but
25 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 dnl for more details.
28 dnl
29 dnl You should have received copies of the GNU General Public License and the
30 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
31 dnl see https://www.gnu.org/licenses/.
32
33 include(`../config.m4')
34
35 C cycles/limb
36 C AMD K8,K9 4.27
37 C AMD K10 4.27 4.54
38 C AMD bull 4.76
39 C AMD pile 4.55
40 C AMD steam
41 C AMD excavator
42 C AMD bobcat 5.30
43 C AMD jaguar 5.28
44 C Intel P4 16.2 17.1
45 C Intel core2 5.26
46 C Intel NHM 5.09
47 C Intel SBR 3.21
48 C Intel IBR 2.96
49 C Intel HWL 2.81
50 C Intel BWL 2.76
51 C Intel SKL 2.76
52 C Intel atom 21.5
53 C Intel SLM 9.5
54 C VIA nano
55
56 C The loop of this code is the result of running a code generation and
57 C optimization tool suite written by David Harvey and Torbjörn Granlund.
58
59 define(`rp', `%rdi') C rcx
60 define(`up', `%rsi') C rdx
61 define(`n_param', `%rdx') C r8
62 define(`v0', `%rcx') C r9
63
64 define(`n', `%rbx')
65
66 define(`I',`$1')
67
68 ifdef(`OPERATION_addmul_1',`
69 define(`ADDSUB', `add')
70 define(`func', `mpn_addmul_1')
71 ')
72 ifdef(`OPERATION_submul_1',`
73 define(`ADDSUB', `sub')
74 define(`func', `mpn_submul_1')
75 ')
76
77 ABI_SUPPORT(DOS64)
78 ABI_SUPPORT(STD64)
79
80 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
81
82 IFDOS(` define(`up', ``%rsi'')') dnl
83 IFDOS(` define(`rp', ``%rcx'')') dnl
84 IFDOS(` define(`v0', ``%r9'')') dnl
85 IFDOS(` define(`r9', ``rdi'')') dnl
86 IFDOS(` define(`n_param',``%r8'')') dnl
87
88 ASM_START()
89 TEXT
90 ALIGN(32)
91 PROLOGUE(func)
92
93 IFDOS(``push %rsi '')
94 IFDOS(``push %rdi '')
95 IFDOS(``mov %rdx, %rsi '')
96
97 mov (up), %rax
98 push %rbx
99 lea (up,n_param,8), up
100 lea (rp,n_param,8), rp
101
102 test $1, R8(n_param)
103 jnz L(b13)
104
105 L(b02): xor R32(%r11), R32(%r11)
106 test $2, R8(n_param)
107 jnz L(b2)
108
109 L(b0): mov $1, R32(n)
110 sub n_param, n
111 mul v0
112 mov %rdx, %r9
113 mov -8(rp,n,8), %r8
114 jmp L(e0)
115
116 ALIGN(16)
117 L(b2): mov $-1, n
118 sub n_param, n
119 mul v0
120 mov 8(rp,n,8), %r8
121 mov %rdx, %r9
122 jmp L(e2)
123
124 ALIGN(16)
125 L(b13): xor R32(%r9), R32(%r9)
126 test $2, R8(n_param)
127 jnz L(b3)
128
129 L(b1): mov $2, R32(n)
130 sub n_param, n
131 jns L(1)
132 mul v0
133 mov -16(rp,n,8), %r10
134 mov %rdx, %r11
135 jmp L(e1)
136
137 ALIGN(16)
138 L(b3): xor R32(n), R32(n)
139 sub n_param, n
140 mul v0
141 mov (rp,n,8), %r10
142 jmp L(e3)
143
144 ALIGN(32)
145 L(top): mul v0
146 mov -16(rp,n,8), %r10
147 ADDSUB %r11, %r8
148 mov %rdx, %r11
149 adc $0, %r9
150 mov %r8, -24(rp,n,8)
151 L(e1): ADDSUB %rax, %r10
152 mov -8(up,n,8), %rax
153 adc $0, %r11
154 mul v0
155 ADDSUB %r9, %r10
156 mov %rdx, %r9
157 mov -8(rp,n,8), %r8
158 adc $0, %r11
159 mov %r10, -16(rp,n,8)
160 L(e0): ADDSUB %rax, %r8
161 adc $0, %r9
162 mov (up,n,8), %rax
163 mul v0
164 mov (rp,n,8), %r10
165 ADDSUB %r11, %r8
166 mov %r8, -8(rp,n,8)
167 adc $0, %r9
168 L(e3): mov %rdx, %r11
169 ADDSUB %rax, %r10
170 mov 8(up,n,8), %rax
171 adc $0, %r11
172 mul v0
173 mov 8(rp,n,8), %r8
174 ADDSUB %r9, %r10
175 mov %rdx, %r9
176 mov %r10, (rp,n,8)
177 adc $0, %r11
178 L(e2): ADDSUB %rax, %r8
179 adc $0, %r9
180 mov 16(up,n,8), %rax
181 add $4, n
182 jnc L(top)
183
184 L(end): mul v0
185 mov I(-8(rp),-16(rp,n,8)), %r10
186 ADDSUB %r11, %r8
187 mov %rdx, %r11
188 adc $0, %r9
189 mov %r8, I(-16(rp),-24(rp,n,8))
190 ADDSUB %rax, %r10
191 adc $0, %r11
192 ADDSUB %r9, %r10
193 adc $0, %r11
194 mov %r10, I(-8(rp),-16(rp,n,8))
195 mov %r11, %rax
196
197 pop %rbx
198 IFDOS(``pop %rdi '')
199 IFDOS(``pop %rsi '')
200 ret
201
202 ALIGN(16)
203 L(1): mul v0
204 ADDSUB %rax, -8(rp)
205 mov %rdx, %rax
206 adc $0, %rax
207 pop %rbx
208 IFDOS(``pop %rdi '')
209 IFDOS(``pop %rsi '')
210 ret
211 EPILOGUE()
212 ASM_END()