Debian Codegraph @

msvc/gmp/mpn/amd64i/copyd.asm

raw
1
2 ; AMD64 mpn_copyd -- decrementing 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_copyd(
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_copyd
44
45 %ifdef DLL
46 export __gmpn_copyd
47 %endif
48
49 __gmpn_copyd:
50 movsxd s_len,r8d
51 cmp s_len,byte UNROLL_THRESHOLD
52 jge .2 ; if many limbs to move
53 dec s_len
54 jl .1
55 .0: mov rax,[s_ptr+s_len*8] ; short move via rax
56 mov [d_ptr+s_len*8],rax
57 dec s_len
58 jge .0 ; avoid single byte ret that
59 .1: rep ret ; interferes with branch prediction
60
61 .2: mov rax,s_ptr ; find relative alignment of
62 xor rax,d_ptr ; source and destination (min
63 test al,8
64 jnz .7 ; not 16 byte aligned
65 lea rax,[s_ptr+s_len*8]
66 test al,8 ; see if src is on 16 byte
67 jz .3 ; boundary
68 dec s_len
69 mov rax,[rax-8] ; if not do a one limb copy
70 mov [d_ptr+s_len*8],rax
71 .3: lea s_len,[s_len-4] ; now 16 byte aligned
72 .4: prefetchnta [s_ptr+s_len*8+16-3*64] ; should this be -4*64 ??
73 movdqa xmm0,[s_ptr+s_len*8+16] ; move 32 bytes at a time
74 movntdq [d_ptr+s_len*8+16],xmm0
75 movdqa xmm0,[s_ptr+s_len*8]
76 movntdq [d_ptr+s_len*8],xmm0
77 sub s_len,4
78 jge .4
79 sfence
80 test s_len,2
81 jz .5
82 movdqa xmm0,[s_ptr+s_len*8+16] ; move 16 bytes if necessary
83 movdqa [d_ptr+s_len*8+16],xmm0
84 .5 test s_len,1
85 jz .6
86 movq xmm0,[s_ptr] ; move 8 bytes if necessary
87 movq [d_ptr],xmm0
88 .6: ret
89
90 .7: lea s_len,[s_len-2] ; move 8 bytes at a time
91 .8: movq xmm0,[s_ptr+s_len*8+8]
92 movq xmm1,[s_ptr+s_len*8]
93 movq [d_ptr+s_len*8+8],xmm0
94 movq [d_ptr+s_len*8],xmm1
95 sub s_len,2
96 jge .8
97 test s_len,1
98 jz .9
99 movq xmm0,[s_ptr]
100 movq [d_ptr],xmm0
101 .9: ret
102
103 end