1 dnl Intel Pentium mpn_rshift -- mpn right shift.
8 dnl Copyright (C) 1992, 1994, 1995, 1996, 1999, 2000 Free Software
11 dnl This file is part of the GNU MP Library.
13 dnl The GNU MP Library is free software; you can redistribute it and/or
14 dnl modify it under the terms of the GNU Lesser General Public License as
15 dnl published by the Free Software Foundation; either version 2.1 of the
16 dnl License, or (at your option) any later version.
18 dnl The GNU MP Library is distributed in the hope that it will be useful,
19 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
20 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 dnl Lesser General Public License for more details.
23 dnl You should have received a copy of the GNU Lesser General Public
24 dnl License along with the GNU MP Library; see the file COPYING.LIB. If
25 dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
26 dnl Suite 330, Boston, MA 02111-1307, USA.
29 include(`../config.m4')
32 C mp_limb_t mpn_rshift (mp_ptr dst, mp_srcptr src, mp_size_t size,
35 C The main shift-by-N loop should run at 5.375 c/l and that's what P55 does,
36 C but P5 and P54 run only at 6.0 c/l, which is 4 cycles lost somewhere.
38 defframe(PARAM_SHIFT,16)
39 defframe(PARAM_SIZE, 12)
40 defframe(PARAM_SRC, 8)
41 defframe(PARAM_DST, 4)
58 C We can use faster code for shift-by-1 under certain conditions.
63 jnc L(special) C jump if res_ptr + 1 >= s_ptr
64 leal (%edi,%ebp,4),%eax
66 jnc L(special) C jump if s_ptr >= res_ptr + size
72 shrdl( %cl, %edx, %eax) C compute carry limb
73 pushl %eax C push carry limb onto stack
80 movl (%edi),%eax C fetch destination cache line
83 L(oop): movl 28(%edi),%eax C fetch destination cache line
88 shrdl( %cl, %eax, %ebx)
89 shrdl( %cl, %edx, %eax)
95 shrdl( %cl, %ebx, %edx)
96 shrdl( %cl, %eax, %ebx)
102 shrdl( %cl, %edx, %eax)
103 shrdl( %cl, %ebx, %edx)
109 shrdl( %cl, %eax, %ebx)
110 shrdl( %cl, %edx, %eax)
124 shrdl( %cl,%eax,%edx) C compute result limb
133 shrl %cl,%edx C compute most significant limb
134 movl %edx,(%edi) C store it
136 popl %eax C pop carry limb
145 C We loop from least significant end of the arrays, which is only
146 C permissable if the source and destination don't overlap, since the
147 C function is documented to work for overlapping source and destination.
150 leal -4(%edi,%ebp,4),%edi
151 leal -4(%esi,%ebp,4),%esi
165 movl (%edi),%eax C fetch destination cache line
169 movl -28(%edi),%eax C fetch destination cache line
200 leal -32(%esi),%esi C use leal not to clobber carry
207 sbbl %eax,%eax C save carry in %eax
210 addl %eax,%eax C restore carry from eax
217 leal -4(%esi),%esi C use leal not to clobber carry
224 addl %eax,%eax C restore carry from eax
225 L(L1): movl %edx,(%edi) C store last limb