1dnl  SPARC v9 mpn_rshift
2
3dnl  Contributed to the GNU project by David Miller.
4
5dnl  Copyright 2013 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 UltraSPARC 1&2:	 2
37C UltraSPARC 3:		 2.5
38C UltraSPARC T1:	17.5
39C UltraSPARC T3:	 8
40C UltraSPARC T4:	 3
41
42C INPUT PARAMETERS
43define(`rp',     `%i0')
44define(`up',     `%i1')
45define(`n',      `%i2')
46define(`cnt',    `%i3')
47
48define(`tcnt',   `%i4')
49define(`retval', `%i5')
50define(`u0',     `%l0')
51define(`u1',     `%l1')
52define(`r0',     `%l6')
53define(`r1',     `%l7')
54define(`u0_off', `%o0')
55define(`u1_off', `%o1')
56define(`r0_off', `%o2')
57define(`r1_off', `%o3')
58
59ASM_START()
60	REGISTER(%g2,#scratch)
61	REGISTER(%g3,#scratch)
62PROLOGUE(mpn_rshift)
63	save	%sp, -176, %sp
64
65	sllx	n, 3, n
66	sub	%g0, cnt, tcnt
67
68	add	up, n, up
69	add	rp, n, rp
70
71	neg	n, n
72	sub	up, (2 * 8), u0_off
73	sub	rp, (5 * 8), r0_off
74
75	ldx	[n + up], u1		C WAS: up + 0
76	sub	u0_off, (1 * 8), u1_off
77	sub	r0_off, (1 * 8), r1_off
78
79	subcc	n, -(3 * 8), n
80	sllx	u1, tcnt, retval
81
82	bg,pn	%xcc, L(end12)
83	 srlx	u1, cnt, %l3
84
85	ldx	[n + u0_off], u0	C WAS: up + 0
86	subcc	n, -(2 * 8), n
87
88	ldx	[n + u1_off], u1	C WAS: up + 8
89
90	bg,pn	%xcc, L(end34)
91	 sllx	u0, tcnt, %l4
92
93	b,a	L(top)
94	ALIGN(16)
95L(top):
96	srlx	u0, cnt, %l2
97	or	%l3, %l4, r0
98
99	ldx	[n + u0_off], u0	C WAS: up + 0
100	sllx	u1, tcnt, %l5
101
102	stx	r0, [n + r0_off]	C WAS: rp + 0
103	subcc	n, -(2 * 8), n
104
105	srlx	u1, cnt, %l3
106	or	%l2, %l5, r1
107
108	ldx	[n + u1_off], u1	C WAS: up + 8
109	sllx	u0, tcnt, %l4
110
111	ble,pt	%xcc, L(top)
112	 stx	r1, [n + r1_off]	C WAS: rp + 8
113
114L(end34):
115	srlx	u0, cnt, %l2
116	or	%l3, %l4, r0
117
118	sllx	u1, tcnt, %l5
119	stx	r0, [n + r0_off]	C WAS: rp + 0
120
121	or	%l2, %l5, r1
122	sub	n, -(2 * 8), %o5
123
124	srlx	u1, cnt, %l3
125	stx	r1, [%o5 + r1_off]	C WAS: rp + 8
126
127L(end12):
128	andcc	n, 8, %g0
129	bz,pn	%xcc, L(done)
130	 nop
131
132	ldx	[n + u0_off], u1
133	sllx	u1, tcnt, %l4
134	or	%l3, %l4, r0
135	stx	r0, [r0_off + 24]
136	srlx	u1, cnt, %l3
137L(done):
138	stx	%l3, [r0_off + 32]
139
140	ret
141	restore retval, 0, %o0
142EPILOGUE()
143