1
/* $Id: urem.S,v 1.2 2001/06/06 17:04:50 bencollins Exp $
2
* urem.S: This routine was taken from glibc-1.09 and is covered
3
* by the GNU Library General Public License Version 2.
6
/* This file is generated from divrem.m4; DO NOT EDIT! */
8
* Division and remainder, from Appendix E of the Sparc Version 8
9
* Architecture Manual, with fixes from Gordon Irlam.
13
* Input: dividend and divisor in %o0 and %o1 respectively.
16
* .urem name of function to generate
17
* rem rem=div => %o0 / %o1; rem=rem => %o0 % %o1
18
* false false=true => signed; false=false => unsigned
20
* Algorithm parameters:
21
* N how many bits per iteration we try to get (4)
22
* WORDSIZE total number of bits (32)
25
* TOPBITS number of bits in the top decade of a number
27
* Important variables:
28
* Q the partial quotient under development (initially 0)
29
* R the remainder so far, initially the dividend
30
* ITER number of main division loop iterations required;
31
* equal to ceil(log2(quotient) / N). Note that this
32
* is the log base (2^N) of the quotient.
33
* V the current comparand, initially divisor*2^(ITER*N-1)
36
* Current estimate for non-large dividend is
37
* ceil(log2(quotient) / N) * (10 + 7N/2) + C
38
* A large dividend is one greater than 2^(31-TOPBITS) and takes a
39
* different path, as the upper bits of the quotient must be developed
46
! Ready to divide. Compute size of quotient; scale comparand.
51
! Divide by zero trap. If it returns, return 0 (about as
52
! wrong as possible, but that is what SunOS does...).
53
! ta ST_DIV0 -- Not for SILO
58
cmp %o3, %o5 ! if %o1 exceeds %o0, done
59
blu Lgot_result ! (and algorithm fails otherwise)
62
sethi %hi(1 << (32 - 4 - 1)), %g1
68
! Here the dividend is >= 2**(31-N) or so. We must be careful here,
69
! as our usual N-at-a-shot divide step will cause overflow and havoc.
70
! The number of bits in the result here is N*ITER+SC, where SC <= N.
71
! Compute ITER in an unorthodox manner: know we need to shift V into
72
! the top decade: so do not even bother to compare to R.
89
! We get here if the %o1 overflowed while shifting.
90
! This means that %o3 has the high-order bit set.
91
! Restore %o5 and subtract from %o3.
92
sll %g1, 4, %g1 ! high order bit
93
srl %o5, 1, %o5 ! rest of %o5
107
/* NB: these are commented out in the V8-Sparc manual as well */
108
/* (I do not understand this) */
109
! %o5 > %o3: went too far: back up 1 step
112
! do single-bit divide steps
114
! We have to be careful here. We know that %o3 >= %o5, so we can do the
115
! first divide step without thinking. BUT, the others are conditional,
116
! and are only done if %o3 >= 0. Because both %o3 and %o5 may have the high-
117
! order bit set in the first step, just falling into the regular
118
! division loop will mess up the first time around.
119
! So we unroll slightly...
122
bl Lend_regular_divide
128
b Lend_single_divloop
147
b,a Lend_regular_divide
160
tst %o3 ! set up for initial iteration
163
! depth 1, accumulated bits 0
166
! remainder is positive
168
! depth 2, accumulated bits 1
171
! remainder is positive
173
! depth 3, accumulated bits 3
176
! remainder is positive
178
! depth 4, accumulated bits 7
181
! remainder is positive
184
add %o2, (7*2+1), %o2
187
! remainder is negative
190
add %o2, (7*2-1), %o2
193
! remainder is negative
195
! depth 4, accumulated bits 5
198
! remainder is positive
201
add %o2, (5*2+1), %o2
204
! remainder is negative
207
add %o2, (5*2-1), %o2
210
! remainder is negative
212
! depth 3, accumulated bits 1
215
! remainder is positive
217
! depth 4, accumulated bits 3
220
! remainder is positive
223
add %o2, (3*2+1), %o2
226
! remainder is negative
229
add %o2, (3*2-1), %o2
232
! remainder is negative
234
! depth 4, accumulated bits 1
237
! remainder is positive
240
add %o2, (1*2+1), %o2
243
! remainder is negative
246
add %o2, (1*2-1), %o2
249
! remainder is negative
251
! depth 2, accumulated bits -1
254
! remainder is positive
256
! depth 3, accumulated bits -1
259
! remainder is positive
261
! depth 4, accumulated bits -1
264
! remainder is positive
267
add %o2, (-1*2+1), %o2
270
! remainder is negative
273
add %o2, (-1*2-1), %o2
276
! remainder is negative
278
! depth 4, accumulated bits -3
281
! remainder is positive
284
add %o2, (-3*2+1), %o2
287
! remainder is negative
290
add %o2, (-3*2-1), %o2
293
! remainder is negative
295
! depth 3, accumulated bits -3
298
! remainder is positive
300
! depth 4, accumulated bits -5
303
! remainder is positive
306
add %o2, (-5*2+1), %o2
309
! remainder is negative
312
add %o2, (-5*2-1), %o2
315
! remainder is negative
317
! depth 4, accumulated bits -7
320
! remainder is positive
323
add %o2, (-7*2+1), %o2
326
! remainder is negative
329
add %o2, (-7*2-1), %o2
338
! non-restoring fixup here (one instruction only!)