home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bsd / src / libm / libm-amiga / mc68881 / support.s < prev    next >
Text File  |  1993-09-23  |  4KB  |  156 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * the Systems Programming Group of the University of Utah Computer
  7.  * Science Department.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  *
  37.  *    @(#)support.s    5.2 (Berkeley) 5/17/90
  38.  */
  39.  
  40.     .text
  41.     .globl    _copysign, _finite, _scalb, _logb, _drem, _pow_p, _atan2__A
  42.  
  43. | copysign(x,y) 
  44. | returns x with the sign of y. 
  45. _copysign:
  46.     movl    sp@(4),d0
  47.     movl    sp@(8),d1
  48.     tstw    sp@(12)
  49.     jmi    Lneg
  50.     bclr    #31,d0
  51.     rts
  52. Lneg:
  53.     bset    #31,d0
  54.     rts
  55.  
  56. | finite(x)
  57. | returns the value TRUE if -INF < x < +INF and returns FALSE otherwise.
  58. _finite:
  59.     movw    #0x7FF0,d0
  60.     movw    sp@(4),d1
  61.     andw    d0,d1
  62.     cmpw    d0,d1
  63.     beq    Lnotfin
  64.     moveq    #1,d0
  65.     rts
  66. Lnotfin:
  67.     clrl    d0
  68.     rts
  69.  
  70. | scalb(x, N)
  71. | returns  x * (2**N), for integer values N.
  72. _scalb:
  73.     fmoved    sp@(4),fp0
  74.     fbeq    Ldone
  75.     fscalel    sp@(12),fp0
  76. Ldone:
  77.     fmoved    fp0,sp@-
  78.     movel    sp@+,d0
  79.     movel    sp@+,d1
  80.     rts
  81.  
  82. | logb(x)
  83. | returns the unbiased exponent of x, a signed integer in double precision,
  84. | except that logb(0) is -INF, logb(INF) is +INF, and logb(NAN) is that NAN.
  85. _logb:
  86.     movw    sp@(4),d0
  87.     movw    #0x7FF0,d1    | exponent bits
  88.     andw    d1,d0        | mask off all else
  89.     cmpw    d1,d0        | max exponent?
  90.     bne    Lfinite        | no, is finite
  91.     fmoved    sp@(4),fp0    | yes, infinite or NaN
  92.     fbun    Ldone        | NaN returns NaN
  93.     fabsx    fp0        | +-inf returns inf
  94.     jra    Ldone
  95. Lfinite:
  96.     fmoved    sp@(4),fp0    | get entire number
  97.     fbne    Lnonz        | zero?
  98.     flog2x    fp0        | yes, log(0) a convenient source of -inf
  99.     jra    Ldone
  100. Lnonz:
  101.     fgetexpx    fp0    | get exponent
  102.     jra    Ldone
  103.  
  104. | drem(x,y)
  105. | returns  x REM y  =  x - [x/y]*y , where [x/y] is the integer nearest x/y;
  106. | in half way case, choose the even one.
  107. _drem:
  108.     fmoved    sp@(4),fp0
  109.     fremd    sp@(12),fp0
  110.     fmoved    fp0,sp@-
  111.     movel    sp@+,d0
  112.     movel    sp@+,d1
  113.     rts
  114.  
  115. | pow_p(x,y)
  116. | return x**y for x with sign=1 and finite y
  117. _pow_p:
  118.     flognd    sp@(4),fp0
  119.     fmuld    sp@(12),fp0
  120.     fetoxx    fp0
  121.     fmoved    fp0,sp@-
  122.     movel    sp@+,d0
  123.     movel    sp@+,d1
  124.     rts
  125.  
  126. | atan2__A(y,x)
  127. | compute atan2(y,x) where x,y are finite and non-zero
  128. | called by atan2() after weeding out all the special cases
  129. _atan2__A:
  130.     moveq    #0,d0        | sign of result
  131.     fmoved    sp@(4),fp0    | get y
  132.     fboge    Lypos        | <0?
  133.     moveq    #1,d0        | yes, result is neg
  134.     fnegx    fp0        | make y pos
  135. Lypos:
  136.     fmoved    sp@(12),fp1    | get x
  137.     fboge    Lxpos        | <0?
  138.     fnegx    fp1        | yes, make x pos
  139.     fdivx    fp1,fp0        | y/x
  140.     fatanx    fp0,fp1        | atan(y/x)
  141.     fmovecr    #0,fp0        | get pi
  142.     fsubx    fp1,fp0        | pi - atan(y/x)
  143.     jra    Lsetsign
  144. Lxpos:
  145.     fdivx    fp1,fp0        | y/x
  146.     fatanx    fp0        | atan(y/x)
  147. Lsetsign:
  148.     tstl    d0        | should be neg?
  149.     jeq    Lrpos        | no, all done
  150.     fnegx    fp0        | yes, negate
  151. Lrpos:
  152.     fmoved    fp0,sp@-
  153.     movel    sp@+,d0
  154.     movel    sp@+,d1
  155.     rts
  156.