1 dnl AMD64 mpn_mul_basecase optimised for Intel Sandy bridge
and Ivy bridge.
3 dnl Contributed to the GNU project by Torbjörn Granlund.
5 dnl Copyright
2003-2005, 2007, 2008, 2011-2013 Free Software Foundation
, Inc.
7 dnl
This file is part of the GNU MP Library.
9 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
10 dnl it under the terms of
either:
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.
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
22 dnl
or both
in parallel
, as here.
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
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
/.
33 include(`..
/config.m4
')
35 C cycles/limb mul_1 mul_2 mul_3 addmul_2
46 C Intel SBR 2.5 2.5 - 2.95
47 C Intel IBR 2.4 2.3 - 2.68
48 C Intel HWL 2.35 2.0 - 2.5
53 C The inner loops of this code are the result of running a code generation and
54 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
57 C * Fix the addmul_2 fluctuation affecting SBR.
58 C * Improve feed-in code, avoiding zeroing of many registers and dummy adds in
59 C the loops at the expense of code size.
60 C * Adjoin a mul_3, avoiding slow mul_1 for odd vn.
61 C * Consider replacing the 2-way mul_2 code with 4-way code, for a very slight
63 C * Further micro-optimise.
65 C When playing with pointers, set this to $2 to fall back to conservative
66 C indexing in wind-down code.
72 define(`un_param',`
%rdx
')
91 PROLOGUE(mpn_mul_basecase)
93 IFDOS(` mov 56(%rsp), %r8d ')
96 mov un_param
, un C free up rdx
99 mov (up
), %rax C shared for mul_1
and mul_2
100 lea (up
,un_param
,8), up C point at operand
end
101 lea (rp
,un_param
,8), rp C point at rp
[un
-1]
103 mov (vp
), v0 C shared for mul_1
and mul_2
104 mul v0 C shared for mul_1
and mul_2
113 L
(m1x0
):mov %rax
, w0 C un
= 2, 4, 6, 8, ...
119 L
(m100
):lea 2(un
), n C un
= 4, 8, 12, ...
122 L
(m110
):lea (un
), n C un
= 2, 6, 10, ...
125 L
(m1x1
):mov %rax
, w1 C un
= 1, 3, 5, 7, ...
130 L
(m101
):lea 3(un
), n C un
= 1, 5, 9, ...
140 L
(m111
):lea 1(un
), n C un
= 3, 7, 11, ...
147 L
(m1l1
):mov -16(up
,n
,8), %rax
174 mov w1
, I
(-8(rp
),-24(rp
,n
,8))
175 mov %rdx
, I
((rp
),-16(rp
,n
,8))
216 L
(m2l1
):mov -8(up
,n
,8), %rax
230 L
(m2l0
):mov (up
,n
,8), %rax
245 mov I
(-8(up
),-8(up
,n
,8)), %rax
250 mov w0
, I
(-8(rp
),-8(rp
,n
,8))
253 mov w2
, I
((rp
),(rp
,n
,8))
255 mov %rdx
, I
(8(rp
),8(rp
,n
,8))
265 push vn C save vn
in new stack slot
266 define
(`vn
', `(%rsp)')
279 L
(a1x0
):mov (rp
,un
,8), X0
285 L
(a100
):lea 2(un
), n C un
= 4, 8, 12, ...
293 L
(a110
):lea (un
), n C un
= 2, 6, 10, ...
297 L
(a1x1
):mov (rp
,un
,8), X1
303 L
(a101
):lea 3(un
), n C un
= 1, 5, 9, ...
311 L
(a111
):lea 1(un
), n C un
= 3, 7, 11, ...
323 mov -16(up
,n
,8), %rax
328 mov -16(up
,n
,8), %rax
377 mov 16(rp
,n
,8), X0 C useless but harmless
in final iter
387 mov X1
, I
(-8(rp
),-24(rp
,n
,8))
390 mov %rax
, I
((rp
),-16(rp
,n
,8))
391 mov %rdx
, I
(8(rp
),-8(rp
,n
,8))
398 pop %rax C deallocate vn slot