4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 ! .asciz "Copyr 1986 Sun Micro"
27 #ident "%Z%%M% %I% %E% SMI"
30 * Copyright 1986 Sun Microsystems, Inc. All rights reserved.
31 * Use is subject to license terms.
38 * dividend -- the thing being divided
39 * divisor -- how many ways to divide
40 * Important parameters:
41 * N -- how many bits per iteration we try to get
42 * as our current guess:
43 * WORDSIZE -- how many bits altogether we're talking about:
46 * TOPBITS -- how many bits are in the top "decade" of a number:
48 * Important variables are:
49 * Q -- the partial quotient under development -- initally 0
50 * R -- the remainder so far -- initially == the dividend
51 * ITER -- number of iterations of the main division loop will
52 * be required. Equal to CEIL( lg2(quotient)/4 )
53 * Note that this is log_base_(2^4) of the quotient.
54 * V -- the current comparand -- initially divisor*2^(ITER*4-1)
56 * current estimate for non-large dividend is
57 * CEIL( lg2(quotient) / 4 ) x ( 10 + 74/2 ) + C
58 * a large dividend is one greater than 2^(31-4 ) and takes a
59 * different path, as the upper bits of the quotient must be developed
64 #include <sys/asm_linkage.h>
77 * this is the recursive definition of how we develop quotient digits.
78 * it takes three important parameters:
79 * $1 -- the current depth, 1<=$1<=4
80 * $2 -- the current accumulation of quotient bits
82 * We add a new bit to $2 and either recurse or
83 * insert the bits in the quotient.
85 * %o3 -- current remainder
86 * %o2 -- current quotient
87 * %o5 -- current comparand
88 * cc -- set on current value of %o3
90 * %o3', %o2', %o5', cc'
96 ! RTENTRY
(.urem) ! UNSIGNED REMAINDER
100 mov
0,%g1
! result always positive
102 ! RTENTRY
(.rem) ! SIGNED REMAINDER
105 orcc
%o1
,%o0
,%g0
! are either
%o0
or %o1 negative
106 bge divide
! if
not, skip this junk
107 mov
%o0
,%g1
! record sign of result in sign of
%g1
121 ! compute size of quotient
, scale comparand
122 orcc
%o1
,%g0
,%o5
! movcc
%o1
,%o5
129 blu got_result
! if
%o3
<%o5 already
, there
's no point in continuing
131 sethi %hi(1<<(32-4 -1)),%g2
136 ! here, the %o0 is >= 2^(31-4) or so. We must be careful here, as
137 ! our usual 4-at-a-shot divide step will cause overflow and havoc. The
138 ! total number of bits in the result here is 4*%o4+%g3, where %g3 <= 4.
139 ! compute %o4, in an unorthodox manner: know we need to Shift %o5 into
140 ! the top decade: so don't even bother to compare to
%o3.
150 bcc not_too_big
! bcc not_too_big
153 ! here if the
%o1 overflowed when Shifting
154 ! this means that
%o3 has the high-order bit set
155 ! restore
%o5
and subtract from
%o3
156 sll
%g2
,4 ,%g2
! high order bit
157 srl
%o5
,1,%o5
! rest of
%o5
167 ! %o5
> %o3
: went too far
: back up
1 step
170 ! do single-bit divide steps
172 ! we have to
be careful here. We know that
%o3
>= %o5
, so we can do the
173 ! first divide step without thinking. BUT
, the others are conditional
,
174 ! and are only done if
%o3
>= 0. Because both %o3 and %o5 may have the high-
175 ! order bit set in the first step
, just falling into the regular
176 ! division loop will mess up the first time around.
177 ! So we unroll slightly.
..
180 bl end_regular_divide
184 b,a end_single_divloop
201 b,a end_regular_divide
213 ! do the main division iteration
215 ! fall through into divide loop
218 !depth
1, accumulated bits
0
221 ! remainder is positive
223 !depth
2, accumulated bits
1
226 ! remainder is positive
228 !depth
3, accumulated bits
3
231 ! remainder is positive
233 !depth
4, accumulated bits
7
236 ! remainder is positive
239 add %o2
, (7*2+1), %o2
241 L.4
.23: ! remainder is negative
244 add %o2
, (7*2-1), %o2
249 L.3
.19: ! remainder is negative
251 !depth
4, accumulated bits
5
254 ! remainder is positive
257 add %o2
, (5*2+1), %o2
259 L.4
.21: ! remainder is negative
262 add %o2
, (5*2-1), %o2
270 L.2
.17: ! remainder is negative
272 !depth
3, accumulated bits
1
275 ! remainder is positive
277 !depth
4, accumulated bits
3
280 ! remainder is positive
283 add %o2
, (3*2+1), %o2
285 L.4
.19: ! remainder is negative
288 add %o2
, (3*2-1), %o2
293 L.3
.17: ! remainder is negative
295 !depth
4, accumulated bits
1
298 ! remainder is positive
301 add %o2
, (1*2+1), %o2
303 L.4
.17: ! remainder is negative
306 add %o2
, (1*2-1), %o2
317 L.1
.16: ! remainder is negative
319 !depth
2, accumulated bits
-1
322 ! remainder is positive
324 !depth
3, accumulated bits
-1
327 ! remainder is positive
329 !depth
4, accumulated bits
-1
332 ! remainder is positive
335 add %o2
, (-1*2+1), %o2
337 L.4
.15: ! remainder is negative
340 add %o2
, (-1*2-1), %o2
345 L.3
.15: ! remainder is negative
347 !depth
4, accumulated bits
-3
350 ! remainder is positive
353 add %o2
, (-3*2+1), %o2
355 L.4
.13: ! remainder is negative
358 add %o2
, (-3*2-1), %o2
366 L.2
.15: ! remainder is negative
368 !depth
3, accumulated bits
-3
371 ! remainder is positive
373 !depth
4, accumulated bits
-5
376 ! remainder is positive
379 add %o2
, (-5*2+1), %o2
381 L.4
.11: ! remainder is negative
384 add %o2
, (-5*2-1), %o2
389 L.3
.13: ! remainder is negative
391 !depth
4, accumulated bits
-7
394 ! remainder is positive
397 add %o2
, (-7*2+1), %o2
399 L.4
.9: ! remainder is negative
402 add %o2
, (-7*2-1), %o2
426 neg %o3
! remainder
<- -%o3
430 mov
%o3
,%o0
! remainder
<- %o3
434 ta ST_DIV0
! divide by zero
trap
435 retl
! if handled
, ignored
, return