home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / tahoe / math / Kmuld.s < prev    next >
Encoding:
Text File  |  1991-05-04  |  4.6 KB  |  146 lines

  1. /*-
  2.  * Copyright (c) 1985 The 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.  *    @(#)Kmuld.s    7.1 (Berkeley) 12/6/90
  37.  */
  38.  
  39. #include "../math/fp.h"
  40. #include "../math/Kfp.h"
  41. #include "../tahoe/SYS.h"
  42.  
  43. #define    HIDDEN    23    /* here we count from 0 not from 1 as in fp.h */
  44.  
  45. /*
  46.  * _Kmuld(acc_most,acc_least,op_most,op_least,hfs)
  47.  */
  48.     .text
  49. ENTRY(Kmuld, R9|R8|R7|R6|R5|R4|R3|R2)
  50.     clrl    r3        /* r3 - sign: 0 for positive,1 for negative. */
  51.     movl    4(fp),r0
  52.     jgeq    1f
  53.     movl    $1,r3
  54. 1:    movl    12(fp),r2
  55.     jgeq    2f
  56.     bbc    $0,r3,1f    /* seconed operand is negative. */
  57.     clrl    r3        /* if first was neg, make result pos */
  58.     jmp    2f
  59. 1:    movl    $1,r3        /* if first was pos, make result neg */
  60. 2:    andl2    $EXPMASK,r0    /* compute first 'pure'exponent. */
  61.     jeql    retzero
  62.     shrl    $EXPSHIFT,r0,r0
  63.     subl2    $BIASP1,r0    
  64.     andl2    $EXPMASK,r2    /* compute seconed 'pure'exponent. */
  65.     jeql    retzero
  66.     shrl    $EXPSHIFT,r2,r2
  67.     subl2    $BIASP1,r2
  68.     addl2    r0,r2        /* add the exponents. */
  69.     addl2    $(BIASP1+2),r2
  70.     jleq    underflow
  71.     cmpl    r2,$258        /* normalization can make the exp. smaller. */
  72.     jgeq    overflow
  73.  /*
  74.   *    We have the sign in r3,the exponent in r2,now is the time to
  75.   *     perform the multiplication...
  76.   */
  77.     /* fetch first fraction: (r0,r1) */
  78.     andl3    $(0!(EXPMASK | SIGNBIT)),4(fp),r0
  79.     orl2    $(0!CLEARHID),r0
  80.     movl    8(fp),r1
  81.     shlq    $7,r0,r0    /* leave the sign bit cleared. */
  82.  
  83.     /* fetch seconed fraction: (r4,r5) */
  84.     andl3    $(0!(EXPMASK | SIGNBIT)),12(fp),r4
  85.     orl2    $(0!CLEARHID),r4
  86.     movl    16(fp),r5
  87.     shlq    $7,r4,r4    /* leave the sign bit cleared. */
  88.  
  89.     /* in the following lp1 stands for least significant part of operand 1,
  90.     *           lp2 for least significant part of operand 2,
  91.     *           mp1 for most significant part of operand 1,
  92.     *           mp2 for most significant part of operand 2.
  93.     */
  94.  
  95.     clrl     r6
  96.     shrl    $1,r1,r1    /* clear the sign bit of the lp1. */
  97.     jeql    1f
  98.     emul    r1,r4,$0,r6    /* r6,r7 <-- lp1*mp2 */
  99.     shlq    $1,r6,r6    /* to compensate for the shift we did to clear the sign bit. */
  100. 1:    shrl    $1,r5,r5    /* clear the sign bit of the lp2. */
  101.     jeql    1f
  102.     emul    r0,r5,$0,r8    /* r8,r9 <-- mp1*lp2 */
  103.     shlq    $1,r8,r8
  104.     addl2    r9,r7        /* r6,r7 <-- the sum of the products. */
  105.     adwc    r8,r6
  106. 1:    emul    r0,r4,$0,r0    /* r0,r1 <-- mp1*mp2  */
  107.     addl2    r6,r1        /* add the most sig. part of the sum. */
  108.     adwc    $0,r0
  109.     movl    r0,r4        /* to see how much we realy need to shift. */
  110.     movl    $6,r5        /* r5 - shift counter. */
  111.     shrl    $7,r4,r4    /* dummy shift. */
  112. 1:    bbs    $HIDDEN,r4,realshift
  113.     shll    $1,r4,r4
  114.     decl    r2        /* update exponent. */
  115.     jeql    underflow
  116.     decl    r5        /* update shift counter. */
  117.     jmp    1b
  118. realshift:
  119.     shrq    r5,r0,r0
  120.     bbc    $0,r1,shiftmore
  121.     incl    r1        /* rounding. */
  122. shiftmore:
  123.     shrq    $1,r0,r0
  124. comb:
  125.     andl2    $CLEARHID,r0
  126.     shll    $EXPSHIFT,r2,r4
  127.     orl2    r4,r0
  128.     cmpl    r2,$256
  129.     jlss    1f
  130.     orl2    $HFS_OVF,*20(fp)    
  131. sign:
  132. 1:    bbc    $0,r3,done
  133.     orl2    $SIGNBIT,r0
  134. done:    ret
  135.  
  136. retzero:
  137.     clrl    r0
  138.     clrl    r1
  139.     ret
  140. overflow:
  141.     orl2    $HFS_OVF,*20(fp)
  142.     ret
  143. underflow:
  144.     orl2    $HFS_UNDF,*20(fp)
  145.     ret
  146.