Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:48

0001 #include "fpsp-namespace.h"
0002 //
0003 //
0004 //  scosh.sa 3.1 12/10/90
0005 //
0006 //  The entry point sCosh computes the hyperbolic cosine of
0007 //  an input argument; sCoshd does the same except for denormalized
0008 //  input.
0009 //
0010 //  Input: Double-extended number X in location pointed to
0011 //      by address register a0.
0012 //
0013 //  Output: The value cosh(X) returned in floating-point register Fp0.
0014 //
0015 //  Accuracy and Monotonicity: The returned result is within 3 ulps in
0016 //      64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
0017 //      result is subsequently rounded to double precision. The
0018 //      result is provably monotonic in double precision.
0019 //
0020 //  Speed: The program sCOSH takes approximately 250 cycles.
0021 //
0022 //  Algorithm:
0023 //
0024 //  COSH
0025 //  1. If |X| > 16380 log2, go to 3.
0026 //
0027 //  2. (|X| <= 16380 log2) Cosh(X) is obtained by the formulae
0028 //      y = |X|, z = exp(Y), and
0029 //      cosh(X) = (1/2)*( z + 1/z ).
0030 //      Exit.
0031 //
0032 //  3. (|X| > 16380 log2). If |X| > 16480 log2, go to 5.
0033 //
0034 //  4. (16380 log2 < |X| <= 16480 log2)
0035 //      cosh(X) = sign(X) * exp(|X|)/2.
0036 //      However, invoking exp(|X|) may cause premature overflow.
0037 //      Thus, we calculate sinh(X) as follows:
0038 //      Y   := |X|
0039 //      Fact    :=  2**(16380)
0040 //      Y'  := Y - 16381 log2
0041 //      cosh(X) := Fact * exp(Y').
0042 //      Exit.
0043 //
0044 //  5. (|X| > 16480 log2) sinh(X) must overflow. Return
0045 //      Huge*Huge to generate overflow and an infinity with
0046 //      the appropriate sign. Huge is the largest finite number in
0047 //      extended format. Exit.
0048 //
0049 //
0050 
0051 //      Copyright (C) Motorola, Inc. 1990
0052 //          All Rights Reserved
0053 //
0054 //  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
0055 //  The copyright notice above does not evidence any
0056 //  actual or intended publication of such source code.
0057 
0058 //SCOSH idnt    2,1 | Motorola 040 Floating Point Software Package
0059 
0060     |section    8
0061 
0062     |xref   t_ovfl
0063     |xref   t_frcinx
0064     |xref   setox
0065 
0066 T1: .long 0x40C62D38,0xD3D64634 // ... 16381 LOG2 LEAD
0067 T2: .long 0x3D6F90AE,0xB1E75CC7 // ... 16381 LOG2 TRAIL
0068 
0069 TWO16380: .long 0x7FFB0000,0x80000000,0x00000000,0x00000000
0070 
0071     .global scoshd
0072 scoshd:
0073 //--COSH(X) = 1 FOR DENORMALIZED X
0074 
0075     fmoves      #0x3F800000,%fp0
0076 
0077     fmovel      %d1,%FPCR
0078     fadds       #0x00800000,%fp0
0079     bra     t_frcinx
0080 
0081     .global scosh
0082 scosh:
0083     fmovex      (%a0),%fp0  // ...LOAD INPUT
0084 
0085     movel       (%a0),%d0
0086     movew       4(%a0),%d0
0087     andil       #0x7FFFFFFF,%d0
0088     cmpil       #0x400CB167,%d0
0089     bgts        COSHBIG
0090 
0091 //--THIS IS THE USUAL CASE, |X| < 16380 LOG2
0092 //--COSH(X) = (1/2) * ( EXP(X) + 1/EXP(X) )
0093 
0094     fabsx       %fp0        // ...|X|
0095 
0096     movel       %d1,-(%sp)
0097     clrl        %d1
0098     fmovemx %fp0-%fp0,(%a0) //pass parameter to setox
0099     bsr     setox       // ...FP0 IS EXP(|X|)
0100     fmuls       #0x3F000000,%fp0    // ...(1/2)EXP(|X|)
0101     movel       (%sp)+,%d1
0102 
0103     fmoves      #0x3E800000,%fp1    // ...(1/4)
0104     fdivx       %fp0,%fp1       // ...1/(2 EXP(|X|))
0105 
0106     fmovel      %d1,%FPCR
0107     faddx       %fp1,%fp0
0108 
0109     bra     t_frcinx
0110 
0111 COSHBIG:
0112     cmpil       #0x400CB2B3,%d0
0113     bgts        COSHHUGE
0114 
0115     fabsx       %fp0
0116     fsubd       T1(%pc),%fp0        // ...(|X|-16381LOG2_LEAD)
0117     fsubd       T2(%pc),%fp0        // ...|X| - 16381 LOG2, ACCURATE
0118 
0119     movel       %d1,-(%sp)
0120     clrl        %d1
0121     fmovemx %fp0-%fp0,(%a0)
0122     bsr     setox
0123     fmovel      (%sp)+,%fpcr
0124 
0125     fmulx       TWO16380(%pc),%fp0
0126     bra     t_frcinx
0127 
0128 COSHHUGE:
0129     fmovel      #0,%fpsr        //clr N bit if set by source
0130     bclrb       #7,(%a0)        //always return positive value
0131     fmovemx (%a0),%fp0-%fp0
0132     bra     t_ovfl
0133 
0134     |end