1dnl  SPARC v7 __udiv_qrnnd division support, used from longlong.h.
2dnl  This is for v7 CPUs with a floating-point unit.
3
4dnl  Copyright 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
5
6dnl  This file is part of the GNU MP Library.
7
8dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of the GNU Lesser General Public License as published
10dnl  by the Free Software Foundation; either version 3 of the License, or (at
11dnl  your option) any later version.
12
13dnl  The GNU MP Library is distributed in the hope that it will be useful, but
14dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16dnl  License for more details.
17
18dnl  You should have received a copy of the GNU Lesser General Public License
19dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
20
21
22include(`../config.m4')
23
24C INPUT PARAMETERS
25C rem_ptr	i0
26C n1		i1
27C n0		i2
28C d		i3
29
30ASM_START()
31
32ifdef(`PIC',
33`	TEXT
34L(getpc):
35	retl
36	nop')
37
38	TEXT
39	ALIGN(8)
40L(C0):	.double	0r4294967296
41L(C1):	.double	0r2147483648
42
43PROLOGUE(mpn_udiv_qrnnd)
44	save	%sp,-104,%sp
45	st	%i1,[%fp-8]
46	ld	[%fp-8],%f10
47
48ifdef(`PIC',
49`L(pc):	call	L(getpc)		C put address of this insn in %o7
50	ldd	[%o7+L(C0)-L(pc)],%f8',
51`	sethi	%hi(L(C0)),%o7
52	ldd	[%o7+%lo(L(C0))],%f8')
53
54	fitod	%f10,%f4
55	cmp	%i1,0
56	bge	L(248)
57	mov	%i0,%i5
58	faddd	%f4,%f8,%f4
59L(248):
60	st	%i2,[%fp-8]
61	ld	[%fp-8],%f10
62	fmuld	%f4,%f8,%f6
63	cmp	%i2,0
64	bge	L(249)
65	fitod	%f10,%f2
66	faddd	%f2,%f8,%f2
67L(249):
68	st	%i3,[%fp-8]
69	faddd	%f6,%f2,%f2
70	ld	[%fp-8],%f10
71	cmp	%i3,0
72	bge	L(250)
73	fitod	%f10,%f4
74	faddd	%f4,%f8,%f4
75L(250):
76	fdivd	%f2,%f4,%f2
77
78ifdef(`PIC',
79`	ldd	[%o7+L(C1)-L(pc)],%f4',
80`	sethi	%hi(L(C1)),%o7
81	ldd	[%o7+%lo(L(C1))],%f4')
82
83	fcmped	%f2,%f4
84	nop
85	fbge,a	L(251)
86	fsubd	%f2,%f4,%f2
87	fdtoi	%f2,%f2
88	st	%f2,[%fp-8]
89	b	L(252)
90	ld	[%fp-8],%i4
91L(251):
92	fdtoi	%f2,%f2
93	st	%f2,[%fp-8]
94	ld	[%fp-8],%i4
95	sethi	%hi(-2147483648),%g2
96	xor	%i4,%g2,%i4
97L(252):
98	wr	%g0,%i4,%y
99	sra	%i3,31,%g2
100	and	%i4,%g2,%g2
101	andcc	%g0,0,%g1
102	mulscc	%g1,%i3,%g1
103	mulscc	%g1,%i3,%g1
104	mulscc	%g1,%i3,%g1
105	mulscc	%g1,%i3,%g1
106	mulscc	%g1,%i3,%g1
107	mulscc	%g1,%i3,%g1
108	mulscc	%g1,%i3,%g1
109	mulscc	%g1,%i3,%g1
110	mulscc	%g1,%i3,%g1
111	mulscc	%g1,%i3,%g1
112	mulscc	%g1,%i3,%g1
113	mulscc	%g1,%i3,%g1
114	mulscc	%g1,%i3,%g1
115	mulscc	%g1,%i3,%g1
116	mulscc	%g1,%i3,%g1
117	mulscc	%g1,%i3,%g1
118	mulscc	%g1,%i3,%g1
119	mulscc	%g1,%i3,%g1
120	mulscc	%g1,%i3,%g1
121	mulscc	%g1,%i3,%g1
122	mulscc	%g1,%i3,%g1
123	mulscc	%g1,%i3,%g1
124	mulscc	%g1,%i3,%g1
125	mulscc	%g1,%i3,%g1
126	mulscc	%g1,%i3,%g1
127	mulscc	%g1,%i3,%g1
128	mulscc	%g1,%i3,%g1
129	mulscc	%g1,%i3,%g1
130	mulscc	%g1,%i3,%g1
131	mulscc	%g1,%i3,%g1
132	mulscc	%g1,%i3,%g1
133	mulscc	%g1,%i3,%g1
134	mulscc	%g1,0,%g1
135	add	%g1,%g2,%i0
136	rd	%y,%g3
137	subcc	%i2,%g3,%o7
138	subxcc	%i1,%i0,%g0
139	be	L(253)
140	cmp	%o7,%i3
141
142	add	%i4,-1,%i0
143	add	%o7,%i3,%o7
144	st	%o7,[%i5]
145	ret
146	restore
147L(253):
148	blu	L(246)
149	mov	%i4,%i0
150	add	%i4,1,%i0
151	sub	%o7,%i3,%o7
152L(246):
153	st	%o7,[%i5]
154	ret
155	restore
156EPILOGUE(mpn_udiv_qrnnd)
157