home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / fpe / muld.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  4.7 KB  |  153 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 "@(#)muld.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(muld, 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    $BIASP1,r0    
  61.     andl2    $EXPMASK,r2    /* compute seconed 'pure'exponent. */
  62.     jeql    is_res2
  63.     shrl    $EXPSHIFT,r2,r2
  64.     subl2    $BIASP1,r2
  65.     addl2    r0,r2        /* add the exponents. */
  66.     addl2    $(BIASP1+2),r2
  67.     jleq    underflow
  68.     cmpl    r2,$258        /* normalization can make the exp. smaller. */
  69.     jgeq    overflow
  70.  /*
  71.  *    We have the sign in r3,the exponent in r2,now is the time to
  72.  *     perform the multiplication...
  73.  */
  74.     /* fetch first fraction: (r0,r1) */
  75.     andl3    $(0!(EXPMASK | SIGNBIT)),4(fp),r0
  76.     orl2    $(0!CLEARHID),r0
  77.     movl    8(fp),r1
  78.     shlq    $7,r0,r0    /* leave the sign bit cleared. */
  79.  
  80.     /* fetch seconed fraction: (r4,r5) */
  81.     andl3    $(0!(EXPMASK | SIGNBIT)),12(fp),r4
  82.     orl2    $(0!CLEARHID),r4
  83.     movl    16(fp),r5
  84.     shlq    $7,r4,r4    /* leave the sign bit cleared. */
  85.  
  86.     /* in the following lp1 stands for least significant part of operand 1,
  87.     *           lp2 for least significant part of operand 2,
  88.     *           mp1 for most significant part of operand 1,
  89.     *           mp2 for most significant part of operand 2.
  90.     */
  91.  
  92.     clrl     r6
  93.     shrl    $1,r1,r1    /* clear the sign bit of the lp1. */
  94.     jeql    1f
  95.     emul    r1,r4,$0,r6    /* r6,r7 <-- lp1*mp2 */
  96.     shlq    $1,r6,r6    /* to compensate for the shift we did to clear the sign bit. */
  97. 1:    shrl    $1,r5,r5    /* clear the sign bit of the lp2. */
  98.     jeql    1f
  99.     emul    r0,r5,$0,r8    /* r8,r9 <-- mp1*lp2 */
  100.     shlq    $1,r8,r8
  101.     addl2    r9,r7        /* r6,r7 <-- the sum of the products. */
  102.     adwc    r8,r6
  103. 1:    emul    r0,r4,$0,r0    /* r0,r1 <-- mp1*mp2  */
  104.     addl2    r6,r1        /* add the most sig. part of the sum. */
  105.     adwc    $0,r0
  106.     movl    r0,r4        /* to see how much we realy need to shift. */
  107.     movl    $6,r5        /* r5 - shift counter. */
  108.     shrl    $7,r4,r4    /* dummy shift. */
  109. 1:    bbs    $HIDDEN,r4,realshift
  110.     shll    $1,r4,r4
  111.     decl    r2        /* update exponent. */
  112.     jeql    underflow
  113.     decl    r5        /* update shift counter. */
  114.     jmp    1b
  115. realshift:
  116.     shrq    r5,r0,r0
  117.     bbc    $0,r1,shiftmore
  118.     incl    r1        /* rounding. */
  119. shiftmore:
  120.     shrq    $1,r0,r0
  121. comb:
  122.     andl2    $CLEARHID,r0
  123.     shll    $EXPSHIFT,r2,r4
  124.     orl2    r4,r0
  125.     cmpl    r2,$256
  126.     jlss    1f
  127.     callf    $4,fpover
  128. sign:
  129. 1:    bbc    $0,r3,done
  130.     orl2    $SIGNBIT,r0
  131. done:    ret
  132.  
  133.  
  134.  
  135. is_res1:
  136.     bbc     $31,4(fp),retzero
  137.     callf    $4,fpresop
  138.     ret
  139. is_res2:
  140.     bbc     $31,12(fp),retzero
  141.     callf    $4,fpresop
  142.     ret
  143.   retzero:
  144.       clrl    r0
  145.       clrl    r1
  146.       ret
  147.   overflow:
  148.     callf    $4,fpover
  149.     jmp    sign
  150.   underflow:
  151.     callf    $4,fpunder
  152.     ret
  153.