Debian Codegraph @

gmp4/mpn/x86_64/coreihwl/mul_2.asm

raw
1 dnl AMD64 mpn_mul_2 optimised for Intel Haswell.
2
3 dnl Contributed to the GNU project by Torbjörn Granlund.
4
5 dnl Copyright 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 n/a
37 C AMD K10 n/a
38 C AMD bull n/a
39 C AMD pile n/a
40 C AMD steam ?
41 C AMD bobcat n/a
42 C AMD jaguar ?
43 C Intel P4 n/a
44 C Intel core n/a
45 C Intel NHM n/a
46 C Intel SBR n/a
47 C Intel IBR n/a
48 C Intel HWL 1.86
49 C Intel BWL ?
50 C Intel atom n/a
51 C VIA nano n/a
52
53 C The loop of this code is the result of running a code generation and
54 C optimisation tool suite written by David Harvey and Torbjörn Granlund.
55
56 C TODO
57 C * Move test and jcc together, for insn fusion.
58
59 define(`rp', `%rdi')
60 define(`up', `%rsi')
61 define(`n_param',`%rdx')
62 define(`vp', `%rcx')
63
64 define(`v0', `%r8')
65 define(`v1', `%r9')
66 define(`w0', `%rbx')
67 define(`w1', `%rcx')
68 define(`w2', `%rbp')
69 define(`w3', `%r10')
70 define(`n', `%r11')
71
72 ABI_SUPPORT(DOS64)
73 ABI_SUPPORT(STD64)
74
75 ASM_START()
76 TEXT
77 ALIGN(32)
78 PROLOGUE(mpn_mul_2)
79 FUNC_ENTRY(4)
80 push %rbx
81 push %rbp
82
83 mov (vp), v0
84 mov 8(vp), v1
85
86 lea 3(n_param), n
87 shr $2, n
88
89 test $1, R8(n_param)
90 jnz L(bx1)
91
92 L(bx0): xor w0, w0
93 test $2, R8(n_param)
94 mov (up), %rdx
95 mulx( v0, w2, w1)
96 jz L(lo0)
97
98 L(b10): lea -16(rp), rp
99 lea -16(up), up
100 jmp L(lo2)
101
102 L(bx1): xor w2, w2
103 test $2, R8(n_param)
104 mov (up), %rdx
105 mulx( v0, w0, w3)
106 jnz L(b11)
107
108 L(b01): lea -24(rp), rp
109 lea 8(up), up
110 jmp L(lo1)
111
112 L(b11): lea -8(rp), rp
113 lea -8(up), up
114 jmp L(lo3)
115
116 ALIGN(16)
117 L(top): mulx( v1, %rax, w0)
118 add %rax, w2 C 0
119 mov (up), %rdx
120 mulx( v0, %rax, w1)
121 adc $0, w0 C 1
122 add %rax, w2 C 0
123 adc $0, w1 C 1
124 add w3, w2 C 0
125 L(lo0): mov w2, (rp) C 0
126 adc $0, w1 C 1
127 mulx( v1, %rax, w2)
128 add %rax, w0 C 1
129 mov 8(up), %rdx
130 adc $0, w2 C 2
131 mulx( v0, %rax, w3)
132 add %rax, w0 C 1
133 adc $0, w3 C 2
134 add w1, w0 C 1
135 L(lo3): mov w0, 8(rp) C 1
136 adc $0, w3 C 2
137 mulx( v1, %rax, w0)
138 add %rax, w2 C 2
139 mov 16(up), %rdx
140 mulx( v0, %rax, w1)
141 adc $0, w0 C 3
142 add %rax, w2 C 2
143 adc $0, w1 C 3
144 add w3, w2 C 2
145 L(lo2): mov w2, 16(rp) C 2
146 adc $0, w1 C 3
147 mulx( v1, %rax, w2)
148 add %rax, w0 C 3
149 mov 24(up), %rdx
150 adc $0, w2 C 4
151 mulx( v0, %rax, w3)
152 add %rax, w0 C 3
153 adc $0, w3 C 4
154 add w1, w0 C 3
155 lea 32(up), up
156 L(lo1): mov w0, 24(rp) C 3
157 adc $0, w3 C 4
158 dec n
159 lea 32(rp), rp
160 jnz L(top)
161
162 L(end): mulx( v1, %rdx, %rax)
163 add %rdx, w2
164 adc $0, %rax
165 add w3, w2
166 mov w2, (rp)
167 adc $0, %rax
168
169 pop %rbp
170 pop %rbx
171 FUNC_EXIT()
172 ret
173 EPILOGUE()