summaryrefslogtreecommitdiff
path: root/mpn/x86_64/sub_n.asm
blob: 7ef17ab3a96505006367b15cb622df508a79b684 (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
dnl  AMD64 mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
dnl  store difference in a third limb vector.

dnl  Copyright 2003, 2004, 2005, 2007 Free Software Foundation, Inc.

dnl  This file is part of the GNU MP Library.

dnl  The GNU MP Library is free software; you can redistribute it and/or modify
dnl  it under the terms of the GNU Lesser General Public License as published
dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
dnl  your option) any later version.

dnl  The GNU MP Library is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
dnl  License for more details.

dnl  You should have received a copy of the GNU Lesser General Public License
dnl  along with the GNU MP Library; see the file COPYING.LIB.  If not, write
dnl  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
dnl  Boston, MA 02110-1301, USA.

include(`../config.m4')


C	    cycles/limb
C K8:		1.69
C P4:		11
C P6-15:	5.0

MULFUNC_PROLOGUE(mpn_sub_n mpn_sub_nc)

C INPUT PARAMETERS
C rp	rdi
C up	rsi
C vp	rdx
C n	rcx
C cy	r8		(only for mpn_sub_nc)

	TEXT
	ALIGN(16)
ASM_START()
PROLOGUE(mpn_sub_nc)
	movq	%rcx, %r10		C				3
	andl	$3, %r10d		C				4
	shrq	$2, %rcx		C				4
	bt	$0, %r8			C cy flag <- carry parameter	5
	je	.L0			C				2
	jmp	.Loop			C				2
EPILOGUE()
PROLOGUE(mpn_sub_n)
	movq	%rcx, %r10		C				3
	shrq	$2, %rcx		C				4
	je	.Lend			C				2
	andl	$3, %r10d		C				4

C Main loop.  1 mod 16 aligned.  Blocks between blank lines take one cycle.
.Loop:	movq	(%rsi), %rax		C				3
	movq	8(%rsi), %r9		C				4
	leaq	32(%rsi), %rsi		C				4

	sbbq	(%rdx), %rax		C				3
	movq	%rax, (%rdi)		C				3

	sbbq	8(%rdx), %r9		C				4
	movq	%r9, 8(%rdi)		C				4

	movq	-16(%rsi), %rax		C				4
	movq	-8(%rsi), %r9		C				4

	sbbq	16(%rdx), %rax		C				4
	movq	%rax, 16(%rdi)		C				4

	sbbq	24(%rdx), %r9		C				4
	movq	%r9, 24(%rdi)		C				4
	decq	%rcx			C				3

	leaq	32(%rdx), %rdx		C				4
	leaq	32(%rdi), %rdi		C				4
	jne	.Loop			C				2


	incl	%r10d			C				3
	decl	%r10d			C				3
	jne	.L0			C				2

	sbbl	%eax,%eax		C				2
	negl	%eax			C				2
	ret				C				1

.Lend:	testl	%eax, %eax		C clear cy			2
.L0:	decl	%r10d			C				3
	jne	.L1			C				2

	movq	(%rsi), %rax		C				3
	sbbq	(%rdx), %rax		C				3
	movq	%rax, (%rdi)		C				3
	sbbl	%eax,%eax		C				2
	negl	%eax			C				2
	ret				C				1

.L1:	decl	%r10d			C				3
	jne	.L2			C				2

	movq	(%rsi), %rax		C				3
	movq	8(%rsi), %r9		C				4
	sbbq	(%rdx), %rax		C				3
	movq	%rax, (%rdi)		C				3
	sbbq	8(%rdx), %r9		C				4
	movq	%r9, 8(%rdi)		C				4
	sbbl	%eax,%eax		C				2
	negl	%eax			C				2
	ret				C				1

.L2:
	movq	(%rsi), %rax		C				3
	movq	8(%rsi), %r9		C				4
	sbbq	(%rdx), %rax		C				3
	movq	%rax, (%rdi)		C				3
	sbbq	8(%rdx), %r9		C				4
	movq	%r9, 8(%rdi)		C				4
	movq	16(%rsi), %rax		C				4
	sbbq	16(%rdx), %rax		C				4
	movq	%rax, 16(%rdi)		C				4
	sbbl	%eax,%eax		C				2
	negl	%eax			C				2
	ret				C				1
EPILOGUE()