1dnl  SPARC T3/T4/T5 mpn_bdiv_q_1.
2
3dnl  Contributed to the GNU project by Torbj��rn Granlund.
4
5dnl  Copyright 2013, 2017 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 T3:	31
37C UltraSPARC T4/T5:	20-26  hits 20 early, then sharply drops
38
39C INPUT PARAMETERS
40define(`qp',  `%i0')
41define(`ap',  `%i1')
42define(`n',   `%i2')
43define(`d',   `%i3')
44define(`dinv',`%i4')
45define(`cnt', `%i5')
46
47define(`tnc', `%o2')
48
49ASM_START()
50	REGISTER(%g2,#scratch)
51	REGISTER(%g3,#scratch)
52PROLOGUE(mpn_bdiv_q_1)
53	save	%sp, -176, %sp
54	ldx	[ap], %o5
55	add	d, -1, %g1
56	andn	%g1, d, %g1
57	popc	%g1, cnt
58
59	srlx	d, cnt, d
60	srlx	d, 1, %g1
61	and	%g1, 127, %g1
62	LEA64(binvert_limb_table, g2, g4)
63	ldub	[%g2+%g1], %g1
64	add	%g1, %g1, %g2
65	mulx	%g1, %g1, %g1
66	mulx	%g1, d, %g1
67	sub	%g2, %g1, %g2
68	add	%g2, %g2, %g1
69	mulx	%g2, %g2, %g2
70	mulx	%g2, d, %g2
71	sub	%g1, %g2, %g1
72	add	%g1, %g1, %o7
73	mulx	%g1, %g1, %g1
74	mulx	%g1, d, %g1
75	add	n, -2, n
76	brz,pt	cnt, L(norm)
77	 sub	%o7, %g1, dinv
78
79	brlz,pt	n, L(edu)
80	 srlx	%o5, cnt, %o5
81	b	L(eee)
82	 mov	0, %g4
83EPILOGUE()
84
85PROLOGUE(mpn_pi1_bdiv_q_1)
86	save	%sp, -176, %sp
87	ldx	[ap], %o5
88
89	brz,pt	cnt, L(norm)
90	 add	n, -2, n
91
92L(unorm):
93	brlz,pt	n, L(edu)
94	 srlx	%o5, cnt, %o5
95	mov	0, %g4
96L(eee):	sub	%g0, cnt, tnc
97
98L(tpu):	ldx	[ap+8], %g3
99	add	ap, 8, ap
100	sllx	%g3, tnc, %g5
101	or	%g5, %o5, %g5
102	srlx	%g3, cnt, %o5
103	subcc	%g5, %g4, %g4
104	mulx	%g4, dinv, %g1
105	stx	%g1, [qp]
106	add	qp, 8, qp
107	umulxhi(d, %g1, %g1)
108	addxc(	%g1, %g0, %g4)
109	brgz,pt	n, L(tpu)
110	 add	n, -1, n
111
112	sub	%o5, %g4, %o5
113L(edu):	mulx	%o5, dinv, %g1
114	return	%i7+8
115	 stx	%g1, [%o0]
116
117L(norm):
118	mulx	dinv, %o5, %g1
119	brlz,pt	n, L(edn)
120	 stx	%g1, [qp]
121	add	qp, 8, qp
122	addcc	%g0, 0, %g4
123
124L(tpn):	umulxhi(d, %g1, %g1)
125	ldx	[ap+8], %g5
126	add	ap, 8, ap
127	addxc(	%g1, %g0, %g1)
128	subcc	%g5, %g1, %g1
129	mulx	%g1, dinv, %g1
130	stx	%g1, [qp]
131	add	qp, 8, qp
132	brgz,pt	n, L(tpn)
133	 add	n, -1, n
134
135L(edn):	return	%i7+8
136	 nop
137EPILOGUE()
138