2008-06-25 03:33:36 -04:00
|
|
|
; Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|
|
|
;
|
2008-07-24 17:14:10 -04:00
|
|
|
; Copyright 2008 Brian Gladman, William Hart
|
2008-06-25 03:33:36 -04:00
|
|
|
;
|
2008-07-24 17:14:10 -04:00
|
|
|
; This file is part of the MPIR Library.
|
|
|
|
;
|
|
|
|
; The MPIR Library is free software; you can redistribute it and/or
|
2008-06-25 03:33:36 -04:00
|
|
|
; modify it under the terms of the GNU Lesser General Public License as
|
|
|
|
; published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
; License, or (at your option) any later version.
|
|
|
|
;
|
2008-07-24 17:14:10 -04:00
|
|
|
; The MPIR Library is distributed in the hope that it will be useful,
|
2008-06-25 03:33:36 -04:00
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
; Lesser General Public License for more details.
|
|
|
|
;
|
|
|
|
; You should have received a copy of the GNU Lesser General Public
|
2008-07-24 17:14:10 -04:00
|
|
|
; License along with the MPIR Library; see the file COPYING.LIB. If
|
|
|
|
; not, write to the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
; Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-06-25 03:33:36 -04:00
|
|
|
;
|
|
|
|
; Adapted by Brian Gladman AMD64 using the Microsoft VC++ v8 64-bit
|
|
|
|
; compiler and the YASM assembler.
|
|
|
|
|
|
|
|
; AMD64 mpn_rshift -- mpn right shift
|
|
|
|
;
|
2008-07-23 13:59:51 -04:00
|
|
|
; Calling interface:
|
2008-06-25 03:33:36 -04:00
|
|
|
;
|
|
|
|
; mp_limb_t mpn_rshift(
|
|
|
|
; mp_ptr dst, rdi
|
|
|
|
; mp_srcptr src, rsi
|
|
|
|
; mp_size_t size, rdx
|
|
|
|
; unsigned shift rcx
|
|
|
|
; )
|
|
|
|
|
2009-03-03 16:40:13 -05:00
|
|
|
%include 'yasm_mac.inc'
|
2008-06-25 03:33:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
%define src rsi
|
|
|
|
%define dst rdi
|
|
|
|
%define r_tmpd ecx
|
|
|
|
%define s_len rdx
|
|
|
|
|
2008-07-23 13:59:51 -04:00
|
|
|
BITS 64
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2008-07-23 13:59:51 -04:00
|
|
|
GLOBAL_FUNC mpn_rshift
|
2008-07-23 15:31:28 -04:00
|
|
|
movq mm7, [src] ; move bottom source into mm7
|
|
|
|
movd mm1, r_tmpd ; move shift value into mm1
|
2008-06-25 03:33:36 -04:00
|
|
|
mov eax, 64
|
|
|
|
sub eax, r_tmpd
|
2008-07-23 15:31:28 -04:00
|
|
|
movd mm0, eax ; and 64 - shift value into mm0
|
|
|
|
movq mm3, mm7 ; save mm7 in mm3
|
|
|
|
psllq mm7, mm0 ; do shift
|
|
|
|
movd rax, mm7 ; put remainder after shift into rax for return
|
|
|
|
lea src, [src+s_len*8]
|
2008-06-25 03:33:36 -04:00
|
|
|
lea dst, [dst+s_len*8]
|
|
|
|
neg s_len
|
|
|
|
add s_len, 2
|
2008-07-23 13:59:51 -04:00
|
|
|
jg label1
|
2008-06-25 03:33:36 -04:00
|
|
|
|
|
|
|
align 8
|
2008-07-23 13:59:51 -04:00
|
|
|
label0:
|
2008-07-23 15:31:28 -04:00
|
|
|
movq mm6, [src+s_len*8-8] ; load next source chunk
|
|
|
|
movq mm2, mm6 ; copy it
|
|
|
|
psllq mm6, mm0 ; shift left
|
|
|
|
psrlq mm3, mm1 ; and right
|
|
|
|
por mm3, mm6 ; and combine
|
|
|
|
movq [dst+s_len*8-16], mm3 ; store result
|
2008-07-23 13:59:51 -04:00
|
|
|
je label2
|
2008-07-23 15:31:28 -04:00
|
|
|
movq mm7, [src+s_len*8] ; next source chunk
|
|
|
|
movq mm3, mm7 ; save it
|
|
|
|
psllq mm7, mm0 ; shift left
|
|
|
|
psrlq mm2, mm1 ; and right
|
|
|
|
por mm2, mm7 ; and combine
|
|
|
|
movq [dst+s_len*8-8], mm2 ; store result
|
2008-06-25 03:33:36 -04:00
|
|
|
add s_len, 2
|
2008-07-23 13:59:51 -04:00
|
|
|
jle label0
|
|
|
|
label1:
|
|
|
|
movq mm2, mm3
|
|
|
|
label2:
|
2008-07-23 15:31:28 -04:00
|
|
|
psrlq mm2, mm1 ; final shift
|
|
|
|
movq [dst-8], mm2 ; and store
|
2008-06-25 03:33:36 -04:00
|
|
|
emms
|
|
|
|
ret
|