1 dnl Intel P6 mpn_copyd
-- copy limb vector backwards.
3 dnl Copyright
2001, 2002 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 P6: 1.75 cycles/limb, or 0.75 if no overlap
37 C void mpn_copyd (mp_ptr dst, mp_srcptr src, mp_size_t size);
39 C An explicit loop is used because a decrementing rep movsl is a bit slow at
40 C 2.4 c/l. That rep movsl also has about a 40 cycle startup time, and the
41 C code here stands a chance of being faster if the branches predict well.
43 C The slightly strange loop form seems necessary for the claimed speed.
44 C Maybe load/store ordering affects it.
46 C The source and destination are checked to see if they're actually
47 C overlapping
, since it might be possible to use an incrementing
rep movsl
48 C at
0.75 c
/l.
(It doesn
't suffer the bad startup time of the decrementing
53 C Top speed for an all-integer copy is probably 1.0 c/l, being one load and
54 C one store each cycle. Unrolling the loop below would approach 1.0, but
55 C it'd be good to know why something like store
/load
/subl
+ store
/load
/jnz
56 C doesn
't already run at 1.0 c/l. It looks like it should decode in 2
57 C cycles, but doesn't run that way.
59 defframe
(PARAM_SIZE
,12)
60 defframe
(PARAM_SRC
, 8)
61 defframe
(PARAM_DST
, 4)
63 dnl re
-using parameter space
64 define
(SAVE_ESI
,`PARAM_SIZE
')
65 define(SAVE_EDI,`PARAM_SRC')
84 movl (%esi,%ecx,4), %eax C src[size-1]
87 movl -4(%esi,%ecx,4), %edx C src[size-2]
89 jbe L(done_loop) C 2 or 3 limbs only
92 C The usual overlap is
95 C +------------------+
97 C +------------------+
98 C +------------------+
100 C +------------------+
102 C We can use an incrementing copy in the following circumstances.
104 C src+4*size<=dst, since then the regions are disjoint
106 C src==dst, clearly (though this shouldn't occur normally
)
108 C src
>dst
, since
in that case it
's a requirement of the
109 C parameters that src>=dst+size*4, and hence the
110 C regions are disjoint
113 leal (%edi,%ecx,4), %edx
115 jae L(use_movsl) C src >= dst
118 movl 4(%esi,%ecx,4), %edx C src[size-2] again
119 jbe L(use_movsl) C src+4*size <= dst
125 C ecx counter, size-3 down to 0 or -1, inclusive, by 2s
131 movl %eax, 8(%edi,%ecx,4)
132 movl (%esi,%ecx,4), %eax
134 movl %edx, 4(%edi,%ecx,4)
135 movl -4(%esi,%ecx,4), %edx
142 movl %eax, 8(%edi,%ecx,4)
143 movl %edx, 4(%edi,%ecx,4)
145 C copy low limb (needed if size was odd, but will already have been
146 C done in the loop if size was even)
167 cld C better safe than sorry, see mpn/x86/README