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 (3) 44 .globl C_SYMBOL_NAME(_gcry_mpih_rshift) 45C_SYMBOL_NAME(_gcry_mpih_rshift:) 46 pushl %edi 47 pushl %esi 48 pushl %ebx 49 50 movl 16(%esp),%edi /* wp */ 51 movl 20(%esp),%esi /* up */ 52 movl 24(%esp),%edx /* usize */ 53 movl 28(%esp),%ecx /* cnt */ 54 55 leal -4(%edi,%edx,4),%edi 56 leal (%esi,%edx,4),%esi 57 negl %edx 58 59 movl (%esi,%edx,4),%ebx /* read least significant limb */ 60 xorl %eax,%eax 61 shrdl %cl,%ebx,%eax /* compute carry limb */ 62 incl %edx 63 jz Lend2 64 pushl %eax /* push carry limb onto stack */ 65 testb $1,%dl 66 jnz L2 /* enter loop in the middle */ 67 movl %ebx,%eax 68 69 ALIGN (3) 70Loop2: movl (%esi,%edx,4),%ebx /* load next higher limb */ 71 shrdl %cl,%ebx,%eax /* compute result limb */ 72 movl %eax,(%edi,%edx,4) /* store it */ 73 incl %edx 74L2: movl (%esi,%edx,4),%eax 75 shrdl %cl,%eax,%ebx 76 movl %ebx,(%edi,%edx,4) 77 incl %edx 78 jnz Loop2 79 80 shrl %cl,%eax /* compute most significant limb */ 81 movl %eax,(%edi) /* store it */ 82 83 popl %eax /* pop carry limb */ 84 85 popl %ebx 86 popl %esi 87 popl %edi 88 ret 89 90Lend2: shrl %cl,%ebx /* compute most significant limb */ 91 movl %ebx,(%edi) /* store it */ 92 93 popl %ebx 94 popl %esi 95 popl %edi 96 ret 97 98