2005-04-17 02:20:36 +04:00
|
| sacos. s a 3 . 3 1 2 / 1 9 / 9 0
|
| Description : The e n t r y p o i n t s A c o s c o m p u t e s t h e i n v e r s e c o s i n e o f
| an i n p u t a r g u m e n t ; sAcosd 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 a r c c o s ( 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 t a k e s a p p r o x i m a t e l y 3 1 0 c y c l e s .
|
| Algorithm :
|
| ACOS
| 1 . If | X | > = 1 , g o t o 3 .
|
| 2 . ( | X| < 1 ) C a l c u l a t e a c o s ( X ) b y
| z : = ( 1 - X ) / ( 1 + X )
| acos( X ) = 2 * a t a n ( s q r t ( z ) ) .
| Exit.
|
| 3 . If | X | > 1 , g o t o 5 .
|
| 4 . ( | X| = 1 ) I f X > 0 , r e t u r n 0 . O t h e r w i s e , r e t u r n P i . E x i t .
|
| 5 . ( | X| > 1 ) G e n e r a t e a n i n v a l i d o p e r a t i o n b y 0 * i n f i n i t y .
| Exit.
|
| 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
| SACOS 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
PI : .long 0x40000000 , 0 xC9 0 F D A A 2 ,0 x21 6 8 C 2 3 5 ,0 x00 0 0 0 0 0 0
PIBY2 : .long 0x3FFF0000 , 0 xC9 0 F D A A 2 ,0 x21 6 8 C 2 3 5 ,0 x00 0 0 0 0 0 0
| xref t _ o p e r r
| xref t _ f r c i n x
| xref s a t a n
.global sacosd
sacosd :
| - - ACOS( X ) = P I / 2 F O R D E N O R M A L I Z E D X
fmovel % d1 ,% f p c r | . . . l o a d u s e r ' s r o u n d i n g m o d e / p r e c i s i o n
fmovex P I B Y 2 ,% f p0
bra t _ f r c i n x
.global sacos
sacos :
fmovex ( % a0 ) ,% f p0 | . . . L O A D I N P U T
movel ( % a0 ) ,% d0 | . . . p a c k e x p o n e n t w i t h u p p e r 1 6 f r a c t i o n
movew 4 ( % a0 ) ,% d0
andil #0x7FFFFFFF ,% d0
cmpil #0x3FFF8000 ,% d0
bges A C O S B I G
| - - THIS I S T H E U S U A L C A S E , | X | < 1
| - - ACOS( X ) = 2 * A T A N ( S Q R T ( ( 1 - X ) / ( 1 + X ) ) )
fmoves #0x3F800000 ,% f p1
faddx % f p0 ,% f p1 | . . . 1 + X
fnegx % f p0 | . . . - X
fadds #0x3F800000 ,% f p0 | . . . 1 - X
fdivx % f p1 ,% f p0 | . . . ( 1 - X ) / ( 1 + X )
fsqrtx % f p0 | . . . S Q R T ( ( 1 - X ) / ( 1 + X ) )
fmovemx % f p0 - % f p0 ,( % a0 ) | . . . o v e r w r i t e i n p u t
movel % d1 ,- ( % s p ) | s a v e o r i g i n a l u s e r s f p c r
clrl % d1
bsr s a t a n | . . . A T A N ( S Q R T ( [ 1 - X ] / [ 1 + X ] ) )
fmovel ( % s p ) + ,% 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 p0 ,% f p0 | . . . 2 * A T A N ( S T U F F )
bra t _ f r c i n x
ACOSBIG :
fabsx % f p0
fcmps #0x3F800000 ,% f p0
fbgt t _ o p e r r | c a u s e a n o p e r r e x c e p t i o n
| - - | X| = 1 , A C O S ( X ) = 0 O R P I
movel ( % a0 ) ,% d0 | . . . p a c k e x p o n e n t w i t h u p p e r 1 6 f r a c t i o n
movew 4 ( % a0 ) ,% d0
cmpl #0 ,% d0 | D 0 h a s o r i g i n a l e x p o n e n t + f r a c t i o n
bgts A C O S P 1
| - - X = - 1
| Returns P I a n d i n e x a c t e x c e p t i o n
fmovex P I ,% f p0
fmovel % d1 ,% F P C R
fadds #0x00800000 ,% f p0 | c a u s e a n i n e x a c t e x c e p t i o n t o b e p u t
| ;into the 040 - will not trap until next
| ;fp inst.
bra t _ f r c i n x
ACOSP1 :
fmovel % d1 ,% F P C R
fmoves #0x00000000 ,% f p0
rts | F a c o s ; of +1 is exact
| end