3 * Copyright (C) 1992, 1994, 1998,
4 * 2001 Free Software Foundation, Inc.
6 * This file is part of GnuPG.
8 * GnuPG is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * GnuPG is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 * Note: This code is heavily based on the GNU MP Library.
24 * Actually it's the same code with only minor changes in the
25 * way the data is stored; this is to support the abstraction
26 * of an optional secure memory allocation which may be used
27 * to avoid revealing of sensitive data due to paging etc.
28 * The GNU MP Library itself is published under the LGPL;
29 * however I decided to publish this code under the plain GPL.
34 #include "asm-syntax.h"
40 * mpihelp_rshift( mpi_ptr_t wp, (sp + 4)
41 * mpi_ptr_t up, (sp + 8)
42 * mpi_size_t usize, (sp + 12)
43 * unsigned cnt) (sp + 16)
48 .globl C_SYMBOL_NAME(mpihelp_rshift)
49 C_SYMBOL_NAME(mpihelp_rshift:)
55 movl 20(%esp),%edi /* res_ptr */
56 movl 24(%esp),%esi /* s_ptr */
57 movl 28(%esp),%ebp /* size */
58 movl 32(%esp),%ecx /* cnt */
60 /* We can use faster code for shift-by-1 under certain conditions. */
65 jnc Rspecial /* jump if res_ptr + 1 >= s_ptr */
66 leal (%edi,%ebp,4),%eax
68 jnc Rspecial /* jump if s_ptr >= res_ptr + size */
74 shrdl %cl,%edx,%eax /* compute carry limb */
75 pushl %eax /* push carry limb onto stack */
82 movl (%edi),%eax /* fetch destination cache line */
85 Roop: movl 28(%edi),%eax /* fetch destination cache line */
124 Roop2: movl (%esi),%eax
125 shrdl %cl,%eax,%edx /* compute result limb */
133 Rend2: shrl %cl,%edx /* compute most significant limb */
134 movl %edx,(%edi) /* store it */
136 popl %eax /* pop carry limb */
144 /* We loop from least significant end of the arrays, which is only
145 permissable if the source and destination don't overlap, since the
146 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 /* fetch destination cache line */
168 RLoop: movl -28(%edi),%eax /* fetch destination cache line */
199 leal -32(%esi),%esi /* use leal not to clobber carry */
205 sbbl %eax,%eax /* save carry in %eax */
208 addl %eax,%eax /* restore carry from eax */
209 RLoop2: movl %edx,%ebx
214 leal -4(%esi),%esi /* use leal not to clobber carry */
220 RLend2: addl %eax,%eax /* restore carry from eax */
221 RL1: movl %edx,(%edi) /* store last limb */