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