xref: /titanic_50/usr/src/cmd/sgs/rtld.4.x/div.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
97*7c478bd9Sstevel@tonic-gate!	RTENTRY(.udiv)		! unsigned divide
98*7c478bd9Sstevel@tonic-gate	.global .udiv
99*7c478bd9Sstevel@tonic-gate.udiv:
100*7c478bd9Sstevel@tonic-gate	b	divide
101*7c478bd9Sstevel@tonic-gate	mov	0,%g1		! result always positive
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate!	RTENTRY(.div)		! SIGNED DIVIDE
104*7c478bd9Sstevel@tonic-gate	.global	.div
105*7c478bd9Sstevel@tonic-gate.div:
106*7c478bd9Sstevel@tonic-gate	orcc	%o1,%o0,%g0 ! are either %o0 or %o1 negative
107*7c478bd9Sstevel@tonic-gate	bge	divide		! if not, skip this junk
108*7c478bd9Sstevel@tonic-gate	xor	%o1,%o0,%g1 ! record sign of result in sign of %g1
109*7c478bd9Sstevel@tonic-gate		tst	%o1
110*7c478bd9Sstevel@tonic-gate		bge	2f
111*7c478bd9Sstevel@tonic-gate		tst	%o0
112*7c478bd9Sstevel@tonic-gate	!	%o1 < 0
113*7c478bd9Sstevel@tonic-gate		bge	divide
114*7c478bd9Sstevel@tonic-gate		neg	%o1
115*7c478bd9Sstevel@tonic-gate	2:
116*7c478bd9Sstevel@tonic-gate	!	%o0 < 0
117*7c478bd9Sstevel@tonic-gate		neg	%o0
118*7c478bd9Sstevel@tonic-gate	!	FALL THROUGH
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gatedivide:
122*7c478bd9Sstevel@tonic-gate!	compute size of quotient, scale comparand
123*7c478bd9Sstevel@tonic-gate	orcc	%o1,%g0,%o5	! movcc	%o1,%o5
124*7c478bd9Sstevel@tonic-gate	bnz	0f		! if %o1 != 0
125*7c478bd9Sstevel@tonic-gate	mov	%o0,%o3
126*7c478bd9Sstevel@tonic-gate	ba	zero_divide
127*7c478bd9Sstevel@tonic-gate	nop
128*7c478bd9Sstevel@tonic-gate0:
129*7c478bd9Sstevel@tonic-gate	cmp     %o3,%o5
130*7c478bd9Sstevel@tonic-gate	blu     got_result ! if %o3<%o5 already, there's no point in continuing
131*7c478bd9Sstevel@tonic-gate	mov	0,%o2
132*7c478bd9Sstevel@tonic-gate	sethi	%hi(1<<(32-4 -1)),%g2
133*7c478bd9Sstevel@tonic-gate	cmp	%o3,%g2
134*7c478bd9Sstevel@tonic-gate	blu	not_really_big
135*7c478bd9Sstevel@tonic-gate	mov	0,%o4
136*7c478bd9Sstevel@tonic-gate	!
137*7c478bd9Sstevel@tonic-gate	! here, the %o0 is >= 2^(31-4) or so. We must be careful here, as
138*7c478bd9Sstevel@tonic-gate	! our usual 4-at-a-shot divide step will cause overflow and havoc. The
139*7c478bd9Sstevel@tonic-gate	! total number of bits in the result here is 4*%o4+%g3, where %g3 <= 4.
140*7c478bd9Sstevel@tonic-gate	! compute %o4, in an unorthodox manner: know we need to Shift %o5 into
141*7c478bd9Sstevel@tonic-gate	!	the top decade: so don't even bother to compare to %o3.
142*7c478bd9Sstevel@tonic-gate	1:
143*7c478bd9Sstevel@tonic-gate		cmp	%o5,%g2
144*7c478bd9Sstevel@tonic-gate		bgeu	3f
145*7c478bd9Sstevel@tonic-gate		mov	1,%g3
146*7c478bd9Sstevel@tonic-gate		sll	%o5,4,%o5
147*7c478bd9Sstevel@tonic-gate		b	1b
148*7c478bd9Sstevel@tonic-gate		inc	%o4
149*7c478bd9Sstevel@tonic-gate	! now compute %g3
150*7c478bd9Sstevel@tonic-gate	2:	addcc	%o5,%o5,%o5
151*7c478bd9Sstevel@tonic-gate		bcc	not_too_big ! bcc	not_too_big
152*7c478bd9Sstevel@tonic-gate		add	%g3,1,%g3
153*7c478bd9Sstevel@tonic-gate			!
154*7c478bd9Sstevel@tonic-gate			! here if the %o1 overflowed when Shifting
155*7c478bd9Sstevel@tonic-gate			! this means that %o3 has the high-order bit set
156*7c478bd9Sstevel@tonic-gate			! restore %o5 and subtract from %o3
157*7c478bd9Sstevel@tonic-gate			sll	%g2,4 ,%g2 ! high order bit
158*7c478bd9Sstevel@tonic-gate			srl	%o5,1,%o5 ! rest of %o5
159*7c478bd9Sstevel@tonic-gate			add	%o5,%g2,%o5
160*7c478bd9Sstevel@tonic-gate			b	do_single_div
161*7c478bd9Sstevel@tonic-gate			sub	%g3,1,%g3
162*7c478bd9Sstevel@tonic-gate	not_too_big:
163*7c478bd9Sstevel@tonic-gate	3:	cmp	%o5,%o3
164*7c478bd9Sstevel@tonic-gate		blu	2b
165*7c478bd9Sstevel@tonic-gate		nop
166*7c478bd9Sstevel@tonic-gate		be	do_single_div
167*7c478bd9Sstevel@tonic-gate		nop
168*7c478bd9Sstevel@tonic-gate	! %o5 > %o3: went too far: back up 1 step
169*7c478bd9Sstevel@tonic-gate	!	srl	%o5,1,%o5
170*7c478bd9Sstevel@tonic-gate	!	dec	%g3
171*7c478bd9Sstevel@tonic-gate	! do single-bit divide steps
172*7c478bd9Sstevel@tonic-gate	!
173*7c478bd9Sstevel@tonic-gate	! we have to be careful here. We know that %o3 >= %o5, so we can do the
174*7c478bd9Sstevel@tonic-gate	! first divide step without thinking. BUT, the others are conditional,
175*7c478bd9Sstevel@tonic-gate	! and are only done if %o3 >= 0. Because both %o3 and %o5 may have the high-
176*7c478bd9Sstevel@tonic-gate	! order bit set in the first step, just falling into the regular
177*7c478bd9Sstevel@tonic-gate	! division loop will mess up the first time around.
178*7c478bd9Sstevel@tonic-gate	! So we unroll slightly...
179*7c478bd9Sstevel@tonic-gate	do_single_div:
180*7c478bd9Sstevel@tonic-gate		deccc	%g3
181*7c478bd9Sstevel@tonic-gate		bl	end_regular_divide
182*7c478bd9Sstevel@tonic-gate		nop
183*7c478bd9Sstevel@tonic-gate		sub	%o3,%o5,%o3
184*7c478bd9Sstevel@tonic-gate		mov	1,%o2
185*7c478bd9Sstevel@tonic-gate		b,a	end_single_divloop
186*7c478bd9Sstevel@tonic-gate	single_divloop:
187*7c478bd9Sstevel@tonic-gate		sll	%o2,1,%o2
188*7c478bd9Sstevel@tonic-gate		bl	1f
189*7c478bd9Sstevel@tonic-gate		srl	%o5,1,%o5
190*7c478bd9Sstevel@tonic-gate		! %o3 >= 0
191*7c478bd9Sstevel@tonic-gate		sub	%o3,%o5,%o3
192*7c478bd9Sstevel@tonic-gate		b	2f
193*7c478bd9Sstevel@tonic-gate		inc	%o2
194*7c478bd9Sstevel@tonic-gate	1:	! %o3 < 0
195*7c478bd9Sstevel@tonic-gate		add	%o3,%o5,%o3
196*7c478bd9Sstevel@tonic-gate		dec	%o2
197*7c478bd9Sstevel@tonic-gate	2:
198*7c478bd9Sstevel@tonic-gate	end_single_divloop:
199*7c478bd9Sstevel@tonic-gate		deccc	%g3
200*7c478bd9Sstevel@tonic-gate		bge	single_divloop
201*7c478bd9Sstevel@tonic-gate		tst	%o3
202*7c478bd9Sstevel@tonic-gate		b,a	end_regular_divide
203*7c478bd9Sstevel@tonic-gate
204*7c478bd9Sstevel@tonic-gatenot_really_big:
205*7c478bd9Sstevel@tonic-gate1:
206*7c478bd9Sstevel@tonic-gate	sll	%o5,4,%o5
207*7c478bd9Sstevel@tonic-gate	cmp	%o5,%o3
208*7c478bd9Sstevel@tonic-gate	bleu	1b
209*7c478bd9Sstevel@tonic-gate	inccc	%o4
210*7c478bd9Sstevel@tonic-gate	be	got_result
211*7c478bd9Sstevel@tonic-gate	dec	%o4
212*7c478bd9Sstevel@tonic-gatedo_regular_divide:
213*7c478bd9Sstevel@tonic-gate
214*7c478bd9Sstevel@tonic-gate!	do the main division iteration
215*7c478bd9Sstevel@tonic-gate	tst	%o3
216*7c478bd9Sstevel@tonic-gate!	fall through into divide loop
217*7c478bd9Sstevel@tonic-gatedivloop:
218*7c478bd9Sstevel@tonic-gate	sll	%o2,4,%o2
219*7c478bd9Sstevel@tonic-gate		!depth 1, accumulated bits 0
220*7c478bd9Sstevel@tonic-gate	bl	L.1.16
221*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
222*7c478bd9Sstevel@tonic-gate	! remainder is positive
223*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
224*7c478bd9Sstevel@tonic-gate			!depth 2, accumulated bits 1
225*7c478bd9Sstevel@tonic-gate	bl	L.2.17
226*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
227*7c478bd9Sstevel@tonic-gate	! remainder is positive
228*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
229*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits 3
230*7c478bd9Sstevel@tonic-gate	bl	L.3.19
231*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
232*7c478bd9Sstevel@tonic-gate	! remainder is positive
233*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
234*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 7
235*7c478bd9Sstevel@tonic-gate	bl	L.4.23
236*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
237*7c478bd9Sstevel@tonic-gate	! remainder is positive
238*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
239*7c478bd9Sstevel@tonic-gate		b	9f
240*7c478bd9Sstevel@tonic-gate		add	%o2, (7*2+1), %o2
241*7c478bd9Sstevel@tonic-gate
242*7c478bd9Sstevel@tonic-gateL.4.23:	! remainder is negative
243*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
244*7c478bd9Sstevel@tonic-gate		b	9f
245*7c478bd9Sstevel@tonic-gate		add	%o2, (7*2-1), %o2
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate
250*7c478bd9Sstevel@tonic-gateL.3.19:	! remainder is negative
251*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
252*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 5
253*7c478bd9Sstevel@tonic-gate	bl	L.4.21
254*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
255*7c478bd9Sstevel@tonic-gate	! remainder is positive
256*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
257*7c478bd9Sstevel@tonic-gate		b	9f
258*7c478bd9Sstevel@tonic-gate		add	%o2, (5*2+1), %o2
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gateL.4.21:	! remainder is negative
261*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
262*7c478bd9Sstevel@tonic-gate		b	9f
263*7c478bd9Sstevel@tonic-gate		add	%o2, (5*2-1), %o2
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-gate
271*7c478bd9Sstevel@tonic-gateL.2.17:	! remainder is negative
272*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
273*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits 1
274*7c478bd9Sstevel@tonic-gate	bl	L.3.17
275*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
276*7c478bd9Sstevel@tonic-gate	! remainder is positive
277*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
278*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 3
279*7c478bd9Sstevel@tonic-gate	bl	L.4.19
280*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
281*7c478bd9Sstevel@tonic-gate	! remainder is positive
282*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
283*7c478bd9Sstevel@tonic-gate		b	9f
284*7c478bd9Sstevel@tonic-gate		add	%o2, (3*2+1), %o2
285*7c478bd9Sstevel@tonic-gate
286*7c478bd9Sstevel@tonic-gateL.4.19:	! remainder is negative
287*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
288*7c478bd9Sstevel@tonic-gate		b	9f
289*7c478bd9Sstevel@tonic-gate		add	%o2, (3*2-1), %o2
290*7c478bd9Sstevel@tonic-gate
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gateL.3.17:	! remainder is negative
295*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
296*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits 1
297*7c478bd9Sstevel@tonic-gate	bl	L.4.17
298*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
299*7c478bd9Sstevel@tonic-gate	! remainder is positive
300*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
301*7c478bd9Sstevel@tonic-gate		b	9f
302*7c478bd9Sstevel@tonic-gate		add	%o2, (1*2+1), %o2
303*7c478bd9Sstevel@tonic-gate
304*7c478bd9Sstevel@tonic-gateL.4.17:	! remainder is negative
305*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
306*7c478bd9Sstevel@tonic-gate		b	9f
307*7c478bd9Sstevel@tonic-gate		add	%o2, (1*2-1), %o2
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-gate
318*7c478bd9Sstevel@tonic-gateL.1.16:	! remainder is negative
319*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
320*7c478bd9Sstevel@tonic-gate			!depth 2, accumulated bits -1
321*7c478bd9Sstevel@tonic-gate	bl	L.2.15
322*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
323*7c478bd9Sstevel@tonic-gate	! remainder is positive
324*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
325*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits -1
326*7c478bd9Sstevel@tonic-gate	bl	L.3.15
327*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
328*7c478bd9Sstevel@tonic-gate	! remainder is positive
329*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
330*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -1
331*7c478bd9Sstevel@tonic-gate	bl	L.4.15
332*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
333*7c478bd9Sstevel@tonic-gate	! remainder is positive
334*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
335*7c478bd9Sstevel@tonic-gate		b	9f
336*7c478bd9Sstevel@tonic-gate		add	%o2, (-1*2+1), %o2
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gateL.4.15:	! remainder is negative
339*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
340*7c478bd9Sstevel@tonic-gate		b	9f
341*7c478bd9Sstevel@tonic-gate		add	%o2, (-1*2-1), %o2
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gate
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gate
346*7c478bd9Sstevel@tonic-gateL.3.15:	! remainder is negative
347*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
348*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -3
349*7c478bd9Sstevel@tonic-gate	bl	L.4.13
350*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
351*7c478bd9Sstevel@tonic-gate	! remainder is positive
352*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
353*7c478bd9Sstevel@tonic-gate		b	9f
354*7c478bd9Sstevel@tonic-gate		add	%o2, (-3*2+1), %o2
355*7c478bd9Sstevel@tonic-gate
356*7c478bd9Sstevel@tonic-gateL.4.13:	! remainder is negative
357*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
358*7c478bd9Sstevel@tonic-gate		b	9f
359*7c478bd9Sstevel@tonic-gate		add	%o2, (-3*2-1), %o2
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-gate
367*7c478bd9Sstevel@tonic-gateL.2.15:	! remainder is negative
368*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
369*7c478bd9Sstevel@tonic-gate			!depth 3, accumulated bits -3
370*7c478bd9Sstevel@tonic-gate	bl	L.3.13
371*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
372*7c478bd9Sstevel@tonic-gate	! remainder is positive
373*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
374*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -5
375*7c478bd9Sstevel@tonic-gate	bl	L.4.11
376*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
377*7c478bd9Sstevel@tonic-gate	! remainder is positive
378*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
379*7c478bd9Sstevel@tonic-gate		b	9f
380*7c478bd9Sstevel@tonic-gate		add	%o2, (-5*2+1), %o2
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gateL.4.11:	! remainder is negative
383*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
384*7c478bd9Sstevel@tonic-gate		b	9f
385*7c478bd9Sstevel@tonic-gate		add	%o2, (-5*2-1), %o2
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gate
390*7c478bd9Sstevel@tonic-gateL.3.13:	! remainder is negative
391*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
392*7c478bd9Sstevel@tonic-gate			!depth 4, accumulated bits -7
393*7c478bd9Sstevel@tonic-gate	bl	L.4.9
394*7c478bd9Sstevel@tonic-gate	srl	%o5,1,%o5
395*7c478bd9Sstevel@tonic-gate	! remainder is positive
396*7c478bd9Sstevel@tonic-gate	subcc	%o3,%o5,%o3
397*7c478bd9Sstevel@tonic-gate		b	9f
398*7c478bd9Sstevel@tonic-gate		add	%o2, (-7*2+1), %o2
399*7c478bd9Sstevel@tonic-gate
400*7c478bd9Sstevel@tonic-gateL.4.9:	! remainder is negative
401*7c478bd9Sstevel@tonic-gate	addcc	%o3,%o5,%o3
402*7c478bd9Sstevel@tonic-gate		b	9f
403*7c478bd9Sstevel@tonic-gate		add	%o2, (-7*2-1), %o2
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
414*7c478bd9Sstevel@tonic-gate	9:
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gateend_regular_divide:
417*7c478bd9Sstevel@tonic-gate	deccc	%o4
418*7c478bd9Sstevel@tonic-gate	bge	divloop
419*7c478bd9Sstevel@tonic-gate	tst	%o3
420*7c478bd9Sstevel@tonic-gate	bl,a	got_result
421*7c478bd9Sstevel@tonic-gate	dec	%o2
422*7c478bd9Sstevel@tonic-gate
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gategot_result:
425*7c478bd9Sstevel@tonic-gate	tst	%g1
426*7c478bd9Sstevel@tonic-gate	bl,a	1f
427*7c478bd9Sstevel@tonic-gate	neg	%o2	! quotient  <- -%o2
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate1:
430*7c478bd9Sstevel@tonic-gate	retl
431*7c478bd9Sstevel@tonic-gate	mov	%o2,%o0	! quotient  <-  %o2
432*7c478bd9Sstevel@tonic-gate
433*7c478bd9Sstevel@tonic-gate
434*7c478bd9Sstevel@tonic-gatezero_divide:
435*7c478bd9Sstevel@tonic-gate	ta	ST_DIV0		! divide by zero trap
436*7c478bd9Sstevel@tonic-gate	retl			! if handled, ignored, return
437*7c478bd9Sstevel@tonic-gate	mov	0, %o0
438