| 1 |
|
| 2 |
; AMD64 mpn_rshift -- mpn right shift |
| 3 |
; |
| 4 |
; Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
| 5 |
; |
| 6 |
; This file is part of the GNU MP Library. |
| 7 |
; |
| 8 |
; The GNU MP Library is free software; you can redistribute it and/or |
| 9 |
; modify it under the terms of the GNU Lesser General Public License as |
| 10 |
; published by the Free Software Foundation; either version 2.1 of the |
| 11 |
; License, or (at your option) any later version. |
| 12 |
; |
| 13 |
; The GNU MP Library 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 GNU |
| 16 |
; 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 the GNU MP Library; see the file COPYING.LIB. If |
| 20 |
; not, write to the Free Software Foundation, Inc., 59 Temple Place - |
| 21 |
; Suite 330, Boston, MA 02111-1307, USA. |
| 22 |
; |
| 23 |
; Adapted by Brian Gladman AMD64 using the Microsoft VC++ v8 64-bit |
| 24 |
; compiler and the YASM assembler. |
| 25 |
; |
| 26 |
; Calling interface: |
| 27 |
; |
| 28 |
; mp_limb_t mpn_rshift( |
| 29 |
; mp_ptr dst, rcx |
| 30 |
; mp_srcptr src, rdx |
| 31 |
; mp_size_t size, r8 |
| 32 |
; unsigned shift r9 |
| 33 |
; ) |
| 34 |
|
| 35 |
%define s_len r8 |
| 36 |
%define r_tmp r9 |
| 37 |
%define d_ptr r10 |
| 38 |
%define s_ptr r11 |
| 39 |
|
| 40 |
bits 64 |
| 41 |
text |
| 42 |
|
| 43 |
global __gmpn_rshift |
| 44 |
|
| 45 |
%ifdef DLL |
| 46 |
export __gmpn_rshift |
| 47 |
%endif |
| 48 |
|
| 49 |
__gmpn_rshift: |
| 50 |
movsxd s_len,r8d |
| 51 |
or s_len,s_len |
| 52 |
jz .0 |
| 53 |
mov d_ptr,rcx |
| 54 |
mov s_ptr,rdx |
| 55 |
mov rcx,r9 |
| 56 |
cmp s_len,byte 2 |
| 57 |
jge .1 |
| 58 |
mov rax,[s_ptr] |
| 59 |
mov r_tmp,rax |
| 60 |
shr r_tmp,cl |
| 61 |
neg cl |
| 62 |
mov [d_ptr],r_tmp |
| 63 |
shl rax,cl |
| 64 |
.0: ret |
| 65 |
.1: lea s_ptr,[s_ptr+s_len*8] |
| 66 |
lea d_ptr,[d_ptr+s_len*8] |
| 67 |
neg s_len |
| 68 |
mov rdx,[s_ptr+s_len*8] |
| 69 |
push rdx |
| 70 |
shr rdx,cl |
| 71 |
neg cl |
| 72 |
inc s_len |
| 73 |
.2: mov rax,[s_ptr+s_len*8] |
| 74 |
mov r_tmp,rax |
| 75 |
shl r_tmp,cl |
| 76 |
neg cl |
| 77 |
xor r_tmp,rdx |
| 78 |
shr rax,cl |
| 79 |
neg cl |
| 80 |
mov rdx,rax |
| 81 |
mov [d_ptr+s_len*8-8],r_tmp |
| 82 |
inc s_len |
| 83 |
jnz .2 |
| 84 |
mov [d_ptr-8],rax |
| 85 |
pop rax |
| 86 |
shl rax,cl |
| 87 |
ret |