| 1 |
|
| 2 |
; AMD64 mpn_copyi -- incrementing copy limb vector |
| 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 |
; Provided by Brian Gladman AMD64 using the Microsoft VC++ v8 64-bit |
| 24 |
; compiler and the YASM assembler. |
| 25 |
; |
| 26 |
; Calling interface: |
| 27 |
; |
| 28 |
; void mpn_copyi( |
| 29 |
; mp_ptr dst, rcx |
| 30 |
; mp_srcptr src, rdx |
| 31 |
; mp_size_t size r8 |
| 32 |
; ) |
| 33 |
|
| 34 |
%define UNROLL_THRESHOLD 16 |
| 35 |
|
| 36 |
%define d_ptr rcx |
| 37 |
%define s_ptr rdx |
| 38 |
%define s_len r8 |
| 39 |
|
| 40 |
bits 64 |
| 41 |
text |
| 42 |
|
| 43 |
global __gmpn_copyi |
| 44 |
|
| 45 |
%ifdef DLL |
| 46 |
export __gmpn_copyi |
| 47 |
%endif |
| 48 |
|
| 49 |
__gmpn_copyi: |
| 50 |
movsxd s_len,r8d |
| 51 |
or s_len,s_len ; none to move? |
| 52 |
jz .1 |
| 53 |
mov rax,s_ptr ; find relative alignment of |
| 54 |
xor rax,d_ptr ; source and destination (min |
| 55 |
mov r9,s_ptr ; 8-byte alignment assumed) |
| 56 |
lea s_ptr,[s_ptr+s_len*8] |
| 57 |
lea d_ptr,[d_ptr+s_len*8] |
| 58 |
neg s_len |
| 59 |
cmp s_len,byte -UNROLL_THRESHOLD |
| 60 |
jbe .2 ; if many limbs to move |
| 61 |
.0: mov rax,[s_ptr+s_len*8] ; short move via rax |
| 62 |
mov [d_ptr+s_len*8],rax |
| 63 |
inc s_len |
| 64 |
jnz .0 ; avoid single byte ret that |
| 65 |
.1: rep ret ; interferes with branch prediction |
| 66 |
|
| 67 |
.2: test al,8 |
| 68 |
jnz .7 ; not 16 byte aligned |
| 69 |
test r9,8 ; see if src is on 16 byte |
| 70 |
jz .3 ; boundary |
| 71 |
mov rax,[s_ptr+s_len*8] ; if not do a one limb copy |
| 72 |
mov [d_ptr+s_len*8],rax |
| 73 |
inc s_len |
| 74 |
.3: lea s_len,[s_len+3] ; now 16 byte aligned |
| 75 |
.4: prefetchnta [s_ptr+s_len*8-24+3*64] ; should this be +4*64 ?? |
| 76 |
movdqa xmm0,[s_ptr+s_len*8-24] ; move 32 bytes at a time |
| 77 |
movntdq [d_ptr+s_len*8-24],xmm0 |
| 78 |
movdqa xmm0,[s_ptr+s_len*8-8] |
| 79 |
movntdq [d_ptr+s_len*8-8],xmm0 |
| 80 |
add s_len,4 |
| 81 |
jl .4 |
| 82 |
sfence |
| 83 |
test s_len,2 |
| 84 |
jnz .5 |
| 85 |
movdqa xmm0,[s_ptr+s_len*8-24] ; move 16 bytes if necessary |
| 86 |
movdqa [d_ptr+s_len*8-24],xmm0 |
| 87 |
add s_len,2 |
| 88 |
.5 test s_len,1 |
| 89 |
jnz .6 |
| 90 |
movq xmm0,[s_ptr+s_len*8-24] ; move 8 bytes if necessary |
| 91 |
movq [d_ptr+s_len*8-24],xmm0 |
| 92 |
.6: ret |
| 93 |
|
| 94 |
.7: lea s_len,[s_len+1] ; move 8 bytes at a time |
| 95 |
.8: movq xmm0,[s_ptr+s_len*8-8] |
| 96 |
movq xmm1,[s_ptr+s_len*8] |
| 97 |
movq [d_ptr+s_len*8-8],xmm0 |
| 98 |
movq [d_ptr+s_len*8],xmm1 |
| 99 |
add s_len,2 |
| 100 |
jl .8 |
| 101 |
test s_len,1 |
| 102 |
jnz .9 |
| 103 |
movq xmm0,[s_ptr-8] |
| 104 |
movq [d_ptr-8],xmm0 |
| 105 |
.9: ret |
| 106 |
|
| 107 |
end |