3 * Copyright (C) 1992, 1994, 1998,
4 * 2001, 2002 Free Software Foundation, Inc.
6 * This file is part of Libgcrypt.
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * Libgcrypt 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 * Note: This code is heavily based on the GNU MP Library.
23 * Actually it's the same code with only minor changes in the
24 * way the data is stored; this is to support the abstraction
25 * of an optional secure memory allocation which may be used
26 * to avoid revealing of sensitive data due to paging etc.
31 #include "asm-syntax.h"
36 * _gcry_mpih_lshift( mpi_ptr_t wp, (sp + 4)
37 * mpi_ptr_t up, (sp + 8)
38 * mpi_size_t usize, (sp + 12)
39 * unsigned cnt) (sp + 16)
44 .globl C_SYMBOL_NAME(_gcry_mpih_lshift)
45 C_SYMBOL_NAME(_gcry_mpih_lshift:)
52 movl 20(%esp),%edi /* res_ptr */
53 movl 24(%esp),%esi /* s_ptr */
54 movl 28(%esp),%ebp /* size */
55 movl 32(%esp),%ecx /* cnt */
57 /* We can use faster code for shift-by-1 under certain conditions. */
62 jnc Lspecial /* jump if s_ptr + 1 >= res_ptr */
63 leal (%esi,%ebp,4),%eax
65 jnc Lspecial /* jump if res_ptr >= s_ptr + size */
68 leal -4(%edi,%ebp,4),%edi
69 leal -4(%esi,%ebp,4),%esi
74 shldl %cl,%edx,%eax /* compute carry limb */
75 pushl %eax /* push carry limb onto stack */
82 movl (%edi),%eax /* fetch destination cache line */
85 Loop: movl -28(%edi),%eax /* fetch destination cache line */
124 Loop2: movl (%esi),%eax
133 Lend2: shll %cl,%edx /* compute least 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.
162 movl (%edi),%eax /* fetch destination cache line */
165 LLoop: movl 28(%edi),%eax /* fetch destination cache line */
196 leal 32(%esi),%esi /* use leal not to clobber carry */
202 sbbl %eax,%eax /* save carry in %eax */
205 addl %eax,%eax /* restore carry from eax */
206 LLoop2: movl %edx,%ebx
211 leal 4(%esi),%esi /* use leal not to clobber carry */
217 LLend2: addl %eax,%eax /* restore carry from eax */
218 LL1: movl %edx,(%edi) /* store last limb */