xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/sparc32/v8/udiv.asm (revision d90047b5d07facf36e6c01dcc0bded8997ce9cc2)
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.
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
33
34include(`../config.m4')
35
36C INPUT PARAMETERS
37C rem_ptr	i0
38C n1		i1
39C n0		i2
40C d		i3
41
42ASM_START()
43
44ifdef(`PIC',
45`	TEXT
46L(getpc):
47	retl
48	nop')
49
50	TEXT
51	ALIGN(8)
52L(C0):	.double	0r4294967296
53L(C1):	.double	0r2147483648
54
55PROLOGUE(mpn_udiv_qrnnd)
56	save	%sp,-104,%sp
57	st	%i1,[%fp-8]
58	ld	[%fp-8],%f10
59
60ifdef(`PIC',
61`L(pc):	call	L(getpc)		C put address of this insn in %o7
62	ldd	[%o7+L(C0)-L(pc)],%f8',
63`	sethi	%hi(L(C0)),%o7
64	ldd	[%o7+%lo(L(C0))],%f8')
65
66	fitod	%f10,%f4
67	cmp	%i1,0
68	bge	L(248)
69	mov	%i0,%i5
70	faddd	%f4,%f8,%f4
71L(248):
72	st	%i2,[%fp-8]
73	ld	[%fp-8],%f10
74	fmuld	%f4,%f8,%f6
75	cmp	%i2,0
76	bge	L(249)
77	fitod	%f10,%f2
78	faddd	%f2,%f8,%f2
79L(249):
80	st	%i3,[%fp-8]
81	faddd	%f6,%f2,%f2
82	ld	[%fp-8],%f10
83	cmp	%i3,0
84	bge	L(250)
85	fitod	%f10,%f4
86	faddd	%f4,%f8,%f4
87L(250):
88	fdivd	%f2,%f4,%f2
89
90ifdef(`PIC',
91`	ldd	[%o7+L(C1)-L(pc)],%f4',
92`	sethi	%hi(L(C1)),%o7
93	ldd	[%o7+%lo(L(C1))],%f4')
94
95	fcmped	%f2,%f4
96	nop
97	fbge,a	L(251)
98	fsubd	%f2,%f4,%f2
99	fdtoi	%f2,%f2
100	st	%f2,[%fp-8]
101	b	L(252)
102	ld	[%fp-8],%i4
103L(251):
104	fdtoi	%f2,%f2
105	st	%f2,[%fp-8]
106	ld	[%fp-8],%i4
107	sethi	%hi(-2147483648),%g2
108	xor	%i4,%g2,%i4
109L(252):
110	umul	%i3,%i4,%g3
111	rd	%y,%i0
112	subcc	%i2,%g3,%o7
113	subxcc	%i1,%i0,%g0
114	be	L(253)
115	cmp	%o7,%i3
116
117	add	%i4,-1,%i0
118	add	%o7,%i3,%o7
119	st	%o7,[%i5]
120	ret
121	restore
122L(253):
123	blu	L(246)
124	mov	%i4,%i0
125	add	%i4,1,%i0
126	sub	%o7,%i3,%o7
127L(246):
128	st	%o7,[%i5]
129	ret
130	restore
131EPILOGUE(mpn_udiv_qrnnd)
132