home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / fpe / mulf.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  4.0 KB  |  135 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 "@(#)mulf.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(mulf, 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) */
  75.     andl3    $(0!(EXPMASK | SIGNBIT)),4(fp),r0
  76.     orl2    $(0!CLEARHID),r0
  77.     shll    $7,r0,r0    /* leave the sign bit cleared. */
  78.  
  79.     /* fetch seconed fraction: (r4) */
  80.     andl3    $(0!(EXPMASK | SIGNBIT)),12(fp),r4
  81.     orl2    $(0!CLEARHID),r4
  82.     shll    $7,r4,r4    /* leave the sign bit cleared. */
  83.  
  84.  
  85.     emul    r4,r0,$0,r0
  86.     movl    r0,r4        /* to see how much we realy need to shift. */
  87.     movl    $6,r5        /* r5 - shift counter. */
  88.     shrl    $7,r4,r4    /* dummy shift. */
  89. 1:    bbs    $HIDDEN,r4,realshift
  90.     shll    $1,r4,r4
  91.     decl    r2        /* update exponent. */
  92.     jeql    underflow
  93.     decl    r5        /* update shift counter. */
  94.     jmp    1b
  95. realshift:
  96.     shrl    r5,r0,r0
  97.     bbc    $0,r1,shiftmore
  98.     incl    r1        /* rounding. */
  99. shiftmore:
  100.     shrl    $1,r0,r0
  101. comb:
  102.     andl2    $CLEARHID,r0
  103.     shll    $EXPSHIFT,r2,r4
  104.     orl2    r4,r0
  105.     cmpl    r2,$256
  106.     jlss    1f
  107.     callf    $4,sfpover
  108. sign:
  109. 1:    bbc    $0,r3,done
  110.     orl2    $SIGNBIT,r0
  111. done:    ret
  112.  
  113.  
  114.  
  115. is_res1:
  116.     bbc     $31,4(fp),retzero
  117.     callf    $4,sfpresop
  118.     ret
  119. is_res2:
  120.     bbc     $31,12(fp),retzero
  121.     callf    $4,sfpresop
  122.     ret
  123.   retzero:
  124.       clrl    r0
  125.       ret
  126.   overflow:
  127.     callf    $4,sfpover
  128.     jmp    sign
  129.   underflow:
  130.     callf    $4,sfpunder
  131.     ret
  132.  
  133.  
  134.     
  135.