1 * $NetBSD: stanh.sa,v 1.3 1994/10/26 07:50:12 cgd Exp $
3 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 * M68000 Hi-Performance Microprocessor Division
5 * M68040 Software Package
7 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
10 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
11 * To the maximum extent permitted by applicable law,
12 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
13 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
14 * PARTICULAR PURPOSE and any warranty against infringement with
15 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
16 * and any accompanying written materials.
18 * To the maximum extent permitted by applicable law,
19 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
20 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
21 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
22 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
23 * SOFTWARE. Motorola assumes no responsibility for the maintenance
24 * and support of the SOFTWARE.
26 * You are hereby granted a copyright license to use, modify, and
27 * distribute the SOFTWARE so long as this entire notice is retained
28 * without alteration in any modified and/or redistributed versions,
29 * and that such modified versions are clearly identified as such.
30 * No licenses are granted by implication, estoppel or otherwise
31 * under any patents or trademarks of Motorola, Inc.
34 * stanh.sa 3.1 12/10/90
36 * The entry point sTanh computes the hyperbolic tangent of
37 * an input argument; sTanhd does the same except for denormalized
40 * Input: Double-extended number X in location pointed to
41 * by address register a0.
43 * Output: The value tanh(X) returned in floating-point register Fp0.
45 * Accuracy and Monotonicity: The returned result is within 3 ulps in
46 * 64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
47 * result is subsequently rounded to double precision. The
48 * result is provably monotonic in double precision.
50 * Speed: The program stanh takes approximately 270 cycles.
55 * 1. If |X| >= (5/2) log2 or |X| <= 2**(-40), go to 3.
57 * 2. (2**(-40) < |X| < (5/2) log2) Calculate tanh(X) by
58 * sgn := sign(X), y := 2|X|, z := expm1(Y), and
59 * tanh(X) = sgn*( z/(2+z) ).
62 * 3. (|X| <= 2**(-40) or |X| >= (5/2) log2). If |X| < 1,
65 * 4. (|X| >= (5/2) log2) If |X| >= 50 log2, go to 6.
67 * 5. ((5/2) log2 <= |X| < 50 log2) Calculate tanh(X) by
68 * sgn := sign(X), y := 2|X|, z := exp(Y),
69 * tanh(X) = sgn - [ sgn*2/(1+z) ].
72 * 6. (|X| >= 50 log2) Tanh(X) = +-1 (round to nearest). Thus, we
73 * calculate Tanh(X) by
74 * sgn := sign(X), Tiny := 2**(-126),
75 * tanh(X) := sgn - sgn*Tiny.
78 * 7. (|X| < 2**(-40)). Tanh(X) = X. Exit.
81 STANH IDNT 2,1 Motorola 040 Floating Point Software Package
95 BOUNDS1 DC.L $3FD78000,$3FFFDDCE ... 2^(-40), (5/2)LOG2
104 *--TANH(X) = X FOR DENORMALIZED X
110 FMOVE.X (a0),FP0 ...LOAD INPUT
117 CMP2.L BOUNDS1(pc),D0 ...2**(-40) < |X| < (5/2)LOG2 ?
120 *--THIS IS THE USUAL CASE
121 *--Y = 2|X|, Z = EXPM1(Y), TANH(X) = SIGN(X) * Z / (Z+2).
126 ADD.L #$00010000,D0 ...EXPONENT OF 2|X|
128 AND.L #$80000000,SGN(a6)
129 FMOVE.X X(a6),FP0 ...FP0 IS Y = 2|X|
134 bsr setoxm1 ...FP0 IS Z = EXPM1(Y)
138 FADD.S #:40000000,FP1 ...Z+2
143 FMOVE.L d1,FPCR ;restore users exceptions
154 *-- (5/2) LOG2 < |X| < 50 LOG2,
155 *--TANH(X) = 1 - (2/[EXP(2X)+1]). LET Y = 2|X|, SGN = SIGN(X),
156 *--TANH(X) = SGN - SGN*2/[EXP(Y)+1].
161 ADD.L #$00010000,D0 ...EXPO OF 2|X|
162 MOVE.L D0,X(a6) ...Y = 2|X|
163 AND.L #$80000000,SGN(a6)
165 FMOVE.X X(a6),FP0 ...Y = 2|X|
170 bsr setox ...FP0 IS EXP(Y)
173 FADD.S #:3F800000,FP0 ...EXP(Y)+1
175 EOR.L #$C0000000,D0 ...-SIGN(X)*2
176 FMOVE.S d0,FP1 ...-SIGN(X)*2 IN SGL FMT
177 FDIV.X FP0,FP1 ...-SIGN(X)2 / [EXP(Y)+1 ]
180 OR.L #$3F800000,D0 ...SGN
181 FMOVE.S d0,FP0 ...SGN IN SGL FMT
183 FMOVE.L d1,FPCR ;restore users exceptions
191 FMOVE.L d1,FPCR ;restore users exceptions
192 FMOVE.X X(a6),FP0 ;last inst - possible exception set
197 *---RETURN SGN(X) - SGN(X)EPS
203 EOR.L #$80800000,D0 ...-SIGN(X)*EPS
205 FMOVE.L d1,FPCR ;restore users exceptions