Debian Codegraph @

mpn/x86_64/coreinhm/aorsmul_1.asm

raw
1 dnl AMD64 mpn_addmul_1 and mpn_submul_1 optimised for Intel Nehalem.
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.0
37 C AMD K10 4.0
38 C AMD bull 5.0
39 C AMD pile 4.84 5.39
40 C AMD steam
41 C AMD excavator
42 C AMD bobcat 5.56
43 C AMD jaguar 5.30
44 C Intel P4 15.7 17.2
45 C Intel core2 5.15
46 C Intel NHM 4.56
47 C Intel SBR 3.44
48 C Intel HWL 3.03
49 C Intel BWL 2.77
50 C Intel SKL 2.76
51 C Intel atom 21
52 C Intel SLM 11
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 N.B.: Be careful if editing, making sure the loop alignment padding does not
59 C become large, as we currently fall into it.
60
61 define(`rp', `%rdi') C rcx
62 define(`up', `%rsi') C rdx
63 define(`n_param', `%rdx') C r8
64 define(`v0', `%rcx') C r9
65
66 define(`n', `%rbx')
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 ASM_START()
83 TEXT
84 ALIGN(32)
85 PROLOGUE(func)
86 FUNC_ENTRY(4)
87 push %rbx
88
89 mov (up), %rax
90 lea -8(up,n_param,8), up
91 mov (rp), %r8
92 lea -8(rp,n_param,8), rp
93
94 test $1, R8(n_param)
95 jnz L(bx1)
96
97 L(bx0): test $2, R8(n_param)
98 jnz L(b10)
99
100 L(b00): mov $3, R32(n)
101 sub n_param, n
102 mul v0
103 mov $0, R32(%r11)
104 mov %r8, %r10
105 ADDSUB %rax, %r10
106 mov -8(up,n,8), %rax
107 adc %rdx, %r11
108 jmp L(lo0)
109
110 L(b10): mov $1, R32(n)
111 sub n_param, n
112 mul v0
113 mov %r8, %r10
114 mov $0, R32(%r11)
115 ADDSUB %rax, %r10
116 mov 8(up,n,8), %rax
117 adc %rdx, %r11
118 jmp L(lo2)
119
120 L(bx1): test $2, R8(n_param)
121 jz L(b01)
122
123 L(b11): mov $2, R32(n)
124 sub n_param, n
125 mul v0
126 ADDSUB %rax, %r8
127 mov $0, R32(%r9)
128 mov (up,n,8), %rax
129 adc %rdx, %r9
130 jmp L(lo3)
131
132 L(b01): mov $0, R32(n)
133 sub n_param, n
134 xor %r11, %r11
135 add $4, n
136 jc L(end)
137
138 ALIGN(32)
139 L(top): mul v0
140 ADDSUB %rax, %r8
141 mov $0, R32(%r9)
142 mov -16(up,n,8), %rax
143 adc %rdx, %r9
144 L(lo1): mul v0
145 ADDSUB %r11, %r8
146 mov $0, R32(%r11)
147 mov -16(rp,n,8), %r10
148 adc $0, %r9
149 ADDSUB %rax, %r10
150 mov -8(up,n,8), %rax
151 adc %rdx, %r11
152 mov %r8, -24(rp,n,8)
153 ADDSUB %r9, %r10
154 adc $0, %r11
155 L(lo0): mov -8(rp,n,8), %r8
156 mul v0
157 ADDSUB %rax, %r8
158 mov $0, R32(%r9)
159 mov (up,n,8), %rax
160 adc %rdx, %r9
161 mov %r10, -16(rp,n,8)
162 ADDSUB %r11, %r8
163 adc $0, %r9
164 L(lo3): mul v0
165 mov (rp,n,8), %r10
166 mov $0, R32(%r11)
167 ADDSUB %rax, %r10
168 mov 8(up,n,8), %rax
169 adc %rdx, %r11
170 mov %r8, -8(rp,n,8)
171 ADDSUB %r9, %r10
172 adc $0, %r11
173 L(lo2): mov 8(rp,n,8), %r8
174 mov %r10, (rp,n,8)
175 add $4, n
176 jnc L(top)
177
178 L(end): mul v0
179 ADDSUB %rax, %r8
180 mov $0, R32(%rax)
181 adc %rdx, %rax
182 ADDSUB %r11, %r8
183 adc $0, %rax
184 mov %r8, (rp)
185
186 pop %rbx
187 FUNC_EXIT()
188 ret
189 EPILOGUE()
190 ASM_END()