1/* i80386   rshift
2 *
3 *      Copyright (C) 1992, 1994, 1998,
4 *                    2001, 2002 Free Software Foundation, Inc.
5 *
6 * This file is part of Libgcrypt.
7 *
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.
12 *
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.
17 *
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
21 *
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.
27 */
28
29
30#include "sysdep.h"
31#include "asm-syntax.h"
32
33
34/*******************
35 * mpi_limb_t
36 * _gcry_mpih_rshift( 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)
40 */
41
42.text
43	ALIGN (2)
44	.globl C_SYMBOL_NAME(_gcry_mpih_rshift)
45C_SYMBOL_NAME(_gcry_mpih_rshift:)
46	CFI_STARTPROC()
47	pushl	%edi
48	CFI_PUSH(%edi)
49	pushl	%esi
50	CFI_PUSH(%esi)
51	pushl	%ebx
52	CFI_PUSH(%ebx)
53
54	movl	16(%esp),%edi		/* wp */
55	movl	20(%esp),%esi		/* up */
56	movl	24(%esp),%edx		/* usize */
57	movl	28(%esp),%ecx		/* cnt */
58
59	leal	-4(%edi,%edx,4),%edi
60	leal	(%esi,%edx,4),%esi
61	negl	%edx
62
63	movl	(%esi,%edx,4),%ebx	/* read least significant limb */
64	xorl	%eax,%eax
65	shrdl	%cl,%ebx,%eax		/* compute carry limb */
66	incl	%edx
67	jz	Lend2
68	pushl	%eax			/* push carry limb onto stack */
69	testb	$1,%dl
70	jnz	L2			/* enter loop in the middle */
71	movl	%ebx,%eax
72
73	ALIGN (2)
74Loop2:	movl	 (%esi,%edx,4),%ebx	/* load next higher limb */
75	shrdl	%cl,%ebx,%eax		/* compute result limb */
76	movl	%eax,(%edi,%edx,4)	/* store it */
77	incl	%edx
78L2:	movl	(%esi,%edx,4),%eax
79	shrdl	%cl,%eax,%ebx
80	movl	%ebx,(%edi,%edx,4)
81	incl	%edx
82	jnz	Loop2
83
84	shrl	%cl,%eax		/* compute most significant limb */
85	movl	%eax,(%edi)		/* store it */
86
87	popl	%eax			/* pop carry limb */
88
89	popl	%ebx
90	popl	%esi
91	popl	%edi
92	ret
93
94Lend2:	shrl	%cl,%ebx		/* compute most significant limb */
95	movl	%ebx,(%edi)		/* store it */
96
97	popl	%ebx
98	CFI_POP(%ebx)
99	popl	%esi
100	CFI_POP(%esi)
101	popl	%edi
102	CFI_POP(%edi)
103	ret
104	CFI_ENDPROC()
105
106