1dnl  AMD64 mpn_lshift -- mpn left shift, optimised for Atom.
2
3dnl  Contributed to the GNU project by Torbjorn Granlund.
4
5dnl  Copyright 2011, 2012 Free Software Foundation, Inc.
6
7dnl  This file is part of the GNU MP Library.
8dnl
9dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10dnl  it under the terms of either:
11dnl
12dnl    * the GNU Lesser General Public License as published by the Free
13dnl      Software Foundation; either version 3 of the License, or (at your
14dnl      option) any later version.
15dnl
16dnl  or
17dnl
18dnl    * the GNU General Public License as published by the Free Software
19dnl      Foundation; either version 2 of the License, or (at your option) any
20dnl      later version.
21dnl
22dnl  or both in parallel, as here.
23dnl
24dnl  The GNU MP Library is distributed in the hope that it will be useful, but
25dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27dnl  for more details.
28dnl
29dnl  You should have received copies of the GNU General Public License and the
30dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
31dnl  see https://www.gnu.org/licenses/.
32
33include(`../config.m4')
34
35C	     cycles/limb
36C AMD K8,K9	 ?
37C AMD K10	 ?
38C Intel P4	 ?
39C Intel core2	 ?
40C Intel NHM	 ?
41C Intel SBR	 ?
42C Intel atom	 4.5
43C VIA nano	 ?
44
45C TODO
46C  * Consider using 4-way unrolling.  We reach 4 c/l, but the code is 2.5 times
47C    larger.
48
49C INPUT PARAMETERS
50define(`rp',	`%rdi')
51define(`up',	`%rsi')
52define(`n',	`%rdx')
53define(`cnt',	`%rcx')
54
55ABI_SUPPORT(DOS64)
56ABI_SUPPORT(STD64)
57
58ASM_START()
59	TEXT
60	ALIGN(16)
61PROLOGUE(mpn_lshift)
62	FUNC_ENTRY(4)
63	lea	-8(up,n,8), up
64	lea	-8(rp,n,8), rp
65	shr	R32(n)
66	mov	(up), %rax
67	jnc	L(evn)
68
69	mov	%rax, %r11
70	shl	R8(%rcx), %r11
71	neg	R8(%rcx)
72	shr	R8(%rcx), %rax
73	test	n, n
74	jnz	L(gt1)
75	mov	%r11, (rp)
76	FUNC_EXIT()
77	ret
78
79L(gt1):	mov	-8(up), %r8
80	mov	%r8, %r10
81	shr	R8(%rcx), %r8
82	jmp	L(lo1)
83
84L(evn):	mov	%rax, %r10
85	neg	R8(%rcx)
86	shr	R8(%rcx), %rax
87	mov	-8(up), %r9
88	mov	%r9, %r11
89	shr	R8(%rcx), %r9
90	neg	R8(%rcx)
91	dec	n
92	lea	8(rp), rp
93	lea	-8(up), up
94	jz	L(end)
95
96	ALIGN(8)
97L(top):	shl	R8(%rcx), %r10
98	or	%r10, %r9
99	shl	R8(%rcx), %r11
100	neg	R8(%rcx)
101	mov	-8(up), %r8
102	mov	%r8, %r10
103	mov	%r9, -8(rp)
104	shr	R8(%rcx), %r8
105	lea	-16(rp), rp
106L(lo1):	mov	-16(up), %r9
107	or	%r11, %r8
108	mov	%r9, %r11
109	shr	R8(%rcx), %r9
110	lea	-16(up), up
111	neg	R8(%rcx)
112	mov	%r8, (rp)
113	dec	n
114	jg	L(top)
115
116L(end):	shl	R8(%rcx), %r10
117	or	%r10, %r9
118	shl	R8(%rcx), %r11
119	mov	%r9, -8(rp)
120	mov	%r11, -16(rp)
121	FUNC_EXIT()
122	ret
123EPILOGUE()
124