1 | #include "fpsp-namespace.h" |
---|
2 | // |
---|
3 | // |
---|
4 | // stanh.sa 3.1 12/10/90 |
---|
5 | // |
---|
6 | // The entry point sTanh computes the hyperbolic tangent of |
---|
7 | // an input argument; sTanhd does the same except for denormalized |
---|
8 | // input. |
---|
9 | // |
---|
10 | // Input: Double-extended number X in location pointed to |
---|
11 | // by address register a0. |
---|
12 | // |
---|
13 | // Output: The value tanh(X) returned in floating-point register Fp0. |
---|
14 | // |
---|
15 | // Accuracy and Monotonicity: The returned result is within 3 ulps in |
---|
16 | // 64 significant bit, i.e. within 0.5001 ulp to 53 bits if the |
---|
17 | // result is subsequently rounded to double precision. The |
---|
18 | // result is provably monotonic in double precision. |
---|
19 | // |
---|
20 | // Speed: The program stanh takes approximately 270 cycles. |
---|
21 | // |
---|
22 | // Algorithm: |
---|
23 | // |
---|
24 | // TANH |
---|
25 | // 1. If |X| >= (5/2) log2 or |X| <= 2**(-40), go to 3. |
---|
26 | // |
---|
27 | // 2. (2**(-40) < |X| < (5/2) log2) Calculate tanh(X) by |
---|
28 | // sgn := sign(X), y := 2|X|, z := expm1(Y), and |
---|
29 | // tanh(X) = sgn*( z/(2+z) ). |
---|
30 | // Exit. |
---|
31 | // |
---|
32 | // 3. (|X| <= 2**(-40) or |X| >= (5/2) log2). If |X| < 1, |
---|
33 | // go to 7. |
---|
34 | // |
---|
35 | // 4. (|X| >= (5/2) log2) If |X| >= 50 log2, go to 6. |
---|
36 | // |
---|
37 | // 5. ((5/2) log2 <= |X| < 50 log2) Calculate tanh(X) by |
---|
38 | // sgn := sign(X), y := 2|X|, z := exp(Y), |
---|
39 | // tanh(X) = sgn - [ sgn*2/(1+z) ]. |
---|
40 | // Exit. |
---|
41 | // |
---|
42 | // 6. (|X| >= 50 log2) Tanh(X) = +-1 (round to nearest). Thus, we |
---|
43 | // calculate Tanh(X) by |
---|
44 | // sgn := sign(X), Tiny := 2**(-126), |
---|
45 | // tanh(X) := sgn - sgn*Tiny. |
---|
46 | // Exit. |
---|
47 | // |
---|
48 | // 7. (|X| < 2**(-40)). Tanh(X) = X. Exit. |
---|
49 | // |
---|
50 | |
---|
51 | // Copyright (C) Motorola, Inc. 1990 |
---|
52 | // All Rights Reserved |
---|
53 | // |
---|
54 | // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA |
---|
55 | // The copyright notice above does not evidence any |
---|
56 | // actual or intended publication of such source code. |
---|
57 | |
---|
58 | //STANH idnt 2,1 | Motorola 040 Floating Point Software Package |
---|
59 | |
---|
60 | |section 8 |
---|
61 | |
---|
62 | #include "fpsp.defs" |
---|
63 | |
---|
64 | .set X,FP_SCR5 |
---|
65 | .set XDCARE,X+2 |
---|
66 | .set XFRAC,X+4 |
---|
67 | |
---|
68 | .set SGN,L_SCR3 |
---|
69 | |
---|
70 | .set V,FP_SCR6 |
---|
71 | |
---|
72 | BOUNDS1: .long 0x3FD78000,0x3FFFDDCE // ... 2^(-40), (5/2)LOG2 |
---|
73 | |
---|
74 | |xref t_frcinx |
---|
75 | |xref t_extdnrm |
---|
76 | |xref setox |
---|
77 | |xref setoxm1 |
---|
78 | |
---|
79 | .global stanhd |
---|
80 | stanhd: |
---|
81 | //--TANH(X) = X FOR DENORMALIZED X |
---|
82 | |
---|
83 | bra t_extdnrm |
---|
84 | |
---|
85 | .global stanh |
---|
86 | stanh: |
---|
87 | fmovex (%a0),%fp0 // ...LOAD INPUT |
---|
88 | |
---|
89 | fmovex %fp0,X(%a6) |
---|
90 | movel (%a0),%d0 |
---|
91 | movew 4(%a0),%d0 |
---|
92 | movel %d0,X(%a6) |
---|
93 | andl #0x7FFFFFFF,%d0 |
---|
94 | cmp2l BOUNDS1(%pc),%d0 // ...2**(-40) < |X| < (5/2)LOG2 ? |
---|
95 | bcss TANHBORS |
---|
96 | |
---|
97 | //--THIS IS THE USUAL CASE |
---|
98 | //--Y = 2|X|, Z = EXPM1(Y), TANH(X) = SIGN(X) * Z / (Z+2). |
---|
99 | |
---|
100 | movel X(%a6),%d0 |
---|
101 | movel %d0,SGN(%a6) |
---|
102 | andl #0x7FFF0000,%d0 |
---|
103 | addl #0x00010000,%d0 // ...EXPONENT OF 2|X| |
---|
104 | movel %d0,X(%a6) |
---|
105 | andl #0x80000000,SGN(%a6) |
---|
106 | fmovex X(%a6),%fp0 // ...FP0 IS Y = 2|X| |
---|
107 | |
---|
108 | movel %d1,-(%a7) |
---|
109 | clrl %d1 |
---|
110 | fmovemx %fp0-%fp0,(%a0) |
---|
111 | bsr setoxm1 // ...FP0 IS Z = EXPM1(Y) |
---|
112 | movel (%a7)+,%d1 |
---|
113 | |
---|
114 | fmovex %fp0,%fp1 |
---|
115 | fadds #0x40000000,%fp1 // ...Z+2 |
---|
116 | movel SGN(%a6),%d0 |
---|
117 | fmovex %fp1,V(%a6) |
---|
118 | eorl %d0,V(%a6) |
---|
119 | |
---|
120 | fmovel %d1,%FPCR //restore users exceptions |
---|
121 | fdivx V(%a6),%fp0 |
---|
122 | bra t_frcinx |
---|
123 | |
---|
124 | TANHBORS: |
---|
125 | cmpl #0x3FFF8000,%d0 |
---|
126 | blt TANHSM |
---|
127 | |
---|
128 | cmpl #0x40048AA1,%d0 |
---|
129 | bgt TANHHUGE |
---|
130 | |
---|
131 | //-- (5/2) LOG2 < |X| < 50 LOG2, |
---|
132 | //--TANH(X) = 1 - (2/[EXP(2X)+1]). LET Y = 2|X|, SGN = SIGN(X), |
---|
133 | //--TANH(X) = SGN - SGN*2/[EXP(Y)+1]. |
---|
134 | |
---|
135 | movel X(%a6),%d0 |
---|
136 | movel %d0,SGN(%a6) |
---|
137 | andl #0x7FFF0000,%d0 |
---|
138 | addl #0x00010000,%d0 // ...EXPO OF 2|X| |
---|
139 | movel %d0,X(%a6) // ...Y = 2|X| |
---|
140 | andl #0x80000000,SGN(%a6) |
---|
141 | movel SGN(%a6),%d0 |
---|
142 | fmovex X(%a6),%fp0 // ...Y = 2|X| |
---|
143 | |
---|
144 | movel %d1,-(%a7) |
---|
145 | clrl %d1 |
---|
146 | fmovemx %fp0-%fp0,(%a0) |
---|
147 | bsr setox // ...FP0 IS EXP(Y) |
---|
148 | movel (%a7)+,%d1 |
---|
149 | movel SGN(%a6),%d0 |
---|
150 | fadds #0x3F800000,%fp0 // ...EXP(Y)+1 |
---|
151 | |
---|
152 | eorl #0xC0000000,%d0 // ...-SIGN(X)*2 |
---|
153 | fmoves %d0,%fp1 // ...-SIGN(X)*2 IN SGL FMT |
---|
154 | fdivx %fp0,%fp1 // ...-SIGN(X)2 / [EXP(Y)+1 ] |
---|
155 | |
---|
156 | movel SGN(%a6),%d0 |
---|
157 | orl #0x3F800000,%d0 // ...SGN |
---|
158 | fmoves %d0,%fp0 // ...SGN IN SGL FMT |
---|
159 | |
---|
160 | fmovel %d1,%FPCR //restore users exceptions |
---|
161 | faddx %fp1,%fp0 |
---|
162 | |
---|
163 | bra t_frcinx |
---|
164 | |
---|
165 | TANHSM: |
---|
166 | movew #0x0000,XDCARE(%a6) |
---|
167 | |
---|
168 | fmovel %d1,%FPCR //restore users exceptions |
---|
169 | fmovex X(%a6),%fp0 //last inst - possible exception set |
---|
170 | |
---|
171 | bra t_frcinx |
---|
172 | |
---|
173 | TANHHUGE: |
---|
174 | //---RETURN SGN(X) - SGN(X)EPS |
---|
175 | movel X(%a6),%d0 |
---|
176 | andl #0x80000000,%d0 |
---|
177 | orl #0x3F800000,%d0 |
---|
178 | fmoves %d0,%fp0 |
---|
179 | andl #0x80000000,%d0 |
---|
180 | eorl #0x80800000,%d0 // ...-SIGN(X)*EPS |
---|
181 | |
---|
182 | fmovel %d1,%FPCR //restore users exceptions |
---|
183 | fadds %d0,%fp0 |
---|
184 | |
---|
185 | bra t_frcinx |
---|
186 | |
---|
187 | |end |
---|