1 dnl Intel Pentium mpn_rshift -- mpn right shift.
3 dnl Copyright 1992, 1994, 1995, 1996, 1999, 2000, 2002 Free Software
6 dnl This file is part of the GNU MP Library.
8 dnl The GNU MP Library is free software; you can redistribute it and/or
9 dnl modify it under the terms of the GNU Lesser General Public License as
10 dnl published by the Free Software Foundation; either version 3 of the
11 dnl License, or (at your option) any later version.
13 dnl The GNU MP Library is distributed in the hope that it will be useful,
14 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 dnl Lesser General Public License for more details.
18 dnl You should have received a copy of the GNU Lesser General Public License
19 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
21 include(`../config.m4')
29 C mp_limb_t mpn_rshift (mp_ptr dst, mp_srcptr src, mp_size_t size,
32 C The main shift-by-N loop should run at 5.375 c/l and that's what P55 does,
33 C but P5 and P54 run only at 6.0 c/l, which is 4 cycles lost somewhere.
35 defframe(PARAM_SHIFT,16)
36 defframe(PARAM_SIZE, 12)
37 defframe(PARAM_SRC, 8)
38 defframe(PARAM_DST, 4)
55 C We can use faster code for shift-by-1 under certain conditions.
60 jnc L(special) C jump if res_ptr + 1 >= s_ptr
61 leal (%edi,%ebp,4),%eax
63 jnc L(special) C jump if s_ptr >= res_ptr + size
69 shrdl( %cl, %edx, %eax) C compute carry limb
70 pushl %eax C push carry limb onto stack
77 movl (%edi),%eax C fetch destination cache line
80 L(oop): movl 28(%edi),%eax C fetch destination cache line
85 shrdl( %cl, %eax, %ebx)
86 shrdl( %cl, %edx, %eax)
92 shrdl( %cl, %ebx, %edx)
93 shrdl( %cl, %eax, %ebx)
99 shrdl( %cl, %edx, %eax)
100 shrdl( %cl, %ebx, %edx)
106 shrdl( %cl, %eax, %ebx)
107 shrdl( %cl, %edx, %eax)
121 shrdl( %cl,%eax,%edx) C compute result limb
130 shrl %cl,%edx C compute most significant limb
131 movl %edx,(%edi) C store it
133 popl %eax C pop carry limb
142 C We loop from least significant end of the arrays, which is only
143 C permissable if the source and destination don't overlap, since the
144 C function is documented to work for overlapping source and destination.
147 leal -4(%edi,%ebp,4),%edi
148 leal -4(%esi,%ebp,4),%esi
162 movl (%edi),%eax C fetch destination cache line
166 movl -28(%edi),%eax C fetch destination cache line
197 leal -32(%esi),%esi C use leal not to clobber carry
204 sbbl %eax,%eax C save carry in %eax
207 addl %eax,%eax C restore carry from eax
214 leal -4(%esi),%esi C use leal not to clobber carry
221 addl %eax,%eax C restore carry from eax
222 L(L1): movl %edx,(%edi) C store last limb