summaryrefslogtreecommitdiff
path: root/mpn/x86/k7/mmx/copyd.asm
blob: 1a9bfca0dd927cf672250b0844d2a56386314dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
dnl  AMD K7 mpn_copyd -- copy limb vector, decrementing.

dnl  Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
dnl
dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or
dnl  modify it under the terms of the GNU Lesser General Public License as
dnl  published by the Free Software Foundation; either version 2.1 of the
dnl  License, or (at your option) any later version.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful,
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl  Lesser General Public License for more details.
dnl
dnl  You should have received a copy of the GNU Lesser General Public
dnl  License along with the GNU MP Library; see the file COPYING.LIB.  If
dnl  not, write to the Free Software Foundation, Inc., 59 Temple Place -
dnl  Suite 330, Boston, MA 02111-1307, USA.

include(`../config.m4')


C    alignment dst/src, A=0mod8 N=4mod8
C       A/A   A/N   N/A   N/N
C K7    0.75  1.0   1.0   0.75


C void mpn_copyd (mp_ptr dst, mp_srcptr src, mp_size_t size);
C
C The various comments in mpn/x86/k7/copyi.asm apply here too.

defframe(PARAM_SIZE,12)
defframe(PARAM_SRC, 8)
defframe(PARAM_DST, 4)
deflit(`FRAME',0)

dnl  parameter space reused
define(SAVE_EBX,`PARAM_SIZE')
define(SAVE_ESI,`PARAM_SRC')

dnl  minimum 5 since the unrolled code can't handle less than 5
deflit(UNROLL_THRESHOLD, 5)

	TEXT
	ALIGN(32)
PROLOGUE(mpn_copyd)

	movl	PARAM_SIZE, %ecx
	movl	%ebx, SAVE_EBX

	movl	PARAM_SRC, %eax
	movl	PARAM_DST, %edx

	cmpl	$UNROLL_THRESHOLD, %ecx
	jae	L(unroll)

	orl	%ecx, %ecx
	jz	L(simple_done)

L(simple):
	C eax	src
	C ebx	scratch
	C ecx	counter
	C edx	dst
	C
	C this loop is 2 cycles/limb

	movl	-4(%eax,%ecx,4), %ebx
	movl	%ebx, -4(%edx,%ecx,4)
	decl	%ecx
	jnz	L(simple)

L(simple_done):
	movl	SAVE_EBX, %ebx
	ret


L(unroll):
	movl	%esi, SAVE_ESI
	leal	(%eax,%ecx,4), %ebx
	leal	(%edx,%ecx,4), %esi

	andl	%esi, %ebx
	movl	SAVE_ESI, %esi
	subl	$4, %ecx		C size-4

	testl	$4, %ebx   C testl to pad code closer to 16 bytes for L(top)
	jz	L(aligned)

	C both src and dst unaligned, process one limb to align them
	movl	12(%eax,%ecx,4), %ebx
	movl	%ebx, 12(%edx,%ecx,4)
	decl	%ecx
L(aligned):


	ALIGN(16)
L(top):
	C eax	src
	C ebx
	C ecx	counter, limbs
	C edx	dst

	movq	8(%eax,%ecx,4), %mm0
	movq	(%eax,%ecx,4), %mm1
	subl	$4, %ecx
	movq	%mm0, 16+8(%edx,%ecx,4)
	movq	%mm1, 16(%edx,%ecx,4)
	jns	L(top)


	C now %ecx is -4 to -1 representing respectively 0 to 3 limbs remaining

	testb	$2, %cl
	jz	L(finish_not_two)

	movq	8(%eax,%ecx,4), %mm0
	movq	%mm0, 8(%edx,%ecx,4)
L(finish_not_two):

	testb	$1, %cl
	jz	L(done)

	movl	(%eax), %ebx
	movl	%ebx, (%edx)

L(done):
	movl	SAVE_EBX, %ebx
	emms
	ret


EPILOGUE()