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