[BACK]Return to scosh.sa CVS log [TXT][DIR] Up to [local] / sys / arch / m68k / fpsp

Annotation of sys/arch/m68k/fpsp/scosh.sa, Revision 1.1.1.1

1.1       nbrk        1: *      $OpenBSD: scosh.sa,v 1.2 1996/05/29 21:05:36 niklas Exp $
                      2: *      $NetBSD: scosh.sa,v 1.2 1994/10/26 07:49:39 cgd Exp $
                      3:
                      4: *      MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
                      5: *      M68000 Hi-Performance Microprocessor Division
                      6: *      M68040 Software Package
                      7: *
                      8: *      M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
                      9: *      All rights reserved.
                     10: *
                     11: *      THE SOFTWARE is provided on an "AS IS" basis and without warranty.
                     12: *      To the maximum extent permitted by applicable law,
                     13: *      MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
                     14: *      INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
                     15: *      PARTICULAR PURPOSE and any warranty against infringement with
                     16: *      regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
                     17: *      and any accompanying written materials.
                     18: *
                     19: *      To the maximum extent permitted by applicable law,
                     20: *      IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
                     21: *      (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
                     22: *      PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
                     23: *      OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
                     24: *      SOFTWARE.  Motorola assumes no responsibility for the maintenance
                     25: *      and support of the SOFTWARE.
                     26: *
                     27: *      You are hereby granted a copyright license to use, modify, and
                     28: *      distribute the SOFTWARE so long as this entire notice is retained
                     29: *      without alteration in any modified and/or redistributed versions,
                     30: *      and that such modified versions are clearly identified as such.
                     31: *      No licenses are granted by implication, estoppel or otherwise
                     32: *      under any patents or trademarks of Motorola, Inc.
                     33:
                     34: *
                     35: *      scosh.sa 3.1 12/10/90
                     36: *
                     37: *      The entry point sCosh computes the hyperbolic cosine of
                     38: *      an input argument; sCoshd does the same except for denormalized
                     39: *      input.
                     40: *
                     41: *      Input: Double-extended number X in location pointed to
                     42: *              by address register a0.
                     43: *
                     44: *      Output: The value cosh(X) returned in floating-point register Fp0.
                     45: *
                     46: *      Accuracy and Monotonicity: The returned result is within 3 ulps in
                     47: *              64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
                     48: *              result is subsequently rounded to double precision. The
                     49: *              result is provably monotonic in double precision.
                     50: *
                     51: *      Speed: The program sCOSH takes approximately 250 cycles.
                     52: *
                     53: *      Algorithm:
                     54: *
                     55: *      COSH
                     56: *      1. If |X| > 16380 log2, go to 3.
                     57: *
                     58: *      2. (|X| <= 16380 log2) Cosh(X) is obtained by the formulae
                     59: *              y = |X|, z = exp(Y), and
                     60: *              cosh(X) = (1/2)*( z + 1/z ).
                     61: *              Exit.
                     62: *
                     63: *      3. (|X| > 16380 log2). If |X| > 16480 log2, go to 5.
                     64: *
                     65: *      4. (16380 log2 < |X| <= 16480 log2)
                     66: *              cosh(X) = sign(X) * exp(|X|)/2.
                     67: *              However, invoking exp(|X|) may cause premature overflow.
                     68: *              Thus, we calculate sinh(X) as follows:
                     69: *              Y       := |X|
                     70: *              Fact    :=      2**(16380)
                     71: *              Y'      := Y - 16381 log2
                     72: *              cosh(X) := Fact * exp(Y').
                     73: *              Exit.
                     74: *
                     75: *      5. (|X| > 16480 log2) sinh(X) must overflow. Return
                     76: *              Huge*Huge to generate overflow and an infinity with
                     77: *              the appropriate sign. Huge is the largest finite number in
                     78: *              extended format. Exit.
                     79: *
                     80:
                     81: SCOSH  IDNT    2,1 Motorola 040 Floating Point Software Package
                     82:
                     83:        section 8
                     84:
                     85:        xref    t_ovfl
                     86:        xref    t_frcinx
                     87:        xref    setox
                     88:
                     89: T1     DC.L $40C62D38,$D3D64634 ... 16381 LOG2 LEAD
                     90: T2     DC.L $3D6F90AE,$B1E75CC7 ... 16381 LOG2 TRAIL
                     91:
                     92: TWO16380 DC.L $7FFB0000,$80000000,$00000000,$00000000
                     93:
                     94:        xdef    scoshd
                     95: scoshd:
                     96: *--COSH(X) = 1 FOR DENORMALIZED X
                     97:
                     98:        FMOVE.S         #:3F800000,FP0
                     99:
                    100:        FMOVE.L         d1,FPCR
                    101:        FADD.S          #:00800000,FP0
                    102:        bra             t_frcinx
                    103:
                    104:        xdef    scosh
                    105: scosh:
                    106:        FMOVE.X         (a0),FP0        ...LOAD INPUT
                    107:
                    108:        move.l          (a0),d0
                    109:        move.w          4(a0),d0
                    110:        ANDI.L          #$7FFFFFFF,d0
                    111:        CMPI.L          #$400CB167,d0
                    112:        BGT.B           COSHBIG
                    113:
                    114: *--THIS IS THE USUAL CASE, |X| < 16380 LOG2
                    115: *--COSH(X) = (1/2) * ( EXP(X) + 1/EXP(X) )
                    116:
                    117:        FABS.X          FP0             ...|X|
                    118:
                    119:        move.l          d1,-(sp)
                    120:        clr.l           d1
                    121:        fmovem.x        fp0,(a0)        ;pass parameter to setox
                    122:        bsr             setox           ...FP0 IS EXP(|X|)
                    123:        FMUL.S          #:3F000000,FP0  ...(1/2)EXP(|X|)
                    124:        move.l          (sp)+,d1
                    125:
                    126:        FMOVE.S         #:3E800000,FP1  ...(1/4)
                    127:        FDIV.X          FP0,FP1         ...1/(2 EXP(|X|))
                    128:
                    129:        FMOVE.L         d1,FPCR
                    130:        FADD.X          fp1,FP0
                    131:
                    132:        bra             t_frcinx
                    133:
                    134: COSHBIG:
                    135:        CMPI.L          #$400CB2B3,d0
                    136:        BGT.B           COSHHUGE
                    137:
                    138:        FABS.X          FP0
                    139:        FSUB.D          T1(pc),FP0              ...(|X|-16381LOG2_LEAD)
                    140:        FSUB.D          T2(pc),FP0              ...|X| - 16381 LOG2, ACCURATE
                    141:
                    142:        move.l          d1,-(sp)
                    143:        clr.l           d1
                    144:        fmovem.x        fp0,(a0)
                    145:        bsr             setox
                    146:        fmove.l         (sp)+,fpcr
                    147:
                    148:        FMUL.X          TWO16380(pc),FP0
                    149:        bra             t_frcinx
                    150:
                    151: COSHHUGE:
                    152:        fmove.l         #0,fpsr         ;clr N bit if set by source
                    153:        bclr.b          #7,(a0)         ;always return positive value
                    154:        fmovem.x        (a0),fp0
                    155:        bra             t_ovfl
                    156:
                    157:        end

CVSweb