1 dnl Intel Pentium
-4 mpn_rsh1add_n
-- mpn
(x
+y
)/2
3 dnl Copyright
2001-2004 Free Software Foundation
, Inc.
5 dnl
This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
8 dnl it under the terms of
either:
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.
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
20 dnl
or both
in parallel
, as here.
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
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
/.
31 include(`..
/config.m4
')
34 C cycles/limb (approx)
35 C dst!=src1,2 dst==src1 dst==src2
39 C mp_limb_t mpn_rsh1add_n (mp_ptr wp, mp_srcptr xp, mp_srcptr yp,
42 C The slightly strange combination of indexing and pointer incrementing
43 C that's used seems to work best.
Not sure why
, but for instance leal
44 C incrementing on
%esi is a
1 or 2 cycle slowdown.
46 C The dependent chain is paddq combining the carry
and next
(shifted
) part
,
47 C plus psrlq to move the new carry down. That
, and just
4 mmx instructions
48 C
in total
, makes
4 c
/l the target speed
, which is almost achieved for
49 C separate src
/dst but when src
==dst the write combining anomalies slow it
52 defframe
(PARAM_SIZE
, 16)
53 defframe
(PARAM_YP
, 12)
57 dnl re
-use parameter space
58 define
(SAVE_EBX
,`PARAM_XP
')
59 define(SAVE_ESI,`PARAM_YP')
64 PROLOGUE
(mpn_rsh1add_n
)
75 movd (%edx), %mm0 C xp[0]
77 movd (%ebx), %mm1 C yp[0]
80 movl (%edx), %eax C xp[0]
82 addl (%ebx), %eax C xp[0]+yp[0]
84 paddq %mm1, %mm0 C xp[0]+yp[0]
85 leal (%esi,%ecx,4), %esi C wp end
88 psrlq $1, %mm0 C (xp[0]+yp[0])/2
89 and $1, %eax C return value, rsh1 bit of xp[0]+yp[0]
90 addl $1, %ecx C -(size-1)
97 C ecx counter, limbs, -(size-1) to -1 inclusive
100 C mm0 carry (32 bits)
102 movd 4(%edx), %mm1 C xp[i+1]
103 movd 4(%ebx), %mm2 C yp[i+1]
106 paddq %mm2, %mm1 C xp[i+1]+yp[i+1]
107 psllq $31, %mm1 C low bit at 31, further 32 above
109 paddq %mm1, %mm0 C 31 and carry from prev add
110 movd %mm0, -4(%esi,%ecx,4) C low ready to store dst[i]
112 psrlq $32, %mm0 C high becomes new carry
119 movd %mm0, -4(%esi) C dst[size-1]