home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / fpe / modf.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  4.7 KB  |  173 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 "@(#)modf.s    1.3 (Berkeley) 6/1/90"
  39. #endif /* SYSLIBC_SCCS and not lint */
  40.  
  41. /* 
  42.  *  double modf (value, iptr)
  43.  *  double value, *iptr;
  44.  * 
  45.  *  Modf returns the fractional part of "value",
  46.  *  and stores the integer part indirectly through "iptr".
  47.  */ 
  48. #include <tahoemath/fp.h>
  49. #include "DEFS.h"
  50.  
  51. ENTRY(modf, R2|R3|R4|R5)
  52.  /*
  53.  * Some initializations:
  54.  */
  55.     ldd    4(fp)        /* load accumulator, for converison    */
  56.     cvdl    r2        /*  to an integer.            */
  57.     bvs    gsb        /* iff too big grunt it out        */
  58.     cvld    r2        /* float the integer part        */
  59.     std    r2
  60.     ldd    4(fp)        /* isolate the fraction            */
  61.     subd    r2
  62.     std    r0
  63.     movl    12(fp),r6    /* get int return address */
  64.     movl    r2,(r6)
  65.     movl    r3,4(r6)
  66.     ret
  67. gsb:    clrl    r3
  68.     movl    4(fp),r0    /* fetch operand to r0,r1. */
  69.     movl    8(fp),r1    
  70.     movl    12(fp),r6    /* fetch addr of int to r6. */
  71.  /*
  72.  * get exponent
  73.  */
  74.     andl3    $EXPMASK,r0,r2    /* r2 will hold the exponent. */
  75.     jeql    is_reserved    /* check for reserved operand.  */
  76.     shrl    $EXPSHIFT,r2,r2
  77.     subl2    $BIAS,r2    /* unbias it.  */
  78.     jleq    allfrac        /* it's int part is  zero. */
  79.     cmpl    r2,$56
  80.     jgeq    allint        /* it's fraction part is zero. */
  81.  /*
  82.  * get fraction
  83.  */
  84.     movl    r0,r4        /* remember the original number. */
  85.     movl    r1,r5
  86.     bbc    $31,r0,positive    /* if negative remember it. */
  87.     incl    r3
  88. positive:
  89.                 /* clear the non fraction parts. */
  90.     andl2    $(0!(EXPMASK | SIGNBIT)),r0
  91.                 /* add the hidden bit. */
  92.     orl2    $(0!CLEARHID),r0
  93.  
  94.     cmpl    r2,$HID_POS    /* see if there are bits to clear only in r0 */
  95.                 /* or r1 has to be taken care of. */
  96.                 /* ( for fraction calculation) */
  97.  
  98.     jgtr    in_r1        /* some bytes in r1. */
  99.  
  100.     jeql    onlyallr0    /* all r0 must be cleared,r1 unchanged. */
  101.  
  102.                 /* only r0 must be canged. */
  103.     mnegl    r2,r7        /* r7 - loop counter. */
  104.     movl    $CLEARHID,r8    /* first bit to clear. */
  105. 1:
  106.     andl2    r8,r0        /* clear int. bits from fraction part. */
  107.     shar    $1,r8,r8
  108.     aoblss    $0,r7,1b
  109. 1:
  110.     andl2    r8,r4        /* clear frac bits for int calculation: */
  111.     shar    $1,r8,r8
  112.     cmpl    $0xffffffff,r8
  113.     jneq    1b
  114.     clrl    r5
  115.     jmp    norm
  116.  
  117. onlyallr0:
  118.     clrl    r0
  119.     clrl    r5
  120.     jmp     norm
  121.  
  122. in_r1:
  123.     clrl    r0        /* clear int part for frac. calculation. */
  124.     subl3    r2,$HID_POS,r7
  125.     movl    $0x7fffffff,r8
  126. 1:
  127.     andl2    r8,r1
  128.     shar    $1,r8,r8
  129.     orl2    $0x80000000,r8        /* force the 'sign' bit to be on. */
  130.     aoblss    $0,r7,1b
  131. 1:
  132.     andl2    r8,r5
  133.     shar    $1,r8,r8
  134.     cmpl    $0xffffffff,r8
  135.     jneq    1b
  136.  
  137. norm:
  138.     addl2    $BIAS,r2    /* fnorm expects it biased. */
  139.     callf    $4,fnorm    /* normelize fraction part. */
  140.     cmpl    $0,r0
  141.     jeql    1f
  142.     bbc    $0,r3,1f
  143.     orl2    $0x80000000,r0
  144. 1:
  145.     movl    r4,(r6)        /* put int part in place. */
  146.     movl    r5,4(r6)
  147.     ret
  148.  
  149. allint:
  150.     movl    r0,(r6)        /* copy the argument to the int addr. */
  151.     movl    r1,4(r6)
  152.     clrl    r0        /* clear the fraction part. */
  153.     clrl    r1
  154.     ret
  155.  
  156. allfrac:
  157.                 /* the fraction is ready in r0,r1. */
  158.     clrl    (r6)        /* zero the int part. */
  159.     clrl    4(r6)
  160.     ret
  161.  
  162. ret_zero:
  163.     clrl    (r6)
  164.     clrl    4(r6)
  165.     clrl    r0
  166.     clrl    r1
  167.     ret
  168.  
  169. is_reserved:
  170.     bbc    $31,r0,ret_zero
  171.     callf     $4,fpresop
  172.     ret
  173.