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