1 dnl AMD K6-2 mpn_lshift -- mpn left shift.
3 dnl K6-2: 1.75 cycles/limb
6 dnl Copyright (C) 1999, 2000 Free Software Foundation, Inc.
8 dnl This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU Lesser General Public License as
12 dnl published by the Free Software Foundation; either version 2.1 of the
13 dnl License, or (at your option) any later version.
15 dnl The GNU MP Library is distributed in the hope that it will be useful,
16 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 dnl Lesser General Public License for more details.
20 dnl You should have received a copy of the GNU Lesser General Public
21 dnl License along with the GNU MP Library; see the file COPYING.LIB. If
22 dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
23 dnl Suite 330, Boston, MA 02111-1307, USA.
26 include(`../config.m4')
29 C mp_limb_t mpn_lshift (mp_ptr dst, mp_srcptr src, mp_size_t size,
33 defframe(PARAM_SHIFT,16)
34 defframe(PARAM_SIZE, 12)
35 defframe(PARAM_SRC, 8)
36 defframe(PARAM_DST, 4)
39 dnl used after src has been fetched
40 define(VAR_RETVAL,`PARAM_SRC')
42 dnl minimum 9, because unrolled loop can't handle less
43 deflit(UNROLL_THRESHOLD, 9)
51 C The 1 limb case can be done without the push %ebx, but it's then
52 C still the same speed. The push is left as a free helping hand for
53 C the two_or_more code.
56 pushl %ebx FRAME_pushl()
61 movl PARAM_SHIFT, %ecx
64 movl (%ebx), %edx C src limb
67 shldl( %cl, %edx, %eax) C return value
71 movl %edx, (%ebx) C dst limb
77 C -----------------------------------------------------------------------------
78 ALIGN(16) C avoid offset 0x1f
85 movl (%ebx,%eax,4), %edx C src high limb
88 movd PARAM_SHIFT, %mm6
89 addl $32, %ecx C 32-shift
92 cmpl $UNROLL_THRESHOLD-1, %eax
106 C ecx counter, size-1 to 1
113 movq -4(%ebx,%ecx,4), %mm0
117 Zdisp( movd, %mm0, 0,(%eax,%ecx,4))
133 C -----------------------------------------------------------------------------
139 C edx retval (but instead VAR_RETVAL is used)
147 subl $7, %eax C size-8
149 leal (%edx,%eax,4), %ecx C alignment of dst
151 movq 32-8(%ebx,%eax,4), %mm2 C src high qword
160 movd %mm2, 32(%edx,%eax,4) C dst high limb
161 movq 32-8(%ebx,%eax,4), %mm2 C new src high qword
164 movq 32-16(%ebx,%eax,4), %mm0 C src second highest qword
167 C This loop is the important bit, the rest is just support for it.
168 C Four src limbs are held at the start, and four more will be read.
169 C Four dst limbs will be written. This schedule seems necessary for
172 C The use of size-8 lets the loop stop when %eax goes negative and
173 C leaves -4 to -1 which can be tested with test $1 and $2.
176 C eax counter, size-8 step by -4 until <0
194 movq 24(%ebx,%eax,4), %mm0
197 movq %mm2, 40(%edx,%eax,4)
203 movq 16(%ebx,%eax,4), %mm0
205 movq %mm1, 32(%edx,%eax,4)
209 C Now have four limbs in mm2 (prev) and mm0 (next), plus eax mod 4.
211 C 8(%ebx) is the next source, and 24(%edx) is the next destination.
212 C %eax is between -4 and -1, representing respectively 0 to 3 extra
213 C limbs that must be read.
216 testl $2, %eax C testl to avoid bad cache line crossing
219 C Two more limbs: lshift mm2, OR it with rshifted mm0, mm0 becomes
220 C new mm2 and a new mm0 is loaded.
229 movq 16(%ebx,%eax,4), %mm0
231 movq %mm2, 32(%edx,%eax,4)
236 C lshift mm2, OR with rshifted mm0, mm1 becomes lshifted mm0
247 movq %mm2, 24(%edx,%eax,4)
251 C Size is odd, so mm1 and one extra limb to process.
253 movd (%ebx), %mm0 C src[0]
265 movq %mm1, 4(%edx) C dst[1,2]
266 movd %mm2, (%edx) C dst[0]
268 movl VAR_RETVAL, %eax
274 nop C avoid bad cache line crossing
277 C Size is even, so only mm1 left to process.
279 movq %mm1, (%edx) C dst[0,1]
280 movl VAR_RETVAL, %eax