xref: /titanic_50/usr/src/cmd/sgs/rtld.4.x/rem.s (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate
23*7c478bd9Sstevel@tonic-gate!	.seg	"data"
24*7c478bd9Sstevel@tonic-gate!	.asciz	"Copyr 1986 Sun Micro"
25*7c478bd9Sstevel@tonic-gate	.seg	"text"
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate/*
30*7c478bd9Sstevel@tonic-gate * Copyright 1986 Sun Microsystems, Inc.  All rights reserved.
31*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate/*
35*7c478bd9Sstevel@tonic-gate * divison/remainder
36*7c478bd9Sstevel@tonic-gate *
37*7c478bd9Sstevel@tonic-gate * Input is:
38*7c478bd9Sstevel@tonic-gate *	dividend -- the thing being divided
39*7c478bd9Sstevel@tonic-gate * divisor  -- how many ways to divide
40*7c478bd9Sstevel@tonic-gate * Important parameters:
41*7c478bd9Sstevel@tonic-gate *	N -- how many bits per iteration we try to get
42*7c478bd9Sstevel@tonic-gate *		as our current guess:
43*7c478bd9Sstevel@tonic-gate *	WORDSIZE -- how many bits altogether we're talking about:
44*7c478bd9Sstevel@tonic-gate *		obviously:
45*7c478bd9Sstevel@tonic-gate * A derived constant:
46*7c478bd9Sstevel@tonic-gate *	TOPBITS -- how many bits are in the top "decade" of a number:
47*7c478bd9Sstevel@tonic-gate *
48*7c478bd9Sstevel@tonic-gate * Important variables are:
49*7c478bd9Sstevel@tonic-gate *	Q -- the partial quotient under development -- initally 0
50*7c478bd9Sstevel@tonic-gate *	R -- the remainder so far -- initially == the dividend
51*7c478bd9Sstevel@tonic-gate *	ITER -- number of iterations of the main division loop will
52*7c478bd9Sstevel@tonic-gate *		be required. Equal to CEIL( lg2(quotient)/4 )
53*7c478bd9Sstevel@tonic-gate *		Note that this is log_base_(2^4) of the quotient.
54*7c478bd9Sstevel@tonic-gate *	V -- the current comparand -- initially divisor*2^(ITER*4-1)
55*7c478bd9Sstevel@tonic-gate * Cost:
56*7c478bd9Sstevel@tonic-gate *	current estimate for non-large dividend is
57*7c478bd9Sstevel@tonic-gate *		CEIL( lg2(quotient) / 4 ) x ( 10 + 74/2 ) + C
58*7c478bd9Sstevel@tonic-gate *	a large dividend is one greater than 2^(31-4 ) and takes a
59*7c478bd9Sstevel@tonic-gate *	different path, as the upper bits of the quotient must be developed
60*7c478bd9Sstevel@tonic-gate *	one bit at a time.
61*7c478bd9Sstevel@tonic-gate */
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate#include <sys/trap.h>
64*7c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate	! working variable
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate/*
77*7c478bd9Sstevel@tonic-gate * this is the recursive definition of how we develop quotient digits.
78*7c478bd9Sstevel@tonic-gate * it takes three important parameters:
79*7c478bd9Sstevel@tonic-gate *	$1 -- the current depth, 1<=$1<=4
80*7c478bd9Sstevel@tonic-gate *	$2 -- the current accumulation of quotient bits
81*7c478bd9Sstevel@tonic-gate *	4  -- max depth
82*7c478bd9Sstevel@tonic-gate * We add a new bit to $2 and either recurse or
83*7c478bd9Sstevel@tonic-gate * insert the bits in the quotient.
84*7c478bd9Sstevel@tonic-gate * Dynamic input:
85*7c478bd9Sstevel@tonic-gate *	%o3 -- current remainder
86*7c478bd9Sstevel@tonic-gate *	%o2 -- current quotient
87*7c478bd9Sstevel@tonic-gate *	%o5 -- current comparand
88*7c478bd9Sstevel@tonic-gate *	cc -- set on current value of %o3
89*7c478bd9Sstevel@tonic-gate * Dynamic output:
90*7c478bd9Sstevel@tonic-gate * %o3', %o2', %o5', cc'
91*7c478bd9Sstevel@tonic-gate */
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate!	RTENTRY(.urem)		! UNSIGNED REMAINDER
97*7c478bd9Sstevel@tonic-gate	.global	.urem
98*7c478bd9Sstevel@tonic-gate.urem:
99*7c478bd9Sstevel@tonic-gate	b	divide
100*7c478bd9Sstevel@tonic-gate	mov	0,%g1		! result always positive
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate!	RTENTRY(.rem)		! SIGNED REMAINDER
103*7c478bd9Sstevel@tonic-gate	.global	.rem
104*7c478bd9Sstevel@tonic-gate.rem:
105*7c478bd9Sstevel@tonic-gate	orcc	%o1,%o0,%g0 ! are either %o0 or %o1 negative
106*7c478bd9Sstevel@tonic-gate	bge	divide		! if not, skip this junk
107*7c478bd9Sstevel@tonic-gate	mov	%o0,%g1	! record sign of result in sign of %g1
108*7c478bd9Sstevel@tonic-gate		tst	%o1
109*7c478bd9Sstevel@tonic-gate		bge	2f
110*7c478bd9Sstevel@tonic-gate		tst	%o0
111*7c478bd9Sstevel@tonic-gate	!	%o1 < 0
112*7c478bd9Sstevel@tonic-gate		bge	divide
113*7c478bd9Sstevel@tonic-gate		neg	%o1
114*7c478bd9Sstevel@tonic-gate	2:
115*7c478bd9Sstevel@tonic-gate	!	%o0 < 0
116*7c478bd9Sstevel@tonic-gate		neg	%o0
117*7c478bd9Sstevel@tonic-gate	!	FALL THROUGH
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gatedivide:
121*7c478bd9Sstevel@tonic-gate!	compute size of quotient, scale comparand
122*7c478bd9Sstevel@tonic-gate	orcc	%o1,%g0,%o5	! movcc	%o1,%o5
123*7c478bd9Sstevel@tonic-gate	bnz	0f		! if %o1 != 0
124*7c478bd9Sstevel@tonic-gate	mov	%o0,%o3
125*7c478bd9Sstevel@tonic-gate	ba	zero_divide
126*7c478bd9Sstevel@tonic-gate	nop
127*7c478bd9Sstevel@tonic-gate0:
128*7c478bd9Sstevel@tonic-gate	cmp     %o3,%o5
129*7c478bd9Sstevel@tonic-gate	blu     got_result ! if %o3<%o5 already, there's no point in continuing
130*7c478bd9Sstevel@tonic-gate	mov	0,%o2
131*7c478bd9Sstevel@tonic-gate	sethi	%hi(1<<(32-4 -1)),%g2
132*7c478bd9Sstevel@tonic-gate	cmp	%o3,%g2
133*7c478bd9Sstevel@tonic-gate	blu	not_really_big
134*7c478bd9Sstevel@tonic-gate	mov	0,%o4
135*7c478bd9Sstevel@tonic-gate	!
136*7c478bd9Sstevel@tonic-gate	! here, the %o0 is >= 2^(31-4) or so. We must be careful here, as
137*7c478bd9Sstevel@tonic-gate	! our usual 4-at-a-shot divide step will cause overflow and havoc. The
138*7c478bd9Sstevel@tonic-gate	! total number of bits in the result here is 4*%o4+%g3, where %g3 <= 4.
139*7c478bd9Sstevel@tonic-gate	! compute %o4, in an unorthodox manner: know we need to Shift %o5 into
140*7c478bd9Sstevel@tonic-gate	!	the top decade: so don't even bother to compare to %o3.
141*7c478bd9Sstevel@tonic-gate	1:
142*7c478bd9Sstevel@tonic-gate		cmp	%o5,%g2
143*7c478bd9Sstevel@tonic-gate		bgeu	3f
144*7c478bd9Sstevel@tonic-gate		mov	1,%g3
145*7c478bd9Sstevel@tonic-gate		sll	%o5,4,%o5
146*7c478bd9Sstevel@tonic-gate		b	1b
147*7c478bd9Sstevel@tonic-gate		inc	%o4
148*7c478bd9Sstevel@tonic-gate	! now compute %g3
149*7c478bd9Sstevel@tonic-gate	2:	addcc	%o5,%o5,%o5
150*7c478bd9Sstevel@tonic-gate		bcc	not_too_big ! bcc	not_too_big
151*7c478bd9Sstevel@tonic-gate		add	%g3,1,%g3
152*7c478bd9Sstevel@tonic-gate			!
153*7c478bd9Sstevel@tonic-gate			! here if the %o1 overflowed when Shifting
154*7c478bd9Sstevel@tonic-gate			! this means that %o3 has the high-order bit set
155*7c478bd9Sstevel@tonic-gate			! restore %o5 and subtract from %o3
156*7c478bd9Sstevel@tonic-gate			sll	%g2,4 ,%g2 ! high order bit
157*7c478bd9Sstevel@tonic-gate			srl	%o5,1,%o5 ! rest of %o5
158*7c478bd9Sstevel@tonic-gate			add	%o5,%g2,%o5
159*7c478bd9Sstevel@tonic-gate			b	do_single_div
160*7c478bd9Sstevel@tonic-gate			sub	%g3,1,%g3
161*7c478bd9Sstevel@tonic-gate	not_too_big:
162*7c478bd9Sstevel@tonic-gate	3:	cmp	%o5,%o3
163*7c478bd9Sstevel@tonic-gate		blu	2b
164*7c478bd9Sstevel@tonic-gate		nop
165*7c478bd9Sstevel@tonic-gate		be	do_single_div
166*7c478bd9Sstevel@tonic-gate		nop
167*7c478bd9Sstevel@tonic-gate	! %o5 > %o3: went too far: back up 1 step
168*7c478bd9Sstevel@tonic-gate	!	srl	%o5,1,%o5
169*7c478bd9Sstevel@tonic-gate	!	dec	%g3
170*7c478bd9Sstevel@tonic-gate	! do single-bit divide steps
171*7c478bd9Sstevel@tonic-gate	!
172*7c478bd9Sstevel@tonic-gate	! we have to be careful here. We know that %o3 >= %o5, so we can do the
173*7c478bd9Sstevel@tonic-gate	! first divide step without thinking. BUT, the others are conditional,
174*7c478bd9Sstevel@tonic-gate	! and are only done if %o3 >= 0. Because both %o3 and %o5 may have the high-
175*7c478bd9Sstevel@tonic-gate	! order bit set in the first step, just falling into the regular
176*7c478bd9Sstevel@tonic-gate	! division loop will mess up the first time around.
177*7c478bd9Sstevel@tonic-gate	! So we unroll slightly...
178*7c478bd9Sstevel@tonic-gate	do_single_div:
179*7c478bd9Sstevel@tonic-gate		deccc	%g3
180*7c478bd9Sstevel@tonic-gate		bl	end_regular_divide
181*7c478bd9Sstevel@tonic-gate		nop
182*7c478bd9Sstevel@tonic-gate		sub	%o3,%o5,%o3
183*7c478bd9Sstevel@tonic-gate		mov	1,%o2
184*7c478bd9Sstevel@tonic-gate		b,a	end_single_divloop
185*7c478bd9Sstevel@tonic-gate	single_divloop:
186*7c478bd9Sstevel@tonic-gate		sll	%o2,1,%o2
187*7c478bd9Sstevel@tonic-gate		bl	1f
188*7c478bd9Sstevel@tonic-gate		srl	%o5,1,%o5
189*7c478bd9Sstevel@tonic-gate		! %o3 >= 0
190*7c478bd9Sstevel@tonic-gate		sub	%o3,%o5,%o3
191*7c478bd9Sstevel@tonic-gate		b	2f
192*7c478bd9Sstevel@tonic-gate		inc	%o2
193*7c478bd9Sstevel@tonic-gate	1:	! %o3 < 0
194*7c478bd9Sstevel@tonic-gate		add	%o3,%o5,%o3
195*7c478bd9Sstevel@tonic-gate		dec	%o2
196*7c478bd9Sstevel@tonic-gate	2:
197*7c478bd9Sstevel@tonic-gate	end_single_divloop:
198*7c478bd9Sstevel@tonic-gate		deccc	%g3
199*7c478bd9Sstevel@tonic-gate		bge	single_divloop
200*7c478bd9Sstevel@tonic-gate		tst	%o3
201*7c478bd9Sstevel@tonic-gate		b,a	end_regular_divide
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gatenot_really_big:
204*7c478bd9Sstevel@tonic-gate1:
205*7c478bd9Sstevel@tonic-gate	sll	%o5,4,%o5
206*7c478bd9Sstevel@tonic-gate	cmp	%o5,%o3
207*7c478bd9Sstevel@tonic-gate	bleu	1b
208*7c478bd9Sstevel@tonic-gate	inccc	%o4
209*7c478bd9Sstevel@tonic-gate	be	got_result
210*7c478bd9Sstevel@tonic-gate	dec	%o4
211*7c478bd9Sstevel@tonic-gatedo_regular_divide:
212*7c478bd9Sstevel@tonic-gate
213*7c478bd9Sstevel@tonic-gate!	do the main division iteration
214*7c478bd9Sstevel@tonic-gate	tst	%o3
215*7c478bd9Sstevel@tonic-gate!	fall through into divide loop
216*7c478bd9Sstevel@tonic-gatedivloop:
217*7c478bd9Sstevel@tonic-gate	sll	%o2,4,%o2
218*7c478bd9Sstevel@tonic-gate		!depth 1, accumulated bits 0
219*7c478bd9Sstevel@tonic-gate	bl	L.1.16
220*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
221*7c478bd9Sstevel@tonic-gate	! remainder is positive
222*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
223*7c478bd9Sstevel@tonic-gate			!depth 2, accumulated bits 1
224*7c478bd9Sstevel@tonic-gate	bl	L.2.17
225*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
226*7c478bd9Sstevel@tonic-gate	! remainder is positive
227*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
228*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits 3
229*7c478bd9Sstevel@tonic-gate	bl	L.3.19
230*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
231*7c478bd9Sstevel@tonic-gate	! remainder is positive
232*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
233*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 7
234*7c478bd9Sstevel@tonic-gate	bl	L.4.23
235*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
236*7c478bd9Sstevel@tonic-gate	! remainder is positive
237*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
238*7c478bd9Sstevel@tonic-gate		b	9f
239*7c478bd9Sstevel@tonic-gate		add	%o2, (7*2+1), %o2
240*7c478bd9Sstevel@tonic-gate
241*7c478bd9Sstevel@tonic-gateL.4.23:	! remainder is negative
242*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
243*7c478bd9Sstevel@tonic-gate		b	9f
244*7c478bd9Sstevel@tonic-gate		add	%o2, (7*2-1), %o2
245*7c478bd9Sstevel@tonic-gate
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gateL.3.19:	! remainder is negative
250*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
251*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 5
252*7c478bd9Sstevel@tonic-gate	bl	L.4.21
253*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
254*7c478bd9Sstevel@tonic-gate	! remainder is positive
255*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
256*7c478bd9Sstevel@tonic-gate		b	9f
257*7c478bd9Sstevel@tonic-gate		add	%o2, (5*2+1), %o2
258*7c478bd9Sstevel@tonic-gate
259*7c478bd9Sstevel@tonic-gateL.4.21:	! remainder is negative
260*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
261*7c478bd9Sstevel@tonic-gate		b	9f
262*7c478bd9Sstevel@tonic-gate		add	%o2, (5*2-1), %o2
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate
265*7c478bd9Sstevel@tonic-gate
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate
269*7c478bd9Sstevel@tonic-gate
270*7c478bd9Sstevel@tonic-gateL.2.17:	! remainder is negative
271*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
272*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits 1
273*7c478bd9Sstevel@tonic-gate	bl	L.3.17
274*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
275*7c478bd9Sstevel@tonic-gate	! remainder is positive
276*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
277*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 3
278*7c478bd9Sstevel@tonic-gate	bl	L.4.19
279*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
280*7c478bd9Sstevel@tonic-gate	! remainder is positive
281*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
282*7c478bd9Sstevel@tonic-gate		b	9f
283*7c478bd9Sstevel@tonic-gate		add	%o2, (3*2+1), %o2
284*7c478bd9Sstevel@tonic-gate
285*7c478bd9Sstevel@tonic-gateL.4.19:	! remainder is negative
286*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
287*7c478bd9Sstevel@tonic-gate		b	9f
288*7c478bd9Sstevel@tonic-gate		add	%o2, (3*2-1), %o2
289*7c478bd9Sstevel@tonic-gate
290*7c478bd9Sstevel@tonic-gate
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate
293*7c478bd9Sstevel@tonic-gateL.3.17:	! remainder is negative
294*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
295*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 1
296*7c478bd9Sstevel@tonic-gate	bl	L.4.17
297*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
298*7c478bd9Sstevel@tonic-gate	! remainder is positive
299*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
300*7c478bd9Sstevel@tonic-gate		b	9f
301*7c478bd9Sstevel@tonic-gate		add	%o2, (1*2+1), %o2
302*7c478bd9Sstevel@tonic-gate
303*7c478bd9Sstevel@tonic-gateL.4.17:	! remainder is negative
304*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
305*7c478bd9Sstevel@tonic-gate		b	9f
306*7c478bd9Sstevel@tonic-gate		add	%o2, (1*2-1), %o2
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate
311*7c478bd9Sstevel@tonic-gate
312*7c478bd9Sstevel@tonic-gate
313*7c478bd9Sstevel@tonic-gate
314*7c478bd9Sstevel@tonic-gate
315*7c478bd9Sstevel@tonic-gate
316*7c478bd9Sstevel@tonic-gate
317*7c478bd9Sstevel@tonic-gateL.1.16:	! remainder is negative
318*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
319*7c478bd9Sstevel@tonic-gate			!depth 2, accumulated bits -1
320*7c478bd9Sstevel@tonic-gate	bl	L.2.15
321*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
322*7c478bd9Sstevel@tonic-gate	! remainder is positive
323*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
324*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits -1
325*7c478bd9Sstevel@tonic-gate	bl	L.3.15
326*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
327*7c478bd9Sstevel@tonic-gate	! remainder is positive
328*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
329*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -1
330*7c478bd9Sstevel@tonic-gate	bl	L.4.15
331*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
332*7c478bd9Sstevel@tonic-gate	! remainder is positive
333*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
334*7c478bd9Sstevel@tonic-gate		b	9f
335*7c478bd9Sstevel@tonic-gate		add	%o2, (-1*2+1), %o2
336*7c478bd9Sstevel@tonic-gate
337*7c478bd9Sstevel@tonic-gateL.4.15:	! remainder is negative
338*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
339*7c478bd9Sstevel@tonic-gate		b	9f
340*7c478bd9Sstevel@tonic-gate		add	%o2, (-1*2-1), %o2
341*7c478bd9Sstevel@tonic-gate
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gate
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gateL.3.15:	! remainder is negative
346*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
347*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -3
348*7c478bd9Sstevel@tonic-gate	bl	L.4.13
349*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
350*7c478bd9Sstevel@tonic-gate	! remainder is positive
351*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
352*7c478bd9Sstevel@tonic-gate		b	9f
353*7c478bd9Sstevel@tonic-gate		add	%o2, (-3*2+1), %o2
354*7c478bd9Sstevel@tonic-gate
355*7c478bd9Sstevel@tonic-gateL.4.13:	! remainder is negative
356*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
357*7c478bd9Sstevel@tonic-gate		b	9f
358*7c478bd9Sstevel@tonic-gate		add	%o2, (-3*2-1), %o2
359*7c478bd9Sstevel@tonic-gate
360*7c478bd9Sstevel@tonic-gate
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate
363*7c478bd9Sstevel@tonic-gate
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate
366*7c478bd9Sstevel@tonic-gateL.2.15:	! remainder is negative
367*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
368*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits -3
369*7c478bd9Sstevel@tonic-gate	bl	L.3.13
370*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
371*7c478bd9Sstevel@tonic-gate	! remainder is positive
372*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
373*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -5
374*7c478bd9Sstevel@tonic-gate	bl	L.4.11
375*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
376*7c478bd9Sstevel@tonic-gate	! remainder is positive
377*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
378*7c478bd9Sstevel@tonic-gate		b	9f
379*7c478bd9Sstevel@tonic-gate		add	%o2, (-5*2+1), %o2
380*7c478bd9Sstevel@tonic-gate
381*7c478bd9Sstevel@tonic-gateL.4.11:	! remainder is negative
382*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
383*7c478bd9Sstevel@tonic-gate		b	9f
384*7c478bd9Sstevel@tonic-gate		add	%o2, (-5*2-1), %o2
385*7c478bd9Sstevel@tonic-gate
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gateL.3.13:	! remainder is negative
390*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
391*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -7
392*7c478bd9Sstevel@tonic-gate	bl	L.4.9
393*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
394*7c478bd9Sstevel@tonic-gate	! remainder is positive
395*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
396*7c478bd9Sstevel@tonic-gate		b	9f
397*7c478bd9Sstevel@tonic-gate		add	%o2, (-7*2+1), %o2
398*7c478bd9Sstevel@tonic-gate
399*7c478bd9Sstevel@tonic-gateL.4.9:	! remainder is negative
400*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
401*7c478bd9Sstevel@tonic-gate		b	9f
402*7c478bd9Sstevel@tonic-gate		add	%o2, (-7*2-1), %o2
403*7c478bd9Sstevel@tonic-gate
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate
406*7c478bd9Sstevel@tonic-gate
407*7c478bd9Sstevel@tonic-gate
408*7c478bd9Sstevel@tonic-gate
409*7c478bd9Sstevel@tonic-gate
410*7c478bd9Sstevel@tonic-gate
411*7c478bd9Sstevel@tonic-gate
412*7c478bd9Sstevel@tonic-gate
413*7c478bd9Sstevel@tonic-gate	9:
414*7c478bd9Sstevel@tonic-gate
415*7c478bd9Sstevel@tonic-gateend_regular_divide:
416*7c478bd9Sstevel@tonic-gate	deccc	%o4
417*7c478bd9Sstevel@tonic-gate	bge	divloop
418*7c478bd9Sstevel@tonic-gate	tst	%o3
419*7c478bd9Sstevel@tonic-gate	bl,a	got_result
420*7c478bd9Sstevel@tonic-gate	add	%o3,%o1,%o3
421*7c478bd9Sstevel@tonic-gate
422*7c478bd9Sstevel@tonic-gate
423*7c478bd9Sstevel@tonic-gategot_result:
424*7c478bd9Sstevel@tonic-gate	tst	%g1
425*7c478bd9Sstevel@tonic-gate	bl,a	1f
426*7c478bd9Sstevel@tonic-gate	neg	%o3	! remainder <- -%o3
427*7c478bd9Sstevel@tonic-gate
428*7c478bd9Sstevel@tonic-gate1:
429*7c478bd9Sstevel@tonic-gate	retl
430*7c478bd9Sstevel@tonic-gate	mov	%o3,%o0	! remainder <-  %o3
431*7c478bd9Sstevel@tonic-gate
432*7c478bd9Sstevel@tonic-gate
433*7c478bd9Sstevel@tonic-gatezero_divide:
434*7c478bd9Sstevel@tonic-gate	ta	ST_DIV0		! divide by zero trap
435*7c478bd9Sstevel@tonic-gate	retl			! if handled, ignored, return
436*7c478bd9Sstevel@tonic-gate	mov	0, %o0
437