home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / fpe / divf.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  3.6 KB  |  115 lines

  1. /*
  2.  * Copyright (c) 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Computer Consoles Inc.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #if defined(SYSLIBC_SCCS) && !defined(lint)
  38.     .asciz "@(#)divf.s    1.3 (Berkeley) 6/1/90"
  39. #endif /* SYSLIBC_SCCS and not lint */
  40.  
  41. #include <tahoemath/fp.h>
  42. #include "DEFS.h"
  43.  
  44. #define    HIDDEN    23    /* here we count from 0 not from 1 as in fp.h */
  45.  
  46. XENTRY(divf, R2|R3|R4|R5|R6|R7|R8|R9)
  47.     clrl    r1
  48.     clrl    r3        # r3 - sign: 0 for positive,1 for negative.
  49.     movl    4(fp),r0
  50.     jgeq    1f
  51.     movl    $1,r3
  52. 1:    movl    12(fp),r2
  53.     jgeq    2f
  54.     bbc    $0,r3,1f    # seconed operand is negative.
  55.     clrl    r3        # if first was negative, make result positive.
  56.     jmp    2f
  57. 1:    movl    $1,r3        # if first was positive, make result negative.
  58. 2:    andl2    $EXPMASK,r0    # compute first 'pure'exponent.
  59.     jeql    is_res1
  60.     shrl    $EXPSHIFT,r0,r0
  61.     subl2    $BIAS,r0    
  62.     andl2    $EXPMASK,r2    # compute seconed 'pure'exponent.
  63.     jeql    is_res2
  64.     shrl    $EXPSHIFT,r2,r2
  65.     subl2    $BIAS,r2
  66.     subl3    r2,r0,r2    # subtruct the exponents.
  67.     addl2    $BIAS,r2
  68.     jleq    underf
  69.                 # normalization can make the exp. smaller.
  70.  #
  71.  #    We have the sign in r3,the exponent in r2,now is the time to
  72.  #     perform the division...
  73.  #
  74.     # fetch dividend. (r0)
  75.     andl3    $(0!(EXPMASK | SIGNBIT)),4(fp),r0
  76.     orl2    $(0!CLEARHID),r0
  77.     clrl    r1
  78.  
  79.     # fetch divisor : (r6)
  80.     andl3    $(0!(EXPMASK | SIGNBIT)),12(fp),r6
  81.     orl2    $(0!CLEARHID),r6
  82.  
  83.     shll    $2,r6,r6    # make the divisor bigger so we will not
  84.                 # get overflow at the divission.
  85.     ediv    r6,r0,r0,r7    # quo to r0, rem to r7
  86.     subl2    $6,r2        # to compensate for: normalization (-24),
  87.                 # ediv (+32), shifting r6 (-2).
  88.     
  89. over:
  90.     callf    $4,fnorm    # we can use fnorm because we have data
  91.                 # at r1 as well.(sfnorm takes care only 
  92.                 # of r0).
  93. sign:
  94. 1:    bbc    $0,r3,done
  95.     orl2    $SIGNBIT,r0
  96. done:    ret
  97.  
  98. is_res1:
  99.     bbc     $31,4(fp),retz
  100.     callf    $4,sfpresop
  101.     ret
  102. is_res2:
  103.     bbc     $31,12(fp),z_div
  104.     callf    $4,sfpresop
  105.     ret
  106. retz:
  107.       clrl    r0
  108.       ret
  109. underf:
  110.     callf    $4,sfpunder
  111.     ret
  112. z_div:
  113.     callf    $4,sfpzdiv
  114.     ret
  115.