2005-04-17 02:20:36 +04:00
|
| satan. s a 3 . 3 1 2 / 1 9 / 9 0
|
| The e n t r y p o i n t s a t a n c o m p u t e s t h e a r c t a n g e n t o f a n
| input v a l u e . s a t a n d d o e s t h e s a m e e x c e p t t h e i n p u t v a l u e i s a
| denormalized n u m b e r .
|
| Input : Double- e x t e n d e d v a l u e i n m e m o r y l o c a t i o n p o i n t e d t o b y a d d r e s s
| register a0 .
|
| Output : Arctan( 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 2 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 a t a n t a k e s a p p r o x i m a t e l y 1 6 0 c y c l e s f o r i n p u t
| argument X s u c h t h a t 1 / 1 6 < | X | < 1 6 . F o r t h e o t h e r a r g u m e n t s ,
| the p r o g r a m w i l l r u n n o w o r s e t h a n 1 0 % s l o w e r .
|
| Algorithm :
| Step 1 . I f | X | > = 1 6 o r | X | < 1 / 1 6 , g o t o S t e p 5 .
|
| Step 2 . L e t X = s g n * 2 * * k * 1 . x x x x x x x x . . . x . N o t e t h a t k = - 4 , - 3 ,. . . , o r 3 .
| Define F = s g n * 2 * * k * 1 . x x x x1 , i . e . t h e f i r s t 5 s i g n i f i c a n t b i t s
| of X w i t h a b i t - 1 a t t a c h e d a t t h e 6 - t h b i t p o s i t i o n . D e f i n e u
| to b e u = ( X - F ) / ( 1 + X * F ) .
|
| Step 3 . A p p r o x i m a t e a r c t a n ( u ) b y a p o l y n o m i a l p o l y .
|
| Step 4 . R e t u r n a r c t a n ( F ) + p o l y , a r c t a n ( F ) i s f e t c h e d f r o m a t a b l e o f v a l u e s
| calculated b e f o r e h a n d . E x i t .
|
| Step 5 . I f | X | > = 1 6 , g o t o S t e p 7 .
|
| Step 6 . A p p r o x i m a t e a r c t a n ( X ) b y a n o d d p o l y n o m i a l i n X . E x i t .
|
| Step 7 . D e f i n e X ' = - 1 / X . A p p r o x i m a t e a r c t a n ( X ' ) b y a n o d d p o l y n o m i a l i n X ' .
| Arctan( X ) = s i g n ( X ) * P i / 2 + a r c t a n ( 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
| satan 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 "
BOUNDS1 : .long 0x3FFB8000 , 0 x4 0 0 2 F F F F
ONE : .long 0x3F800000
.long 0x00000000
ATANA3 : .long 0xBFF6687E , 0 x3 1 4 9 8 7 D 8
ATANA2 : .long 0x4002AC69 , 0 x3 4 A 2 6 D B 3
ATANA1 : .long 0xBFC2476F , 0 x4 E 1 D A 2 8 E
ATANB6 : .long 0x3FB34444 , 0 x7 F 8 7 6 9 8 9
ATANB5 : .long 0xBFB744EE , 0 x7 F A F 4 5 D B
ATANB4 : .long 0x3FBC71C6 , 0 x4 6 9 4 0 2 2 0
ATANB3 : .long 0xBFC24924 , 0 x9 2 1 8 7 2 F 9
ATANB2 : .long 0x3FC99999 , 0 x9 9 9 9 8 F A 9
ATANB1 : .long 0xBFD55555 , 0 x5 5 5 5 5 5 5 5
ATANC5 : .long 0xBFB70BF3 , 0 x9 8 5 3 9 E 6 A
ATANC4 : .long 0x3FBC7187 , 0 x9 6 2 D 1 D 7 D
ATANC3 : .long 0xBFC24924 , 0 x8 2 7 1 0 7 B 8
ATANC2 : .long 0x3FC99999 , 0 x9 9 9 6 2 6 3 E
ATANC1 : .long 0xBFD55555 , 0 x5 5 5 5 5 5 3 6
PPIBY2 : .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
NPIBY2 : .long 0xBFFF0000 , 0 xC9 0 F D A A 2 ,0 x21 6 8 C 2 3 5 ,0 x00 0 0 0 0 0 0
PTINY : .long 0x00010000 , 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
NTINY : .long 0x80010000 , 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
ATANTBL :
.long 0 x3 F F B 0 0 0 0 ,0 x83 D 1 5 2 C 5 ,0 x06 0 B 7 A 5 1 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x8 B C 8 5 4 4 5 ,0 x65 4 9 8 B 8 B ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x93 B E 4 0 6 0 ,0 x17 6 2 6 B 0 D ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x9 B B 3 0 7 8 D ,0 x35 A E C 2 0 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x A 3 A 6 9 A 5 2 ,0 x5 D D C E 7 D E ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x A B 9 8 E 9 4 3 ,0 x62 7 6 5 6 1 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x B 3 8 9 E 5 0 2 ,0 x F 9 C 5 9 8 6 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x B B 7 9 7 E 4 3 ,0 x6 B 0 9 E 6 F B ,0 x00 0 0 0 0 0 0
.long 0 x3 F F B 0 0 0 0 ,0 x C 3 6 7 A 5 C 7 ,0 x39 E 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0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x B 2 2 D F F F D ,0 x9 D 5 3 9 F 8 3 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x B 9 E D E F 4 5 ,0 x3 E 9 0 0 E A 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x C 1 A 8 5 F 1 C ,0 x C 7 5 E 3 E A 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x C 9 5 D 1 B E 8 ,0 x28 1 3 8 D E 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x D 1 0 B F 3 0 0 ,0 x84 0 D 2 D E 4 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x D 8 B 4 B 2 B A ,0 x6 B C 0 5 E 7 A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x E 0 5 7 2 A 6 B ,0 x B 4 2 3 3 5 F 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x E 7 F 3 2 A 7 0 ,0 x E A 9 C A A 8 F ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x E F 8 8 8 4 3 2 ,0 x64 E C E F A A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F C 0 0 0 0 ,0 x F 7 1 7 0 A 2 8 ,0 x E C C 0 6 6 6 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x81 2 F D 2 8 8 ,0 x33 2 D A D 3 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x88 A 8 D 1 B 1 ,0 x21 8 E 4 D 6 4 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x90 1 2 A B 3 F ,0 x23 E 4 A E E 8 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x97 6 C C 3 D 4 ,0 x11 E 7 F 1 B 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x9 E B 6 8 9 4 9 ,0 x38 8 9 A 2 2 7 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x A 5 E F 7 2 C 3 ,0 x44 8 7 3 6 1 B ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x A D 1 7 0 0 B A ,0 x F 0 7 A 7 2 2 7 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x B 4 2 C B C F A ,0 x F D 3 7 E F B 7 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x B B 3 0 3 A 9 4 ,0 x0 B A 8 0 F 8 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x C 2 2 1 1 5 C 6 ,0 x F C A E B B A F ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x C 8 F E F 3 E 6 ,0 x86 3 3 1 2 2 1 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x C F C 9 8 3 3 0 ,0 x B 4 0 0 0 C 7 0 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x D 6 8 0 7 A A 1 ,0 x10 2 C 5 B F 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x D D 2 3 9 9 B C ,0 x31 2 5 2 A A 3 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x E 3 B 2 A 8 5 5 ,0 x6 B 8 F C 5 1 7 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x E A 2 D 7 6 4 F ,0 x64 3 1 5 9 8 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F D 0 0 0 0 ,0 x F 3 B F 5 B F 8 ,0 x B A D 1 A 2 1 D ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x80 1 C E 3 9 E ,0 x0 D 2 0 5 C 9 A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x86 3 0 A 2 D A ,0 x D A 1 E D 0 6 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x8 C 1 A D 4 4 5 ,0 x F 3 E 0 9 B 8 C ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x91 D B 8 F 1 6 ,0 x64 F 3 5 0 E 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x97 7 3 1 4 2 0 ,0 x36 5 E 5 3 8 C ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x9 C E 1 C 8 E 6 ,0 x A 0 B 8 C D B A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x A 2 2 8 3 2 D B ,0 x C A D A A E 0 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x A 7 4 6 F 2 D D ,0 x B 7 6 0 2 2 9 4 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x A C 3 E C 0 F B ,0 x99 7 D D 6 A 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x B 1 1 0 6 8 8 A ,0 x E B D C 6 F 6 A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x B 5 B C C 4 9 0 ,0 x59 E C C 4 B 0 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x B A 4 4 B C 7 D ,0 x D 4 7 0 7 8 2 F ,0 x00 0 0 0 0 0 0
.long 0 x3 F F E 0 0 0 0 ,0 x B E A 9 4 1 4 4 ,0 x F D 0 4 9 A A C ,0 x00 0 0 0 0 0 0
.long 0 x3 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0
.long 0 x3 F F F 0 0 0 0 ,0 x B 2 8 A A A 1 5 ,0 x6 F 9 A D A 3 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 3 7 B 4 4 F F ,0 x37 6 6 B 8 9 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 4 5 8 C 3 D C ,0 x E 9 6 3 0 4 3 3 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 5 2 5 5 2 9 D ,0 x56 2 2 4 6 B D ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 5 E 2 C C A 9 ,0 x5 F 9 D 8 8 C C ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 6 9 2 C A D A ,0 x7 A C A 1 A D A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 7 3 6 A E A 7 ,0 x A 6 9 2 5 8 3 8 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 7 C F A B 2 8 ,0 x7 E 9 F 7 B 3 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 8 5 E C C 6 6 ,0 x C B 2 1 9 8 3 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 8 E 4 F D 5 A ,0 x20 A 5 9 3 D A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B 9 9 F 4 1 F 6 ,0 x4 A F F 9 B B 5 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B A 7 F 1 E 1 7 ,0 x84 2 B B E 7 B ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B B 4 7 1 2 8 5 ,0 x76 3 7 E 1 7 D ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B B F A B E 8 A ,0 x47 8 8 D F 6 F ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B C 9 D 0 F A D ,0 x2 B 6 8 9 D 7 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B D 3 0 6 A 3 9 ,0 x47 1 E C D 8 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B D B 6 C 7 3 1 ,0 x85 6 A F 1 8 A ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B E 3 1 C A C 5 ,0 x02 E 8 0 D 7 0 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B E A 2 D 5 5 C ,0 x E 3 3 1 9 4 E 2 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B F 0 B 1 0 B 7 ,0 x C 0 3 1 2 8 F 0 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B F 6 B 7 A 1 8 ,0 x D A C B 7 7 8 D ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x B F C 4 E A 4 6 ,0 x63 F A 1 8 F 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x C 0 1 8 1 B D E ,0 x8 B 8 9 A 4 5 4 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x C 0 6 5 B 0 6 6 ,0 x C F B F 6 4 3 9 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x C 0 A E 3 4 5 F ,0 x56 3 4 0 A E 6 ,0 x00 0 0 0 0 0 0
.long 0 x3 F F F 0 0 0 0 ,0 x C 0 F 2 2 2 9 1 ,0 x9 C B 9 E 6 A 7 ,0 x00 0 0 0 0 0 0
.set X,F P _ S C R 1
.set XDCARE,X + 2
.set XFRAC,X + 4
.set XFRACLO,X + 8
.set ATANF,F P _ S C R 2
.set ATANFHI,A T A N F + 4
.set ATANFLO,A T A N F + 8
| xref t _ f r c i n x
| xref t _ e x t d n r m
.global satand
satand :
| - - ENTRY P O I N T F O R A T A N ( X ) F O R D E N O R M A L I Z E D A R G U M E N T
bra t _ e x t d n r m
.global satan
satan :
| - - ENTRY P O I N T F O R A T A N ( X ) , H E R E X I S F I N I T E , N O N - Z E R O , A N D N O T N A N ' S
fmovex ( % a0 ) ,% f p0 | . . . L O A D I N P U T
movel ( % a0 ) ,% d0
movew 4 ( % a0 ) ,% d0
fmovex % f p0 ,X ( % a6 )
andil #0x7FFFFFFF ,% d0
cmpil #0x3FFB8000 ,% d0 | . . . | X | > = 1 / 1 6 ?
bges A T A N O K 1
bra A T A N S M
ATANOK1 :
cmpil #0x4002FFFF ,% d0 | . . . | X | < 1 6 ?
bles A T A N M A I N
bra A T A N B I G
| - - THE M O S T L I K E L Y C A S E , | X | I N [ 1 / 1 6 , 1 6 ) . W E U S E T A B L E T E C H N I Q U E
| - - THE I D E A I S A T A N ( X ) = A T A N ( F ) + A T A N ( [ X - F ] / [ 1 + X F ] ) .
| - - SO I F F I S C H O S E N T O B E C L O S E T O X A N D A T A N ( F ) I S S T O R E D I N
| - - A T A B L E , A L L W E N E E D I S T O A P P R O X I M A T E A T A N ( U ) W H E R E
| - - U = ( X - F ) / ( 1 + X F ) I S S M A L L ( R E M E M B E R F I S C L O S E T O X ) . I T I S
| - - TRUE T H A T A D I V I D E I S N O W N E E D E D , B U T T H E A P P R O X I M A T I O N F O R
| - - ATAN( U ) I S A V E R Y S H O R T P O L Y N O M I A L A N D T H E I N D E X I N G T O
| - - FETCH F A N D S A V I N G O F R E G I S T E R S C A N B E A L L H I D E D U N D E R T H E
| - - DIVIDE. I N T H E E N D T H I S M E T H O D I S M U C H F A S T E R T H A N A T R A D I T I O N A L
| - - ONE. N O T E A L S O T H A T T H E T R A D I T I O N A L S C H E M E T H A T A P P R O X I M A T E
| - - ATAN( X ) D I R E C T L Y W I L L N E E D T O U S E A R A T I O N A L A P P R O X I M A T I O N
| - - ( DIVISION N E E D E D ) A N Y W A Y B E C A U S E A P O L Y N O M I A L A P P R O X I M A T I O N
| - - WILL I N V O L V E A V E R Y L O N G P O L Y N O M I A L .
| - - NOW W E S E E X A S + - 2 ^ K * 1 . B B B B B B B . . . . B < - 1 . + 6 3 B I T S
| - - WE C H O S E F T O B E + - 2 ^ K * 1 . B B B B 1
| - - THAT I S I T M A T C H E S T H E E X P O N E N T A N D F I R S T 5 B I T S O F X , T H E
| - - SIXTH B I T S I S S E T T O B E 1 . S I N C E K = - 4 , - 3 , . . . , 3 , T H E R E
| - - ARE O N L Y 8 T I M E S 1 6 = 2 ^ 7 = 1 2 8 | F | ' S . S I N C E A T A N ( - | F | ) I S
| - - - ATAN( | F | ) , W E N E E D T O S T O R E O N L Y A T A N ( | F | ) .
ATANMAIN :
movew #0x0000 ,X D C A R E ( % a6 ) | . . . C L E A N U P X J U S T I N C A S E
andil #0xF8000000 ,X F R A C ( % a6 ) | . . . F I R S T 5 B I T S
oril #0x04000000 ,X F R A C ( % a6 ) | . . . S E T 6 - T H B I T T O 1
movel #0x00000000 ,X F R A C L O ( % a6 ) | . . . L O C A T I O N O F X I S N O W F
fmovex % f p0 ,% f p1 | . . . F P 1 I S X
fmulx X ( % a6 ) ,% f p1 | . . . F P 1 I S X * F , N O T E T H A T X * F > 0
fsubx X ( % a6 ) ,% f p0 | . . . F P 0 I S X - F
fadds #0x3F800000 ,% f p1 | . . . F P 1 I S 1 + X * F
fdivx % f p1 ,% f p0 | . . . F P 0 I S U = ( X - F ) / ( 1 + X * F )
| - - WHILE T H E D I V I S I O N I S T A K I N G I T S T I M E , W E F E T C H A T A N ( | F | )
| - - CREATE A T A N ( F ) A N D S T O R E I T I N A T A N F , A N D
| - - SAVE R E G I S T E R S F P 2 .
movel % d2 ,- ( % a7 ) | . . . S A V E d2 T E M P O R A R I L Y
movel % d0 ,% d2 | . . . T H E E X P O A N D 1 6 B I T S O F X
andil #0x00007800 ,% d0 | . . . 4 V A R Y I N G B I T S O F F ' S F R A C T I O N
andil #0x7FFF0000 ,% d2 | . . . E X P O N E N T O F F
subil #0x3FFB0000 ,% d2 | . . . K + 4
asrl #1 ,% d2
addl % d2 ,% d0 | . . . T H E 7 B I T S I D E N T I F Y I N G F
asrl #7 ,% d0 | . . . I N D E X I N T O T B L O F A T A N ( | F | )
lea A T A N T B L ,% a1
addal % d0 ,% a1 | . . . A D D R E S S O F A T A N ( | F | )
movel ( % a1 ) + ,A T A N F ( % a6 )
movel ( % a1 ) + ,A T A N F H I ( % a6 )
movel ( % a1 ) + ,A T A N F L O ( % a6 ) | . . . A T A N F I S N O W A T A N ( | F | )
movel X ( % a6 ) ,% d0 | . . . L O A D S I G N A N D E X P O . A G A I N
andil #0x80000000 ,% d0 | . . . S I G N ( F )
orl % d0 ,A T A N F ( % a6 ) | . . . A T A N F I S N O W S I G N ( F ) * A T A N ( | F | )
movel ( % a7 ) + ,% d2 | . . . R E S T O R E d2
| - - THAT' S A L L I H A V E T O D O F O R N O W ,
| - - BUT A L A S , T H E D I V I D E I S S T I L L C R A N K I N G !
| - - U I N F P 0 , W E A R E N O W R E A D Y T O C O M P U T E A T A N ( U ) A S
| - - U + A 1 * U * V * ( A 2 + V * ( A 3 + V ) ) , V = U * U
| - - THE P O L Y N O M I A L M A Y L O O K S T R A N G E , B U T I S N E V E R T H E L E S S C O R R E C T .
| - - THE N A T U R A L F O R M I S U + U * V * ( A 1 + V * ( A 2 + V * A 3 ) )
| - - WHAT W E H A V E H E R E I S M E R E L Y A 1 = A 3 , A 2 = A 1 / A 3 , A 3 = A 2 / A 3 .
| - - THE R E A S O N F O R T H I S R E A R R A N G E M E N T I S T O M A K E T H E I N D E P E N D E N T
| - - PARTS A 1 * U * V A N D ( A 2 + . . . S T U F F ) M O R E L O A D - B A L A N C E D
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1
fmoved A T A N A 3 ,% f p2
faddx % f p1 ,% f p2 | . . . A 3 + V
fmulx % f p1 ,% f p2 | . . . V * ( A 3 + V )
fmulx % f p0 ,% f p1 | . . . U * V
faddd A T A N A 2 ,% f p2 | . . . A 2 + V * ( A 3 + V )
fmuld A T A N A 1 ,% f p1 | . . . A 1 * U * V
fmulx % f p2 ,% f p1 | . . . A 1 * U * V * ( A 2 + V * ( A 3 + V ) )
faddx % f p1 ,% f p0 | . . . A T A N ( U ) , F P 1 R E L E A S E D
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 A T A N F ( % a6 ) ,% f p0 | . . . A T A N ( X )
bra t _ f r c i n x
ATANBORS :
| - - | X| I S I N d0 I N C O M P A C T F O R M . F P 1 , d0 S A V E D .
| - - FP0 I S X A N D | X | < = 1 / 1 6 O R | X | > = 1 6 .
cmpil #0x3FFF8000 ,% d0
bgt A T A N B I G | . . . I . E . | X | > = 1 6
ATANSM :
| - - | X| < = 1 / 1 6
| - - IF | X | < 2 ^ ( - 4 0 ) , R E T U R N X A S A N S W E R . O T H E R W I S E , A P P R O X I M A T E
| - - ATAN( X ) B Y X + X * Y * ( B 1 + Y * ( B 2 + Y * ( B 3 + Y * ( B 4 + Y * ( B 5 + Y * B 6 ) ) ) ) )
| - - WHICH I S X + X * Y * ( [ B 1 + Z * ( B 3 + Z * B 5 ) ] + [ Y * ( B 2 + Z * ( B 4 + Z * B 6 ) ] )
| - - WHERE Y = X * X , A N D Z = Y * Y .
cmpil #0x3FD78000 ,% d0
blt A T A N T I N Y
| - - COMPUTE P O L Y N O M I A L
fmulx % f p0 ,% f p0 | . . . F P 0 I S Y = X * X
movew #0x0000 ,X D C A R E ( % a6 )
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1 | . . . F P 1 I S Z = Y * Y
fmoved A T A N B 6 ,% f p2
fmoved A T A N B 5 ,% f p3
fmulx % f p1 ,% f p2 | . . . Z * B 6
fmulx % f p1 ,% f p3 | . . . Z * B 5
faddd A T A N B 4 ,% f p2 | . . . B 4 + Z * B 6
faddd A T A N B 3 ,% f p3 | . . . B 3 + Z * B 5
fmulx % f p1 ,% f p2 | . . . Z * ( B 4 + Z * B 6 )
fmulx % f p3 ,% f p1 | . . . Z * ( B 3 + Z * B 5 )
faddd A T A N B 2 ,% f p2 | . . . B 2 + Z * ( B 4 + Z * B 6 )
faddd A T A N B 1 ,% f p1 | . . . B 1 + Z * ( B 3 + Z * B 5 )
fmulx % f p0 ,% f p2 | . . . Y * ( B 2 + Z * ( B 4 + Z * B 6 ) )
fmulx X ( % a6 ) ,% f p0 | . . . X * Y
faddx % f p2 ,% f p1 | . . . [ B 1 + Z * ( B 3 + Z * B 5 ) ] + [ Y * ( B 2 + Z * ( B 4 + Z * B 6 ) ) ]
fmulx % f p1 ,% f p0 | . . . X * Y * ( [ B 1 + Z * ( B 3 + Z * B 5 ) ] + [ Y * ( B 2 + Z * ( B 4 + Z * B 6 ) ) ] )
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 X ( % a6 ) ,% f p0
bra t _ f r c i n x
ATANTINY :
| - - | X| < 2 ^ ( - 4 0 ) , A T A N ( X ) = X
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
ATANBIG :
| - - IF | X | > 2 ^ ( 1 0 0 ) , R E T U R N S I G N ( X ) * ( P I / 2 - T I N Y ) . O T H E R W I S E ,
| - - RETURN S I G N ( X ) * P I / 2 + A T A N ( - 1 / X ) .
cmpil #0x40638000 ,% d0
bgt A T A N H U G E
| - - APPROXIMATE A T A N ( - 1 / X ) B Y
| - - X' + X ' * Y * ( C 1 + Y * ( C 2 + Y * ( C 3 + Y * ( C 4 + Y * C 5 ) ) ) ) , X ' = - 1 / X , Y = X ' * X '
| - - THIS C A N B E R E - W R I T T E N A S
| - - X' + X ' * Y * ( [ C 1 + Z * ( C 3 + Z * C 5 ) ] + [ Y * ( C 2 + Z * C 4 ) ] ) , Z = Y * Y .
fmoves #0xBF800000 ,% f p1 | . . . L O A D - 1
fdivx % f p0 ,% f p1 | . . . F P 1 I S - 1 / X
| - - DIVIDE I S S T I L L C R A N K I N G
fmovex % f p1 ,% f p0 | . . . F P 0 I S X '
fmulx % f p0 ,% f p0 | . . . F P 0 I S Y = X ' * X '
fmovex % f p1 ,X ( % a6 ) | . . . X I S R E A L L Y X '
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1 | . . . F P 1 I S Z = Y * Y
fmoved A T A N C 5 ,% f p3
fmoved A T A N C 4 ,% f p2
fmulx % f p1 ,% f p3 | . . . Z * C 5
fmulx % f p1 ,% f p2 | . . . Z * B 4
faddd A T A N C 3 ,% f p3 | . . . C 3 + Z * C 5
faddd A T A N C 2 ,% f p2 | . . . C 2 + Z * C 4
fmulx % f p3 ,% f p1 | . . . Z * ( C 3 + Z * C 5 ) , F P 3 R E L E A S E D
fmulx % f p0 ,% f p2 | . . . Y * ( C 2 + Z * C 4 )
faddd A T A N C 1 ,% f p1 | . . . C 1 + Z * ( C 3 + Z * C 5 )
fmulx X ( % a6 ) ,% f p0 | . . . X ' * Y
faddx % f p2 ,% f p1 | . . . [ Y * ( C 2 + Z * C 4 ) ] + [ C 1 + Z * ( C 3 + Z * C 5 ) ]
fmulx % f p1 ,% f p0 | . . . X ' * Y * ( [ B 1 + Z * ( B 3 + Z * B 5 ) ]
| . . . + [ Y* ( B 2 + Z * ( B 4 + Z * B 6 ) ) ] )
faddx X ( % a6 ) ,% f p0
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
btstb #7 ,( % a0 )
beqs p o s _ b i g
neg_big :
faddx N P I B Y 2 ,% f p0
bra t _ f r c i n x
pos_big :
faddx P P I B Y 2 ,% f p0
bra t _ f r c i n x
ATANHUGE :
| - - RETURN S I G N ( X ) * ( P I B Y 2 - T I N Y ) = S I G N ( X ) * P I B Y 2 - S I G N ( X ) * T I N Y
btstb #7 ,( % a0 )
beqs p o s _ h u g e
neg_huge :
fmovex N P I B Y 2 ,% f p0
fmovel % d1 ,% f p c r
fsubx N T I N Y ,% f p0
bra t _ f r c i n x
pos_huge :
fmovex P P I B Y 2 ,% f p0
fmovel % d1 ,% f p c r
fsubx P T I N Y ,% f p0
bra t _ f r c i n x
| end