xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/sparc32/udiv.asm (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
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.
7dnl
8dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of either:
10dnl
11dnl    * the GNU Lesser General Public License as published by the Free
12dnl      Software Foundation; either version 3 of the License, or (at your
13dnl      option) any later version.
14dnl
15dnl  or
16dnl
17dnl    * the GNU General Public License as published by the Free Software
18dnl      Foundation; either version 2 of the License, or (at your option) any
19dnl      later version.
20dnl
21dnl  or both in parallel, as here.
22dnl
23dnl  The GNU MP Library is distributed in the hope that it will be useful, but
24dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26dnl  for more details.
27dnl
28dnl  You should have received copies of the GNU General Public License and the
29dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
30dnl  see https://www.gnu.org/licenses/.
31
32
33include(`../config.m4')
34
35C INPUT PARAMETERS
36C rem_ptr	i0
37C n1		i1
38C n0		i2
39C d		i3
40
41ASM_START()
42
43ifdef(`PIC',
44`	TEXT
45L(getpc):
46	retl
47	nop')
48
49	TEXT
50	ALIGN(8)
51L(C0):	.double	0r4294967296
52L(C1):	.double	0r2147483648
53
54PROLOGUE(mpn_udiv_qrnnd)
55	save	%sp,-104,%sp
56	st	%i1,[%fp-8]
57	ld	[%fp-8],%f10
58
59ifdef(`PIC',
60`L(pc):	call	L(getpc)		C put address of this insn in %o7
61	ldd	[%o7+L(C0)-L(pc)],%f8',
62`	sethi	%hi(L(C0)),%o7
63	ldd	[%o7+%lo(L(C0))],%f8')
64
65	fitod	%f10,%f4
66	cmp	%i1,0
67	bge	L(248)
68	mov	%i0,%i5
69	faddd	%f4,%f8,%f4
70L(248):
71	st	%i2,[%fp-8]
72	ld	[%fp-8],%f10
73	fmuld	%f4,%f8,%f6
74	cmp	%i2,0
75	bge	L(249)
76	fitod	%f10,%f2
77	faddd	%f2,%f8,%f2
78L(249):
79	st	%i3,[%fp-8]
80	faddd	%f6,%f2,%f2
81	ld	[%fp-8],%f10
82	cmp	%i3,0
83	bge	L(250)
84	fitod	%f10,%f4
85	faddd	%f4,%f8,%f4
86L(250):
87	fdivd	%f2,%f4,%f2
88
89ifdef(`PIC',
90`	ldd	[%o7+L(C1)-L(pc)],%f4',
91`	sethi	%hi(L(C1)),%o7
92	ldd	[%o7+%lo(L(C1))],%f4')
93
94	fcmped	%f2,%f4
95	nop
96	fbge,a	L(251)
97	fsubd	%f2,%f4,%f2
98	fdtoi	%f2,%f2
99	st	%f2,[%fp-8]
100	b	L(252)
101	ld	[%fp-8],%i4
102L(251):
103	fdtoi	%f2,%f2
104	st	%f2,[%fp-8]
105	ld	[%fp-8],%i4
106	sethi	%hi(-2147483648),%g2
107	xor	%i4,%g2,%i4
108L(252):
109	wr	%g0,%i4,%y
110	sra	%i3,31,%g2
111	and	%i4,%g2,%g2
112	andcc	%g0,0,%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,%i3,%g1
135	mulscc	%g1,%i3,%g1
136	mulscc	%g1,%i3,%g1
137	mulscc	%g1,%i3,%g1
138	mulscc	%g1,%i3,%g1
139	mulscc	%g1,%i3,%g1
140	mulscc	%g1,%i3,%g1
141	mulscc	%g1,%i3,%g1
142	mulscc	%g1,%i3,%g1
143	mulscc	%g1,%i3,%g1
144	mulscc	%g1,%i3,%g1
145	mulscc	%g1,0,%g1
146	add	%g1,%g2,%i0
147	rd	%y,%g3
148	subcc	%i2,%g3,%o7
149	subxcc	%i1,%i0,%g0
150	be	L(253)
151	cmp	%o7,%i3
152
153	add	%i4,-1,%i0
154	add	%o7,%i3,%o7
155	st	%o7,[%i5]
156	ret
157	restore
158L(253):
159	blu	L(246)
160	mov	%i4,%i0
161	add	%i4,1,%i0
162	sub	%o7,%i3,%o7
163L(246):
164	st	%o7,[%i5]
165	ret
166	restore
167EPILOGUE(mpn_udiv_qrnnd)
168