home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / fpe / divd.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  3.7 KB  |  132 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 "@(#)divd.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(divd, R2|R3|R4|R5|R6|R7|R8|R9)
  47.     clrl    r3        # r3 - sign: 0 for positive,1 for negative.
  48.     movl    4(fp),r0
  49.     jgeq    1f
  50.     movl    $1,r3
  51. 1:    movl    12(fp),r2
  52.     jgeq    2f
  53.     bbc    $0,r3,1f    # seconed operand is negative.
  54.     clrl    r3        # if first was negative, make result positive.
  55.     jmp    2f
  56. 1:    movl    $1,r3        # if first was positive, make result negative.
  57. 2:    andl2    $EXPMASK,r0    # compute first 'pure'exponent.
  58.     jeql    is_res1
  59.     shrl    $EXPSHIFT,r0,r0
  60.     subl2    $BIAS,r0    
  61.     andl2    $EXPMASK,r2    # compute seconed 'pure'exponent.
  62.     jeql    is_res2
  63.     shrl    $EXPSHIFT,r2,r2
  64.     subl2    $BIAS,r2
  65.     subl3    r2,r0,r2    # subtruct the exponents.
  66.     addl2    $BIAS,r2
  67.     jleq    underf
  68.                 # normalization can make the exp. smaller.
  69.  #
  70.  #    We have the sign in r3,the exponent in r2,now is the time to
  71.  #     perform the division...
  72.  #
  73.     # fetch dividend. (r4,r5)
  74.     andl3    $(0!(EXPMASK | SIGNBIT)),4(fp),r4
  75.     orl2    $(0!CLEARHID),r4
  76.     movl    8(fp),r5
  77.  
  78.     # fetch divisor : (r6,r7)
  79.     andl3    $(0!(EXPMASK | SIGNBIT)),12(fp),r6
  80.     orl2    $(0!CLEARHID),r6
  81.     movl    16(fp),r7
  82.  
  83.     movl    $0,r0        # init r0,r1 to be zeros
  84.     movl    $0,r1
  85.     movl    $(0!CLEARHID),r8# r8 first bit to set (if).
  86.     shll    $1,r8,r8    # to have one more bit,because we might
  87.                 # have to shift left to normelize.
  88.     movl    $0,r9
  89.  
  90. 2:
  91.     subl2    r7,r5
  92.     sbwc    r6,r4
  93.     jgeq    1f
  94.     addl2    r7,r5
  95.     adwc    r6,r4
  96.     shlq    $1,r4,r4
  97.     shrq    $1,r8,r8
  98.     jeql    over
  99.     jmp    2b
  100. 1:    
  101.     orl2    r8,r0
  102.     orl2    r9,r1
  103.     shlq    $1,r4,r4
  104.     shrq    $1,r8,r8
  105.     jneq    2b
  106.     
  107. over:
  108.     callf    $4,fnorm
  109. sign:
  110. 1:    bbc    $0,r3,done
  111.     orl2    $SIGNBIT,r0
  112. done:    ret
  113.  
  114. is_res1:
  115.     bbc     $31,4(fp),retz
  116.     callf    $4,fpresop
  117.     ret
  118. is_res2:
  119.     bbc     $31,12(fp),z_div
  120.     callf    $4,fpresop
  121.     ret
  122. retz:
  123.       clrl    r0
  124.       clrl    r1
  125.       ret
  126. underf:
  127.     callf    $4,fpunder
  128.     ret
  129. z_div:
  130.     callf    $4,fpzdiv
  131.     ret
  132.