Home | History | Annotate | Line # | Download | only in fpsp
stanh.sa revision 1.1.1.1
      1  1.1  mycroft *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      2  1.1  mycroft *	M68000 Hi-Performance Microprocessor Division
      3  1.1  mycroft *	M68040 Software Package 
      4  1.1  mycroft *
      5  1.1  mycroft *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      6  1.1  mycroft *	All rights reserved.
      7  1.1  mycroft *
      8  1.1  mycroft *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
      9  1.1  mycroft *	To the maximum extent permitted by applicable law,
     10  1.1  mycroft *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     11  1.1  mycroft *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     12  1.1  mycroft *	PARTICULAR PURPOSE and any warranty against infringement with
     13  1.1  mycroft *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     14  1.1  mycroft *	and any accompanying written materials. 
     15  1.1  mycroft *
     16  1.1  mycroft *	To the maximum extent permitted by applicable law,
     17  1.1  mycroft *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     18  1.1  mycroft *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     19  1.1  mycroft *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     20  1.1  mycroft *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     21  1.1  mycroft *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     22  1.1  mycroft *	and support of the SOFTWARE.  
     23  1.1  mycroft *
     24  1.1  mycroft *	You are hereby granted a copyright license to use, modify, and
     25  1.1  mycroft *	distribute the SOFTWARE so long as this entire notice is retained
     26  1.1  mycroft *	without alteration in any modified and/or redistributed versions,
     27  1.1  mycroft *	and that such modified versions are clearly identified as such.
     28  1.1  mycroft *	No licenses are granted by implication, estoppel or otherwise
     29  1.1  mycroft *	under any patents or trademarks of Motorola, Inc.
     30  1.1  mycroft 
     31  1.1  mycroft *
     32  1.1  mycroft *	stanh.sa 3.1 12/10/90
     33  1.1  mycroft *
     34  1.1  mycroft *	The entry point sTanh computes the hyperbolic tangent of
     35  1.1  mycroft *	an input argument; sTanhd does the same except for denormalized
     36  1.1  mycroft *	input.
     37  1.1  mycroft *
     38  1.1  mycroft *	Input: Double-extended number X in location pointed to
     39  1.1  mycroft *		by address register a0.
     40  1.1  mycroft *
     41  1.1  mycroft *	Output: The value tanh(X) returned in floating-point register Fp0.
     42  1.1  mycroft *
     43  1.1  mycroft *	Accuracy and Monotonicity: The returned result is within 3 ulps in
     44  1.1  mycroft *		64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
     45  1.1  mycroft *		result is subsequently rounded to double precision. The
     46  1.1  mycroft *		result is provably monotonic in double precision.
     47  1.1  mycroft *
     48  1.1  mycroft *	Speed: The program stanh takes approximately 270 cycles.
     49  1.1  mycroft *
     50  1.1  mycroft *	Algorithm:
     51  1.1  mycroft *
     52  1.1  mycroft *	TANH
     53  1.1  mycroft *	1. If |X| >= (5/2) log2 or |X| <= 2**(-40), go to 3.
     54  1.1  mycroft *
     55  1.1  mycroft *	2. (2**(-40) < |X| < (5/2) log2) Calculate tanh(X) by
     56  1.1  mycroft *		sgn := sign(X), y := 2|X|, z := expm1(Y), and
     57  1.1  mycroft *		tanh(X) = sgn*( z/(2+z) ).
     58  1.1  mycroft *		Exit.
     59  1.1  mycroft *
     60  1.1  mycroft *	3. (|X| <= 2**(-40) or |X| >= (5/2) log2). If |X| < 1,
     61  1.1  mycroft *		go to 7.
     62  1.1  mycroft *
     63  1.1  mycroft *	4. (|X| >= (5/2) log2) If |X| >= 50 log2, go to 6.
     64  1.1  mycroft *
     65  1.1  mycroft *	5. ((5/2) log2 <= |X| < 50 log2) Calculate tanh(X) by
     66  1.1  mycroft *		sgn := sign(X), y := 2|X|, z := exp(Y),
     67  1.1  mycroft *		tanh(X) = sgn - [ sgn*2/(1+z) ].
     68  1.1  mycroft *		Exit.
     69  1.1  mycroft *
     70  1.1  mycroft *	6. (|X| >= 50 log2) Tanh(X) = +-1 (round to nearest). Thus, we
     71  1.1  mycroft *		calculate Tanh(X) by
     72  1.1  mycroft *		sgn := sign(X), Tiny := 2**(-126),
     73  1.1  mycroft *		tanh(X) := sgn - sgn*Tiny.
     74  1.1  mycroft *		Exit.
     75  1.1  mycroft *
     76  1.1  mycroft *	7. (|X| < 2**(-40)). Tanh(X) = X.	Exit.
     77  1.1  mycroft *
     78  1.1  mycroft 
     79  1.1  mycroft STANH	IDNT	2,1 Motorola 040 Floating Point Software Package
     80  1.1  mycroft 
     81  1.1  mycroft 	section	8
     82  1.1  mycroft 	
     83  1.1  mycroft 	include fpsp.h
     84  1.1  mycroft 
     85  1.1  mycroft X	equ	FP_SCR5
     86  1.1  mycroft XDCARE	equ	X+2
     87  1.1  mycroft XFRAC	equ	X+4
     88  1.1  mycroft 
     89  1.1  mycroft SGN	equ	L_SCR3
     90  1.1  mycroft 
     91  1.1  mycroft V	equ	FP_SCR6
     92  1.1  mycroft 
     93  1.1  mycroft BOUNDS1	DC.L $3FD78000,$3FFFDDCE ... 2^(-40), (5/2)LOG2
     94  1.1  mycroft 
     95  1.1  mycroft 	xref	t_frcinx
     96  1.1  mycroft 	xref	t_extdnrm
     97  1.1  mycroft 	xref	setox
     98  1.1  mycroft 	xref	setoxm1
     99  1.1  mycroft 
    100  1.1  mycroft 	xdef	stanhd
    101  1.1  mycroft stanhd:
    102  1.1  mycroft *--TANH(X) = X FOR DENORMALIZED X
    103  1.1  mycroft 
    104  1.1  mycroft 	bra		t_extdnrm
    105  1.1  mycroft 
    106  1.1  mycroft 	xdef	stanh
    107  1.1  mycroft stanh:
    108  1.1  mycroft 	FMOVE.X		(a0),FP0	...LOAD INPUT
    109  1.1  mycroft 
    110  1.1  mycroft 	FMOVE.X		FP0,X(a6)
    111  1.1  mycroft 	move.l		(a0),d0
    112  1.1  mycroft 	move.w		4(a0),d0
    113  1.1  mycroft 	MOVE.L		D0,X(a6)
    114  1.1  mycroft 	AND.L		#$7FFFFFFF,D0
    115  1.1  mycroft 	CMP2.L		BOUNDS1(pc),D0	...2**(-40) < |X| < (5/2)LOG2 ?
    116  1.1  mycroft 	BCS.B		TANHBORS
    117  1.1  mycroft 
    118  1.1  mycroft *--THIS IS THE USUAL CASE
    119  1.1  mycroft *--Y = 2|X|, Z = EXPM1(Y), TANH(X) = SIGN(X) * Z / (Z+2).
    120  1.1  mycroft 
    121  1.1  mycroft 	MOVE.L		X(a6),D0
    122  1.1  mycroft 	MOVE.L		D0,SGN(a6)
    123  1.1  mycroft 	AND.L		#$7FFF0000,D0
    124  1.1  mycroft 	ADD.L		#$00010000,D0	...EXPONENT OF 2|X|
    125  1.1  mycroft 	MOVE.L		D0,X(a6)
    126  1.1  mycroft 	AND.L		#$80000000,SGN(a6)
    127  1.1  mycroft 	FMOVE.X		X(a6),FP0		...FP0 IS Y = 2|X|
    128  1.1  mycroft 
    129  1.1  mycroft 	move.l		d1,-(a7)
    130  1.1  mycroft 	clr.l		d1
    131  1.1  mycroft 	fmovem.x	fp0,(a0)
    132  1.1  mycroft 	bsr		setoxm1	 	...FP0 IS Z = EXPM1(Y)
    133  1.1  mycroft 	move.l		(a7)+,d1
    134  1.1  mycroft 
    135  1.1  mycroft 	FMOVE.X		FP0,FP1
    136  1.1  mycroft 	FADD.S		#:40000000,FP1	...Z+2
    137  1.1  mycroft 	MOVE.L		SGN(a6),D0
    138  1.1  mycroft 	FMOVE.X		FP1,V(a6)
    139  1.1  mycroft 	EOR.L		D0,V(a6)
    140  1.1  mycroft 
    141  1.1  mycroft 	FMOVE.L		d1,FPCR		;restore users exceptions
    142  1.1  mycroft 	FDIV.X		V(a6),FP0
    143  1.1  mycroft 	bra		t_frcinx
    144  1.1  mycroft 
    145  1.1  mycroft TANHBORS:
    146  1.1  mycroft 	CMP.L		#$3FFF8000,D0
    147  1.1  mycroft 	BLT.W		TANHSM
    148  1.1  mycroft 
    149  1.1  mycroft 	CMP.L		#$40048AA1,D0
    150  1.1  mycroft 	BGT.W		TANHHUGE
    151  1.1  mycroft 
    152  1.1  mycroft *-- (5/2) LOG2 < |X| < 50 LOG2,
    153  1.1  mycroft *--TANH(X) = 1 - (2/[EXP(2X)+1]). LET Y = 2|X|, SGN = SIGN(X),
    154  1.1  mycroft *--TANH(X) = SGN -	SGN*2/[EXP(Y)+1].
    155  1.1  mycroft 
    156  1.1  mycroft 	MOVE.L		X(a6),D0
    157  1.1  mycroft 	MOVE.L		D0,SGN(a6)
    158  1.1  mycroft 	AND.L		#$7FFF0000,D0
    159  1.1  mycroft 	ADD.L		#$00010000,D0	...EXPO OF 2|X|
    160  1.1  mycroft 	MOVE.L		D0,X(a6)		...Y = 2|X|
    161  1.1  mycroft 	AND.L		#$80000000,SGN(a6)
    162  1.1  mycroft 	MOVE.L		SGN(a6),D0
    163  1.1  mycroft 	FMOVE.X		X(a6),FP0		...Y = 2|X|
    164  1.1  mycroft 
    165  1.1  mycroft 	move.l		d1,-(a7)
    166  1.1  mycroft 	clr.l		d1
    167  1.1  mycroft 	fmovem.x	fp0,(a0)
    168  1.1  mycroft 	bsr		setox		...FP0 IS EXP(Y)
    169  1.1  mycroft 	move.l		(a7)+,d1
    170  1.1  mycroft 	move.l		SGN(a6),d0
    171  1.1  mycroft 	FADD.S		#:3F800000,FP0	...EXP(Y)+1
    172  1.1  mycroft 
    173  1.1  mycroft 	EOR.L		#$C0000000,D0	...-SIGN(X)*2
    174  1.1  mycroft 	FMOVE.S		d0,FP1		...-SIGN(X)*2 IN SGL FMT
    175  1.1  mycroft 	FDIV.X		FP0,FP1	 	...-SIGN(X)2 / [EXP(Y)+1 ]
    176  1.1  mycroft 
    177  1.1  mycroft 	MOVE.L		SGN(a6),D0
    178  1.1  mycroft 	OR.L		#$3F800000,D0	...SGN
    179  1.1  mycroft 	FMOVE.S		d0,FP0		...SGN IN SGL FMT
    180  1.1  mycroft 
    181  1.1  mycroft 	FMOVE.L		d1,FPCR		;restore users exceptions
    182  1.1  mycroft 	FADD.X		fp1,FP0
    183  1.1  mycroft 
    184  1.1  mycroft 	bra		t_frcinx
    185  1.1  mycroft 
    186  1.1  mycroft TANHSM:
    187  1.1  mycroft 	MOVE.W		#$0000,XDCARE(a6)
    188  1.1  mycroft 
    189  1.1  mycroft 	FMOVE.L		d1,FPCR		;restore users exceptions
    190  1.1  mycroft 	FMOVE.X		X(a6),FP0		;last inst - possible exception set
    191  1.1  mycroft 
    192  1.1  mycroft 	bra		t_frcinx
    193  1.1  mycroft 
    194  1.1  mycroft TANHHUGE:
    195  1.1  mycroft *---RETURN SGN(X) - SGN(X)EPS
    196  1.1  mycroft 	MOVE.L		X(a6),D0
    197  1.1  mycroft 	AND.L		#$80000000,D0
    198  1.1  mycroft 	OR.L		#$3F800000,D0
    199  1.1  mycroft 	FMOVE.S		d0,FP0
    200  1.1  mycroft 	AND.L		#$80000000,D0
    201  1.1  mycroft 	EOR.L		#$80800000,D0	...-SIGN(X)*EPS
    202  1.1  mycroft 
    203  1.1  mycroft 	FMOVE.L		d1,FPCR		;restore users exceptions
    204  1.1  mycroft 	FADD.S		d0,FP0
    205  1.1  mycroft 
    206  1.1  mycroft 	bra		t_frcinx
    207  1.1  mycroft 
    208  1.1  mycroft 	end
    209