Debian Codegraph @

mpn/x86_64/coreibwl/mul_1.asm

raw
1 dnl AMD64 mpn_mul_1 optimised for Intel Broadwell.
2
3 dnl Copyright 2015 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 bull -
37 C AMD pile -
38 C AMD steam -
39 C AMD excavator -
40 C AMD bobcat -
41 C AMD jaguar -
42 C Intel P4 -
43 C Intel core2 -
44 C Intel NHM -
45 C Intel SBR -
46 C Intel IBR -
47 C Intel HWL 1.70
48 C Intel BWL 1.51
49 C Intel SKL 1.52
50 C Intel atom -
51 C Intel SLM -
52 C VIA nano -
53
54 C The loop of this code is the result of running a code generation and
55 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
56
57 C TODO
58 C * Put an initial mulx before switching, targeting some free registers.
59 C * Tune feed-in code.
60 C * Trim nop execution after L(f2).
61 C * Port to DOS64, not forgetting nop execution.
62
63 define(`rp', `%rdi') C rcx
64 define(`up', `%rsi') C rdx
65 define(`n_param', `%rdx') C r8
66 define(`v0_param',`%rcx') C r9
67
68 define(`n', `%rcx')
69
70 dnl ABI_SUPPORT(DOS64)
71 ABI_SUPPORT(STD64)
72
73 dnl IFDOS(` define(`up', ``%rsi'') ') dnl
74 dnl IFDOS(` define(`rp', ``%rcx'') ') dnl
75 dnl IFDOS(` define(`vl', ``%r9'') ') dnl
76 dnl IFDOS(` define(`r9', ``rdi'') ') dnl
77 dnl IFDOS(` define(`n', ``%r8'') ') dnl
78 dnl IFDOS(` define(`r8', ``r11'') ') dnl
79
80 ASM_START()
81 TEXT
82 ALIGN(32)
83 PROLOGUE(mpn_mul_1)
84
85 mov v0_param, %r10
86 mov n_param, n
87 mov R32(n_param), R32(%r8)
88 shr $3, n
89 and $7, R32(%r8) C clear OF, CF as side-effect
90 mov %r10, %rdx
91 lea L(tab)(%rip), %r10
92 ifdef(`PIC',
93 ` movslq (%r10,%r8,4), %r8
94 lea (%r8, %r10), %r10
95 jmp *%r10
96 ',`
97 jmp *(%r10,%r8,8)
98 ')
99 JUMPTABSECT
100 ALIGN(8)
101 L(tab): JMPENT( L(f0), L(tab))
102 JMPENT( L(f1), L(tab))
103 JMPENT( L(f2), L(tab))
104 JMPENT( L(f3), L(tab))
105 JMPENT( L(f4), L(tab))
106 JMPENT( L(f5), L(tab))
107 JMPENT( L(f6), L(tab))
108 JMPENT( L(f7), L(tab))
109 TEXT
110
111 L(f0): mulx( (up), %r10, %r8)
112 lea 56(up), up
113 lea -8(rp), rp
114 jmp L(b0)
115
116 L(f3): mulx( (up), %r9, %rax)
117 lea 16(up), up
118 lea 16(rp), rp
119 inc n
120 jmp L(b3)
121
122 L(f4): mulx( (up), %r10, %r8)
123 lea 24(up), up
124 lea 24(rp), rp
125 inc n
126 jmp L(b4)
127
128 L(f5): mulx( (up), %r9, %rax)
129 lea 32(up), up
130 lea 32(rp), rp
131 inc n
132 jmp L(b5)
133
134 L(f6): mulx( (up), %r10, %r8)
135 lea 40(up), up
136 lea 40(rp), rp
137 inc n
138 jmp L(b6)
139
140 L(f7): mulx( (up), %r9, %rax)
141 lea 48(up), up
142 lea 48(rp), rp
143 inc n
144 jmp L(b7)
145
146 L(f1): mulx( (up), %r9, %rax)
147 test n, n
148 jnz L(b1)
149 L(1): mov %r9, (rp)
150 ret
151
152 L(f2): mulx( (up), %r10, %r8)
153 lea 8(up), up
154 lea 8(rp), rp
155 mulx( (up), %r9, %rax)
156 test n, n
157 jz L(end)
158
159 ALIGN(32)
160 L(top): mov %r10, -8(rp)
161 adc %r8, %r9
162 L(b1): mulx( 8,(up), %r10, %r8)
163 adc %rax, %r10
164 lea 64(up), up
165 mov %r9, (rp)
166 L(b0): mov %r10, 8(rp)
167 mulx( -48,(up), %r9, %rax)
168 lea 64(rp), rp
169 adc %r8, %r9
170 L(b7): mulx( -40,(up), %r10, %r8)
171 mov %r9, -48(rp)
172 adc %rax, %r10
173 L(b6): mov %r10, -40(rp)
174 mulx( -32,(up), %r9, %rax)
175 adc %r8, %r9
176 L(b5): mulx( -24,(up), %r10, %r8)
177 mov %r9, -32(rp)
178 adc %rax, %r10
179 L(b4): mulx( -16,(up), %r9, %rax)
180 mov %r10, -24(rp)
181 adc %r8, %r9
182 L(b3): mulx( -8,(up), %r10, %r8)
183 adc %rax, %r10
184 mov %r9, -16(rp)
185 dec n
186 mulx( (up), %r9, %rax)
187 jnz L(top)
188
189 L(end): mov %r10, -8(rp)
190 adc %r8, %r9
191 mov %r9, (rp)
192 adc %rcx, %rax
193 ret
194 EPILOGUE()
195 ASM_END()