2005-04-17 02:20:36 +04:00
|
| stanh. s a 3 . 1 1 2 / 1 0 / 9 0
|
| The e n t r y p o i n t s T a n h c o m p u t e s t h e h y p e r b o l i c t a n g e n t o f
| an i n p u t a r g u m e n t ; sTanhd does the same except for denormalized
| input.
|
| Input : Double- e x t e n d e d n u m b e r X i n l o c a t i o n p o i n t e d t o
| by a d d r e s s r e g i s t e r a0 .
|
| Output : The v a l u e t a n h ( X ) r e t u r n e d i n f l o a t i n g - p o i n t r e g i s t e r F p0 .
|
| Accuracy a n d M o n o t o n i c i t y : T h e r e t u r n e d r e s u l t i s w i t h i n 3 u l p s i n
| 6 4 significant b i t , i . e . w i t h i n 0 . 5 0 0 1 u l p t o 5 3 b i t s i f t h e
| result i s s u b s e q u e n t l y r o u n d e d t o d o u b l e p r e c i s i o n . T h e
| result i s p r o v a b l y m o n o t o n i c i n d o u b l e p r e c i s i o n .
|
| Speed : The p r o g r a m s t a n h t a k e s a p p r o x i m a t e l y 2 7 0 c y c l e s .
|
| Algorithm :
|
| TANH
| 1 . If | X | > = ( 5 / 2 ) l o g 2 o r | X | < = 2 * * ( - 4 0 ) , g o t o 3 .
|
| 2 . ( 2 * * ( - 4 0 ) < | X| < ( 5 / 2 ) l o g 2 ) C a l c u l a t e t a n h ( X ) b y
| sgn : = s i g n ( X ) , y : = 2 | X | , z : = e x p m 1 ( Y ) , a n d
| tanh( X ) = s g n * ( z / ( 2 + z ) ) .
| Exit.
|
| 3 . ( | X| < = 2 * * ( - 4 0 ) o r | X | > = ( 5 / 2 ) l o g 2 ) . I f | X | < 1 ,
| go t o 7 .
|
| 4 . ( | X| > = ( 5 / 2 ) l o g 2 ) I f | X | > = 5 0 l o g 2 , g o t o 6 .
|
| 5 . ( ( 5 / 2 ) log2 < = | X | < 5 0 l o g 2 ) C a l c u l a t e t a n h ( X ) b y
| sgn : = s i g n ( X ) , y : = 2 | X | , z : = e x p ( Y ) ,
| tanh( X ) = s g n - [ s g n * 2 / ( 1 + z ) ] .
| Exit.
|
| 6 . ( | X| > = 5 0 l o g 2 ) T a n h ( X ) = + - 1 ( r o u n d t o n e a r e s t ) . T h u s , w e
| calculate T a n h ( X ) b y
| sgn : = s i g n ( X ) , T i n y : = 2 * * ( - 1 2 6 ) ,
| tanh( X ) : = s g n - s g n * T i n y .
| Exit.
|
| 7 . ( | X| < 2 * * ( - 4 0 ) ) . T a n h ( X ) = X . E x i t .
|
| Copyright ( C ) M o t o r o l a , I n c . 1 9 9 0
| All R i g h t s R e s e r v e d
|
2006-02-12 04:55:48 +03:00
| For d e t a i l s o n t h e l i c e n s e f o r t h i s f i l e , p l e a s e s e e t h e
| file, R E A D M E , i n t h i s s a m e d i r e c t o r y .
2005-04-17 02:20:36 +04:00
| STANH i d n t 2 ,1 | M o t o r o l a 0 4 0 F l o a t i n g P o i n t S o f t w a r e P a c k a g e
| section 8
# include " f p s p . h "
.set X,F P _ S C R 5
.set XDCARE,X + 2
.set XFRAC,X + 4
.set SGN,L _ S C R 3
.set V,F P _ S C R 6
BOUNDS1 : .long 0x3FD78000 , 0 x3 F F F D D C E | . . . 2 ^ ( - 4 0 ) , ( 5 / 2 ) L O G 2
| xref t _ f r c i n x
| xref t _ e x t d n r m
| xref s e t o x
| xref s e t o x m 1
.global stanhd
stanhd :
| - - TANH( X ) = X F O R D E N O R M A L I Z E D X
bra t _ e x t d n r m
.global stanh
stanh :
fmovex ( % a0 ) ,% f p0 | . . . L O A D I N P U T
fmovex % f p0 ,X ( % a6 )
movel ( % a0 ) ,% d0
movew 4 ( % a0 ) ,% d0
movel % d0 ,X ( % a6 )
andl #0x7FFFFFFF ,% d0
cmp2 l B O U N D S 1 ( % p c ) ,% d0 | . . . 2 * * ( - 4 0 ) < | X | < ( 5 / 2 ) L O G 2 ?
bcss T A N H B O R S
| - - THIS I S T H E U S U A L C A S E
| - - Y = 2 | X | , Z = E X P M 1 ( Y ) , T A N H ( X ) = S I G N ( X ) * Z / ( Z + 2 ) .
movel X ( % a6 ) ,% d0
movel % d0 ,S G N ( % a6 )
andl #0x7FFF0000 ,% d0
addl #0x00010000 ,% d0 | . . . E X P O N E N T O F 2 | X |
movel % d0 ,X ( % a6 )
andl #0x80000000 ,S G N ( % a6 )
fmovex X ( % a6 ) ,% f p0 | . . . F P 0 I S Y = 2 | X |
movel % d1 ,- ( % a7 )
clrl % d1
fmovemx % f p0 - % f p0 ,( % a0 )
bsr s e t o x m 1 | . . . F P 0 I S Z = E X P M 1 ( Y )
movel ( % a7 ) + ,% d1
fmovex % f p0 ,% f p1
fadds #0x40000000 ,% f p1 | . . . Z + 2
movel S G N ( % a6 ) ,% d0
fmovex % f p1 ,V ( % a6 )
eorl % d0 ,V ( % a6 )
fmovel % d1 ,% F P C R | r e s t o r e u s e r s e x c e p t i o n s
fdivx V ( % a6 ) ,% f p0
bra t _ f r c i n x
TANHBORS :
cmpl #0x3FFF8000 ,% d0
blt T A N H S M
cmpl #0x40048AA1 ,% d0
bgt T A N H H U G E
| - - ( 5 / 2 ) LOG2 < | X | < 5 0 L O G 2 ,
| - - TANH( X ) = 1 - ( 2 / [ E X P ( 2 X ) + 1 ] ) . L E T Y = 2 | X | , S G N = S I G N ( X ) ,
| - - TANH( X ) = S G N - S G N * 2 / [ E X P ( Y ) + 1 ] .
movel X ( % a6 ) ,% d0
movel % d0 ,S G N ( % a6 )
andl #0x7FFF0000 ,% d0
addl #0x00010000 ,% d0 | . . . E X P O O F 2 | X |
movel % d0 ,X ( % a6 ) | . . . Y = 2 | X |
andl #0x80000000 ,S G N ( % a6 )
movel S G N ( % a6 ) ,% d0
fmovex X ( % a6 ) ,% f p0 | . . . Y = 2 | X |
movel % d1 ,- ( % a7 )
clrl % d1
fmovemx % f p0 - % f p0 ,( % a0 )
bsr s e t o x | . . . F P 0 I S E X P ( Y )
movel ( % a7 ) + ,% d1
movel S G N ( % a6 ) ,% d0
fadds #0x3F800000 ,% f p0 | . . . E X P ( Y ) + 1
eorl #0xC0000000 ,% d0 | . . . - S I G N ( X ) * 2
fmoves % d0 ,% f p1 | . . . - S I G N ( X ) * 2 I N S G L F M T
fdivx % f p0 ,% f p1 | . . . - S I G N ( X ) 2 / [ E X P ( Y ) + 1 ]
movel S G N ( % a6 ) ,% d0
orl #0x3F800000 ,% d0 | . . . S G N
fmoves % d0 ,% f p0 | . . . S G N I N S G L F M T
fmovel % d1 ,% F P C R | r e s t o r e u s e r s e x c e p t i o n s
faddx % f p1 ,% f p0
bra t _ f r c i n x
TANHSM :
movew #0x0000 ,X D C A R E ( % a6 )
fmovel % d1 ,% F P C R | r e s t o r e u s e r s e x c e p t i o n s
fmovex X ( % a6 ) ,% f p0 | l a s t i n s t - p o s s i b l e e x c e p t i o n s e t
bra t _ f r c i n x
TANHHUGE :
| - - - RETURN S G N ( X ) - S G N ( X ) E P S
movel X ( % a6 ) ,% d0
andl #0x80000000 ,% d0
orl #0x3F800000 ,% d0
fmoves % d0 ,% f p0
andl #0x80000000 ,% d0
eorl #0x80800000 ,% d0 | . . . - S I G N ( X ) * E P S
fmovel % d1 ,% F P C R | r e s t o r e u s e r s e x c e p t i o n s
fadds % d0 ,% f p0
bra t _ f r c i n x
| end