/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
! .seg "data"
! .asciz "Copyr 1986 Sun Micro"
.seg "text"
#ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 1986 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*
* Input is:
* dividend -- the thing being divided
* divisor -- how many ways to divide
* Important parameters:
* N -- how many bits per iteration we try to get
* as our current guess:
* WORDSIZE -- how many bits altogether we're talking about:
* obviously:
* A derived constant:
* TOPBITS -- how many bits are in the top "decade" of a number:
*
* Important variables are:
* Q -- the partial quotient under development -- initally 0
* R -- the remainder so far -- initially == the dividend
* ITER -- number of iterations of the main division loop will
* be required. Equal to CEIL( lg2(quotient)/4 )
* Note that this is log_base_(2^4) of the quotient.
* V -- the current comparand -- initially divisor*2^(ITER*4-1)
* Cost:
* current estimate for non-large dividend is
* CEIL( lg2(quotient) / 4 ) x ( 10 + 74/2 ) + C
* a large dividend is one greater than 2^(31-4 ) and takes a
* different path, as the upper bits of the quotient must be developed
* one bit at a time.
*/
#include <sys/asm_linkage.h>
/*
* this is the recursive definition of how we develop quotient digits.
* it takes three important parameters:
* $1 -- the current depth, 1<=$1<=4
* $2 -- the current accumulation of quotient bits
* 4 -- max depth
* We add a new bit to $2 and either recurse or
* insert the bits in the quotient.
* Dynamic input:
* %o3 -- current remainder
* %o2 -- current quotient
* %o5 -- current comparand
* cc -- set on current value of %o3
* Dynamic output:
* %o3', %o2', %o5', cc'
*/
.udiv:
b divide
.div:
bge 2f
! %o1 < 0
2:
! %o0 < 0
0:
mov 0,%o2
sethi %hi(1<<(32-4 -1)),%g2
cmp %o3,%g2
blu not_really_big
mov 0,%o4
!
! here, the %o0 is >= 2^(31-4) or so. We must be careful here, as
! our usual 4-at-a-shot divide step will cause overflow and havoc. The
! total number of bits in the result here is 4*%o4+%g3, where %g3 <= 4.
! compute %o4, in an unorthodox manner: know we need to Shift %o5 into
1:
bgeu 3f
b 1b
!
blu 2b
!
bl 1f
! %o3 >= 0
b 2f
1: ! %o3 < 0
2:
1:
bleu 1b
bl L.1.16
bl L.2.17
bl L.3.19
bl L.4.23
b 9f
b 9f
bl L.4.21
b 9f
b 9f
bl L.3.17
bl L.4.19
b 9f
b 9f
bl L.4.17
b 9f
b 9f
bl L.2.15
bl L.3.15
bl L.4.15
b 9f
b 9f
bl L.4.13
b 9f
b 9f
bl L.3.13
bl L.4.11
b 9f
b 9f
bl L.4.9
b 9f
b 9f
9:
bl,a got_result
bl,a 1f
1: