2005-04-16 15:20:36 -07:00
|
| scosh. s a 3 . 1 1 2 / 1 0 / 9 0
|
| The e n t r y p o i n t s C o s h c o m p u t e s t h e h y p e r b o l i c c o s i n e o f
| an i n p u t a r g u m e n t ; sCoshd 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 c o s 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 C O S H t a k e s a p p r o x i m a t e l y 2 5 0 c y c l e s .
|
| Algorithm :
|
| COSH
| 1 . If | X | > 1 6 3 8 0 l o g 2 , g o t o 3 .
|
| 2 . ( | X| < = 1 6 3 8 0 l o g 2 ) C o s h ( X ) i s o b t a i n e d b y t h e f o r m u l a e
| y = | X | , z = e x p ( Y ) , a n d
| cosh( X ) = ( 1 / 2 ) * ( z + 1 / z ) .
| Exit.
|
| 3 . ( | X| > 1 6 3 8 0 l o g 2 ) . I f | X | > 1 6 4 8 0 l o g 2 , g o t o 5 .
|
| 4 . ( 1 6 3 8 0 log2 < | X | < = 1 6 4 8 0 l o g 2 )
| cosh( X ) = s i g n ( X ) * e x p ( | X | ) / 2 .
| However, i n v o k i n g e x p ( | X | ) m a y c a u s e p r e m a t u r e o v e r f l o w .
| Thus, w e c a l c u l a t e s i n h ( X ) a s f o l l o w s :
| Y : = | X |
| Fact : = 2 * * ( 1 6 3 8 0 )
| Y' : = Y - 1 6 3 8 1 l o g 2
| cosh( X ) : = F a c t * e x p ( Y ' ) .
| Exit.
|
| 5 . ( | X| > 1 6 4 8 0 l o g 2 ) s i n h ( X ) m u s t o v e r f l o w . R e t u r n
| Huge* H u g e t o g e n e r a t e o v e r f l o w a n d a n i n f i n i t y w i t h
| the a p p r o p r i a t e s i g n . H u g e i s t h e l a r g e s t f i n i t e n u m b e r i n
| extended f o r m a t . 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-11 17:55:48 -08: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-16 15:20:36 -07:00
| SCOSH 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
| xref t _ o v f l
| xref t _ f r c i n x
| xref s e t o x
T1 : .long 0x40C62D38 , 0 xD3 D 6 4 6 3 4 | . . . 1 6 3 8 1 L O G 2 L E A D
T2 : .long 0x3D6F90AE , 0 xB1 E 7 5 C C 7 | . . . 1 6 3 8 1 L O G 2 T R A I L
TWO16380 : .long 0x7FFB0000 , 0 x8 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
.global scoshd
scoshd :
| - - COSH( X ) = 1 F O R D E N O R M A L I Z E D X
fmoves #0x3F800000 ,% f p0
fmovel % d1 ,% F P C R
fadds #0x00800000 ,% f p0
bra t _ f r c i n x
.global scosh
scosh :
fmovex ( % a0 ) ,% f p0 | . . . L O A D I N P U T
movel ( % a0 ) ,% d0
movew 4 ( % a0 ) ,% d0
andil #0x7FFFFFFF ,% d0
cmpil #0x400CB167 ,% d0
bgts C O S H B I G
| - - THIS I S T H E U S U A L C A S E , | X | < 1 6 3 8 0 L O G 2
| - - COSH( X ) = ( 1 / 2 ) * ( E X P ( X ) + 1 / E X P ( X ) )
fabsx % f p0 | . . . | X |
movel % d1 ,- ( % s p )
clrl % d1
fmovemx % f p0 - % f p0 ,( % a0 ) | p a s s p a r a m e t e r t o s e t o x
bsr s e t o x | . . . F P 0 I S E X P ( | X | )
fmuls #0x3F000000 ,% f p0 | . . . ( 1 / 2 ) E X P ( | X | )
movel ( % s p ) + ,% d1
fmoves #0x3E800000 ,% f p1 | . . . ( 1 / 4 )
fdivx % f p0 ,% f p1 | . . . 1 / ( 2 E X P ( | X | ) )
fmovel % d1 ,% F P C R
faddx % f p1 ,% f p0
bra t _ f r c i n x
COSHBIG :
cmpil #0x400CB2B3 ,% d0
bgts C O S H H U G E
fabsx % f p0
fsubd T 1 ( % p c ) ,% f p0 | . . . ( | X | - 1 6 3 8 1 L O G 2 _ L E A D )
fsubd T 2 ( % p c ) ,% f p0 | . . . | X | - 1 6 3 8 1 L O G 2 , A C C U R A T E
movel % d1 ,- ( % s p )
clrl % d1
fmovemx % f p0 - % f p0 ,( % a0 )
bsr s e t o x
fmovel ( % s p ) + ,% f p c r
fmulx T W O 1 6 3 8 0 ( % p c ) ,% f p0
bra t _ f r c i n x
COSHHUGE :
fmovel #0 ,% f p s r | c l r N b i t i f s e t b y s o u r c e
bclrb #7 ,( % a0 ) | a l w a y s r e t u r n p o s i t i v e v a l u e
fmovemx ( % a0 ) ,% f p0 - % f p0
bra t _ o v f l
| end