1dnl  SPARC T3/T4/T5 mpn_divexact_1.
2
3dnl  Contributed to the GNU project by Torbj��rn Granlund.
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 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')
44
45define(`dinv',`%o4')
46
47ASM_START()
48	REGISTER(%g2,#scratch)
49	REGISTER(%g3,#scratch)
50PROLOGUE(mpn_divexact_1)
51	save	%sp, -176, %sp
52	cmp	n, 1
53	bne,pt	%xcc, L(gt1)
54	 ldx	[ap], %o5
55	udivx	%o5, d, %g1
56	stx	%g1, [qp]
57	return	%i7+8
58	 nop
59
60L(gt1):	add	d, -1, %g1
61	andn	%g1, d, %g1
62	popc	%g1, %i4		C i4 = count_trailing_zeros(d)
63
64	srlx	d, %i4, d
65	srlx	d, 1, %g1
66	and	%g1, 127, %g1
67
68	LEA64(binvert_limb_table, g2, g4)
69	ldub	[%g2+%g1], %g1
70	add	%g1, %g1, %g2
71	mulx	%g1, %g1, %g1
72	mulx	%g1, d, %g1
73	sub	%g2, %g1, %g2
74	add	%g2, %g2, %g1
75	mulx	%g2, %g2, %g2
76	mulx	%g2, d, %g2
77	sub	%g1, %g2, %g1
78	add	%g1, %g1, %o7
79	mulx	%g1, %g1, %g1
80	mulx	%g1, d, %g1
81	add	n, -2, n
82	brz,pt	%i4, L(norm)
83	 sub	%o7, %g1, dinv
84
85L(unnorm):
86	mov	0, %g4
87	sub	%g0, %i4, %o2
88	srlx	%o5, %i4, %o5
89L(top_unnorm):
90	ldx	[ap+8], %g3
91	add	ap, 8, ap
92	sllx	%g3, %o2, %g5
93	or	%g5, %o5, %g5
94	srlx	%g3, %i4, %o5
95	subcc	%g5, %g4, %g4
96	mulx	%g4, dinv, %g1
97	stx	%g1, [qp]
98	add	qp, 8, qp
99	umulxhi(d, %g1, %g1)
100	addxc(	%g1, %g0, %g4)
101	brgz,pt	n, L(top_unnorm)
102	 add	n, -1, n
103
104	sub	%o5, %g4, %g4
105	mulx	%g4, dinv, %g1
106	stx	%g1, [qp]
107	return	%i7+8
108	 nop
109
110L(norm):
111	mulx	dinv, %o5, %g1
112	stx	%g1, [qp]
113	add	qp, 8, qp
114	addcc	%g0, 0, %g4
115L(top_norm):
116	umulxhi(d, %g1, %g1)
117	ldx	[ap+8], %g5
118	add	ap, 8, ap
119	addxc(	%g1, %g0, %g1)
120	subcc	%g5, %g1, %g1
121	mulx	%g1, dinv, %g1
122	stx	%g1, [qp]
123	add	qp, 8, qp
124	brgz,pt	n, L(top_norm)
125	 add	n, -1, n
126
127	return	%i7+8
128	 nop
129EPILOGUE()
130