1 dnl AMD K6-2 mpn_lshift -- mpn left shift.
3 dnl Copyright 1999, 2000, 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
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
23 C K6-2: 1.75 cycles/limb
26 C mp_limb_t mpn_lshift (mp_ptr dst, mp_srcptr src, mp_size_t size,
30 defframe(PARAM_SHIFT,16)
31 defframe(PARAM_SIZE, 12)
32 defframe(PARAM_SRC, 8)
33 defframe(PARAM_DST, 4)
36 dnl used after src has been fetched
37 define(VAR_RETVAL,`PARAM_SRC')
39 dnl minimum 9, because unrolled loop can't handle less
40 deflit(UNROLL_THRESHOLD, 9)
48 C The 1 limb case can be done without the push %ebx, but it's then
49 C still the same speed. The push is left as a free helping hand for
50 C the two_or_more code.
53 pushl %ebx FRAME_pushl()
58 movl PARAM_SHIFT, %ecx
61 movl (%ebx), %edx C src limb
64 shldl( %cl, %edx, %eax) C return value
68 movl %edx, (%ebx) C dst limb
74 C -----------------------------------------------------------------------------
75 ALIGN(16) C avoid offset 0x1f
82 movl (%ebx,%eax,4), %edx C src high limb
85 movd PARAM_SHIFT, %mm6
86 addl $32, %ecx C 32-shift
89 cmpl $UNROLL_THRESHOLD-1, %eax
103 C ecx counter, size-1 to 1
110 movq -4(%ebx,%ecx,4), %mm0
114 Zdisp( movd, %mm0, 0,(%eax,%ecx,4))
130 C -----------------------------------------------------------------------------
136 C edx retval (but instead VAR_RETVAL is used)
144 subl $7, %eax C size-8
146 leal (%edx,%eax,4), %ecx C alignment of dst
148 movq 32-8(%ebx,%eax,4), %mm2 C src high qword
157 movd %mm2, 32(%edx,%eax,4) C dst high limb
158 movq 32-8(%ebx,%eax,4), %mm2 C new src high qword
161 movq 32-16(%ebx,%eax,4), %mm0 C src second highest qword
164 C This loop is the important bit, the rest is just support for it.
165 C Four src limbs are held at the start, and four more will be read.
166 C Four dst limbs will be written. This schedule seems necessary for
169 C The use of size-8 lets the loop stop when %eax goes negative and
170 C leaves -4 to -1 which can be tested with test $1 and $2.
173 C eax counter, size-8 step by -4 until <0
191 movq 24(%ebx,%eax,4), %mm0
194 movq %mm2, 40(%edx,%eax,4)
200 movq 16(%ebx,%eax,4), %mm0
202 movq %mm1, 32(%edx,%eax,4)
206 C Now have four limbs in mm2 (prev) and mm0 (next), plus eax mod 4.
208 C 8(%ebx) is the next source, and 24(%edx) is the next destination.
209 C %eax is between -4 and -1, representing respectively 0 to 3 extra
210 C limbs that must be read.
213 testl $2, %eax C testl to avoid bad cache line crossing
216 C Two more limbs: lshift mm2, OR it with rshifted mm0, mm0 becomes
217 C new mm2 and a new mm0 is loaded.
226 movq 16(%ebx,%eax,4), %mm0
228 movq %mm2, 32(%edx,%eax,4)
233 C lshift mm2, OR with rshifted mm0, mm1 becomes lshifted mm0
244 movq %mm2, 24(%edx,%eax,4)
248 C Size is odd, so mm1 and one extra limb to process.
250 movd (%ebx), %mm0 C src[0]
262 movq %mm1, 4(%edx) C dst[1,2]
263 movd %mm2, (%edx) C dst[0]
265 movl VAR_RETVAL, %eax
271 nop C avoid bad cache line crossing
274 C Size is even, so only mm1 left to process.
276 movq %mm1, (%edx) C dst[0,1]
277 movl VAR_RETVAL, %eax