aorsmul_1.asm revision 1.1.1.1
1dnl  x86-64 mpn_addmul_1 and mpn_submul_1, optimized for "Core 2".
2
3dnl  Copyright 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4
5dnl  This file is part of the GNU MP Library.
6
7dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8dnl  it under the terms of the GNU Lesser General Public License as published
9dnl  by the Free Software Foundation; either version 3 of the License, or (at
10dnl  your option) any later version.
11
12dnl  The GNU MP Library is distributed in the hope that it will be useful, but
13dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15dnl  License for more details.
16
17dnl  You should have received a copy of the GNU Lesser General Public License
18dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
19
20include(`../config.m4')
21
22C	     cycles/limb
23C K8,K9:	 4
24C K10:		 4
25C P4:		 ?
26C P6 core2:	 4.3-4.5 (fluctuating)
27C P6 corei7:	 5
28
29C INPUT PARAMETERS
30define(`rp',	`%rdi')
31define(`up',	`%rsi')
32define(`n',	`%rdx')
33define(`v0',	`%rcx')
34
35ifdef(`OPERATION_addmul_1',`
36      define(`ADDSUB',        `add')
37      define(`func',  `mpn_addmul_1')
38')
39ifdef(`OPERATION_submul_1',`
40      define(`ADDSUB',        `sub')
41      define(`func',  `mpn_submul_1')
42')
43
44MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
45
46ASM_START()
47	TEXT
48	ALIGN(16)
49PROLOGUE(func)
50	push	%rbx
51	push	%rbp
52	lea	(%rdx), %rbx
53	neg	%rbx
54
55	mov	(up), %rax
56	mov	(rp), %r10
57
58	lea	-16(rp,%rdx,8), rp
59	lea	(up,%rdx,8), up
60	mul	%rcx
61
62	bt	$0, R32(%rbx)
63	jc	L(odd)
64
65	lea	(%rax), %r11
66	mov	8(up,%rbx,8), %rax
67	lea	(%rdx), %rbp
68	mul	%rcx
69	add	$2, %rbx
70	jns	L(n2)
71
72	lea	(%rax), %r8
73	mov	(up,%rbx,8), %rax
74	lea	(%rdx), %r9
75	jmp	L(mid)
76
77L(odd):	add	$1, %rbx
78	jns	L(n1)
79
80	lea	(%rax), %r8
81	mov	(up,%rbx,8), %rax
82	lea	(%rdx), %r9
83	mul	%rcx
84	lea	(%rax), %r11
85	mov	8(up,%rbx,8), %rax
86	lea	(%rdx), %rbp
87	jmp	L(e)
88
89	ALIGN(16)
90L(top):	mul	%rcx
91	ADDSUB	%r8, %r10
92	lea	(%rax), %r8
93	mov	(up,%rbx,8), %rax
94	adc	%r9, %r11
95	mov	%r10, -8(rp,%rbx,8)
96	mov	(rp,%rbx,8), %r10
97	lea	(%rdx), %r9
98	adc	$0, %rbp
99L(mid):	mul	%rcx
100	ADDSUB	%r11, %r10
101	lea	(%rax), %r11
102	mov	8(up,%rbx,8), %rax
103	adc	%rbp, %r8
104	mov	%r10, (rp,%rbx,8)
105	mov	8(rp,%rbx,8), %r10
106	lea	(%rdx), %rbp
107	adc	$0, %r9
108L(e):	add	$2, %rbx
109	js	L(top)
110
111	mul	%rcx
112	ADDSUB	%r8, %r10
113	adc	%r9, %r11
114	mov	%r10, -8(rp)
115	adc	$0, %rbp
116L(n2):	mov	(rp), %r10
117	ADDSUB	%r11, %r10
118	adc	%rbp, %rax
119	mov	%r10, (rp)
120	adc	$0, %rdx
121L(n1):	mov	8(rp), %r10
122	ADDSUB	%rax, %r10
123	mov	%r10, 8(rp)
124	mov	R32(%rbx), R32(%rax)	C zero rax
125	adc	%rdx, %rax
126	pop	%rbp
127	pop	%rbx
128	ret
129EPILOGUE()
130