2005-04-17 02:20:36 +04:00
|
| stan. s a 3 . 3 7 / 2 9 / 9 1
|
| The e n t r y p o i n t s t a n c o m p u t e s t h e t a n g e n t o f
| an i n p u t a r g u m e n t ;
| stand d o e s t h e s a m e e x c e p t f o r d e n o r m a l i z e d i n p u t .
|
| 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 ( 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 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 t a k e s a p p r o x i m a t e l y 1 7 0 c y c l e s f o r
| input a r g u m e n t X s u c h t h a t | X | < 1 5 P i , w h i c h i s t h e u s u a l
| situation.
|
| Algorithm :
|
| 1 . If | X | > = 1 5 P i o r | X | < 2 * * ( - 4 0 ) , g o t o 6 .
|
| 2 . Decompose X a s X = N ( P i / 2 ) + r w h e r e | r | < = P i / 4 . L e t
| k = N m o d 2 , s o i n p a r t i c u l a r , k = 0 o r 1 .
|
| 3 . If k i s o d d , g o t o 5 .
|
| 4 . ( k i s e v e n ) T a n ( X ) = t a n ( r ) a n d t a n ( r ) i s a p p r o x i m a t e d b y a
| rational f u n c t i o n U / V w h e r e
| U = r + r * s * ( P 1 + s * ( P 2 + s * P 3 ) ) , a n d
| V = 1 + s * ( Q 1 + s * ( Q 2 + s * ( Q 3 + s * Q 4 ) ) ) , s = r * r .
| Exit.
|
| 4 . ( k i s o d d ) T a n ( X ) = - c o t ( r ) . S i n c e t a n ( r ) i s a p p r o x i m a t e d b y a
| rational f u n c t i o n U / V w h e r e
| U = r + r * s * ( P 1 + s * ( P 2 + s * P 3 ) ) , a n d
| V = 1 + s * ( Q 1 + s * ( Q 2 + s * ( Q 3 + s * Q 4 ) ) ) , s = r * r ,
| - Cot( r ) = - V / U . E x i t .
|
| 6 . If | X | > 1 , g o t o 8 .
|
| 7 . ( | X| < 2 * * ( - 4 0 ) ) T a n ( X ) = X . E x i t .
|
| 8 . Overwrite X b y X : = X r e m 2 P i . N o w t h a t | X | < = P i , g o b a c k t o 2 .
|
| 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
| STAN 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 0x3FD78000 , 0 x4 0 0 4 B C 7 E
TWOBYPI : .long 0x3FE45F30 , 0 x6 D C 9 C 8 8 3
TANQ4 : .long 0x3EA0B759 , 0 xF5 0 F 8 6 8 8
TANP3 : .long 0xBEF2BAA5 , 0 xA8 9 2 4 F 0 4
TANQ3 : .long 0xBF346F59 , 0 xB3 9 B A 6 5 F ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
TANP2 : .long 0x3FF60000 , 0 xE0 7 3 D 3 F C ,0 x19 9 C 4 A 0 0 ,0 x00 0 0 0 0 0 0
TANQ2 : .long 0x3FF90000 , 0 xD2 3 C D 6 8 4 ,0 x15 D 9 5 F A 1 ,0 x00 0 0 0 0 0 0
TANP1 : .long 0xBFFC0000 , 0 x8 8 9 5 A 6 C 5 ,0 x F B 4 2 3 B C A ,0 x00 0 0 0 0 0 0
TANQ1 : .long 0xBFFD0000 , 0 xEEF5 7 E 0 D ,0 x A 8 4 B C 8 C E ,0 x00 0 0 0 0 0 0
INVTWOPI : .long 0x3FFC0000 , 0 xA2 F 9 8 3 6 E ,0 x4 E 4 4 1 5 2 A ,0 x00 0 0 0 0 0 0
TWOPI1 : .long 0x40010000 , 0 xC9 0 F D A A 2 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
TWOPI2 : .long 0x3FDF0000 , 0 x8 5 A 3 0 8 D 4 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| - - N* P I / 2 , - 3 2 < = N < = 3 2 , I N A L E A D I N G T E R M I N E X T . A N D T R A I L I N G
| - - TERM I N S G L . N O T E T H A T P I I S 6 4 - B I T L O N G , T H U S N * P I / 2 I S A T
| - - MOST 6 9 B I T S L O N G .
.global PITBL
PITBL :
.long 0 xC0 0 4 0 0 0 0 ,0 x C 9 0 F D A A 2 ,0 x21 6 8 C 2 3 5 ,0 x21 8 0 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x C 2 C 7 5 B C D ,0 x10 5 D 7 C 2 3 ,0 x A 0 D 0 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x B C 7 E D C F 7 ,0 x F F 5 2 3 6 1 1 ,0 x A 1 E 8 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x B 6 3 6 5 E 2 2 ,0 x E E 4 6 F 0 0 0 ,0 x21 4 8 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x A F E D D F 4 D ,0 x D D 3 B A 9 E E ,0 x A 1 2 0 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x A 9 A 5 6 0 7 8 ,0 x C C 3 0 6 3 D D ,0 x21 F C 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x A 3 5 C E 1 A 3 ,0 x B B 2 5 1 D C B ,0 x21 1 0 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x9 D 1 4 6 2 C E ,0 x A A 1 9 D 7 B 9 ,0 x A 1 5 8 0 0 0 0
.long 0 xC0 0 4 0 0 0 0 ,0 x96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D ,0 x D D 3 B A 9 E E ,0 x21 2 0 0 0 0 0
.long 0 x4 0 0 4 0 0 0 0 ,0 x B 6 3 6 5 E 2 2 ,0 x E E 4 6 F 0 0 0 ,0 x A 1 4 8 0 0 0 0
.long 0 x4 0 0 4 0 0 0 0 ,0 x B C 7 E D C F 7 ,0 x F F 5 2 3 6 1 1 ,0 x21 E 8 0 0 0 0
.long 0 x4 0 0 4 0 0 0 0 ,0 x C 2 C 7 5 B C D ,0 x10 5 D 7 C 2 3 ,0 x20 D 0 0 0 0 0
.long 0 x4 0 0 4 0 0 0 0 ,0 x C 9 0 F D A A 2 ,0 x21 6 8 C 2 3 5 ,0 x A 1 8 0 0 0 0 0
.set INARG,F P _ S C R 4
.set TWOTO6 3 ,L _ S C R 1
.set ENDFLAG,L _ S C R 2
.set N,L _ S C R 3
| xref t _ f r c i n x
| xref t _ e x t d n r m
.global stand
stand :
| - - TAN( 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 stan
stan :
fmovex ( % a0 ) ,% f p0 | . . . L O A D I N P U T
movel ( % a0 ) ,% d0
movew 4 ( % a0 ) ,% d0
andil #0x7FFFFFFF ,% d0
cmpil #0x3FD78000 ,% d0 | . . . | X | > = 2 * * ( - 4 0 ) ?
bges T A N O K 1
bra T A N S M
TANOK1 :
cmpil #0x4004BC7E ,% d0 | . . . | X | < 1 5 P I ?
blts T A N M A I N
bra R E D U C E X
TANMAIN :
| - - THIS I S T H E U S U A L C A S E , | X | < = 1 5 P I .
| - - THE A R G U M E N T R E D U C T I O N I S D O N E B Y T A B L E L O O K U P .
fmovex % f p0 ,% f p1
fmuld T W O B Y P I ,% f p1 | . . . X * 2 / P I
| - - HIDE T H E N E X T T W O I N S T R U C T I O N S
leal P I T B L + 0 x20 0 ,% a1 | . . . T A B L E O F N * P I / 2 , N = - 3 2 ,. . . ,3 2
| - - FP1 I S N O W R E A D Y
fmovel % f p1 ,% d0 | . . . C O N V E R T T O I N T E G E R
asll #4 ,% d0
addal % d0 ,% a1 | . . . A D D R E S S N * P I B Y 2 I N Y 1 , Y 2
fsubx ( % a1 ) + ,% f p0 | . . . X - Y 1
| - - HIDE T H E N E X T O N E
fsubs ( % a1 ) ,% f p0 | . . . F P 0 I S R = ( X - Y 1 ) - Y 2
rorl #5 ,% d0
andil #0x80000000 ,% d0 | . . . D 0 W A S O D D I F F D 0 < 0
TANCONT :
cmpil #0 ,% d0
blt N O D D
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1 | . . . S = R * R
fmoved T A N Q 4 ,% f p3
fmoved T A N P 3 ,% f p2
fmulx % f p1 ,% f p3 | . . . S Q 4
fmulx % f p1 ,% f p2 | . . . S P 3
faddd T A N Q 3 ,% f p3 | . . . Q 3 + S Q 4
faddx T A N P 2 ,% f p2 | . . . P 2 + S P 3
fmulx % f p1 ,% f p3 | . . . S ( Q 3 + S Q 4 )
fmulx % f p1 ,% f p2 | . . . S ( P 2 + S P 3 )
faddx T A N Q 2 ,% f p3 | . . . Q 2 + S ( Q 3 + S Q 4 )
faddx T A N P 1 ,% f p2 | . . . P 1 + S ( P 2 + S P 3 )
fmulx % f p1 ,% f p3 | . . . S ( Q 2 + S ( Q 3 + S Q 4 ) )
fmulx % f p1 ,% f p2 | . . . S ( P 1 + S ( P 2 + S P 3 ) )
faddx T A N Q 1 ,% f p3 | . . . Q 1 + S ( Q 2 + S ( Q 3 + S Q 4 ) )
fmulx % f p0 ,% f p2 | . . . R S ( P 1 + S ( P 2 + S P 3 ) )
fmulx % f p3 ,% f p1 | . . . S ( Q 1 + S ( Q 2 + S ( Q 3 + S Q 4 ) ) )
faddx % f p2 ,% f p0 | . . . R + R S ( P 1 + S ( P 2 + S P 3 ) )
fadds #0x3F800000 ,% f p1 | . . . 1 + S ( Q 1 + . . . )
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 % f p1 ,% 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
NODD :
fmovex % f p0 ,% f p1
fmulx % f p0 ,% f p0 | . . . S = R * R
fmoved T A N Q 4 ,% f p3
fmoved T A N P 3 ,% f p2
fmulx % f p0 ,% f p3 | . . . S Q 4
fmulx % f p0 ,% f p2 | . . . S P 3
faddd T A N Q 3 ,% f p3 | . . . Q 3 + S Q 4
faddx T A N P 2 ,% f p2 | . . . P 2 + S P 3
fmulx % f p0 ,% f p3 | . . . S ( Q 3 + S Q 4 )
fmulx % f p0 ,% f p2 | . . . S ( P 2 + S P 3 )
faddx T A N Q 2 ,% f p3 | . . . Q 2 + S ( Q 3 + S Q 4 )
faddx T A N P 1 ,% f p2 | . . . P 1 + S ( P 2 + S P 3 )
fmulx % f p0 ,% f p3 | . . . S ( Q 2 + S ( Q 3 + S Q 4 ) )
fmulx % f p0 ,% f p2 | . . . S ( P 1 + S ( P 2 + S P 3 ) )
faddx T A N Q 1 ,% f p3 | . . . Q 1 + S ( Q 2 + S ( Q 3 + S Q 4 ) )
fmulx % f p1 ,% f p2 | . . . R S ( P 1 + S ( P 2 + S P 3 ) )
fmulx % f p3 ,% f p0 | . . . S ( Q 1 + S ( Q 2 + S ( Q 3 + S Q 4 ) ) )
faddx % f p2 ,% f p1 | . . . R + R S ( P 1 + S ( P 2 + S P 3 ) )
fadds #0x3F800000 ,% f p0 | . . . 1 + S ( Q 1 + . . . )
fmovex % f p1 ,- ( % s p )
eoril #0x80000000 ,( % s p )
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 ( % s p ) + ,% 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
TANBORS :
| - - IF | X | > 1 5 P I , W E U S E T H E G E N E R A L A R G U M E N T R E D U C T I O N .
| - - IF | X | < 2 * * ( - 4 0 ) , R E T U R N X O R 1 .
cmpil #0x3FFF8000 ,% d0
bgts R E D U C E X
TANSM :
fmovex % f p0 ,- ( % s p )
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 ( % s p ) + ,% 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
REDUCEX :
| - - WHEN R E D U C E X I S U S E D , T H E C O D E W I L L I N E V I T A B L Y B E S L O W .
| - - THIS R E D U C T I O N M E T H O D , H O W E V E R , I S M U C H F A S T E R T H A N U S I N G
| - - THE R E M A I N D E R I N S T R U C T I O N W H I C H I S N O W I N S O F T W A R E .
fmovemx % f p2 - % f p5 ,- ( % a7 ) | . . . s a v e F P 2 t h r o u g h F P 5
movel % d2 ,- ( % a7 )
fmoves #0x00000000 ,% f p1
| - - If c o m p a c t f o r m o f a b s ( a r g ) i n d0 = $ 7 f f e f f f f , a r g u m e n t i s s o l a r g e t h a t
| - - there i s a d a n g e r o f u n w a n t e d o v e r f l o w i n f i r s t L O O P i t e r a t i o n . I n t h i s
| - - case, r e d u c e a r g u m e n t b y o n e r e m a i n d e r s t e p t o m a k e s u b s e q u e n t r e d u c t i o n
| - - safe.
cmpil #0x7ffeffff ,% d0 | i s a r g u m e n t d a n g e r o u s l y l a r g e ?
bnes L O O P
movel #0x7ffe0000 ,F P _ S C R 2 ( % a6 ) | y e s
| ;create 2**16383*PI/2
movel #0xc90fdaa2 ,F P _ S C R 2 + 4 ( % a6 )
clrl F P _ S C R 2 + 8 ( % a6 )
ftstx % f p0 | t e s t s i g n o f a r g u m e n t
movel #0x7fdc0000 ,F P _ S C R 3 ( % a6 ) | c r e a t e l o w h a l f o f 2 * * 1 6 3 8 3 *
| ;PI/2 at FP_SCR3
movel #0x85a308d3 ,F P _ S C R 3 + 4 ( % a6 )
clrl F P _ S C R 3 + 8 ( % a6 )
fblt r e d _ n e g
orw #0x8000 ,F P _ S C R 2 ( % a6 ) | p o s i t i v e a r g
orw #0x8000 ,F P _ S C R 3 ( % a6 )
red_neg :
faddx F P _ S C R 2 ( % a6 ) ,% f p0 | h i g h p a r t o f r e d u c t i o n i s e x a c t
fmovex % f p0 ,% f p1 | s a v e h i g h r e s u l t i n f p1
faddx F P _ S C R 3 ( % a6 ) ,% f p0 | l o w p a r t o f r e d u c t i o n
fsubx % f p0 ,% f p1 | d e t e r m i n e l o w c o m p o n e n t o f r e s u l t
faddx F P _ S C R 3 ( % a6 ) ,% f p1 | f p0 / f p1 a r e r e d u c e d a r g u m e n t .
| - - ON E N T R Y , F P 0 I S X , O N R E T U R N , F P 0 I S X R E M P I / 2 , | X | < = P I / 4 .
| - - integer q u o t i e n t w i l l b e s t o r e d i n N
| - - Intermediate r e m a i n d e r i s 6 6 - b i t l o n g ; (R,r) in (FP0,FP1)
LOOP :
fmovex % f p0 ,I N A R G ( % a6 ) | . . . + - 2 * * K * F , 1 < = F < 2
movew I N A R G ( % a6 ) ,% d0
movel % d0 ,% a1 | . . . s a v e a c o p y o f D 0
andil #0x00007FFF ,% d0
subil #0x00003FFF ,% d0 | . . . D 0 I S K
cmpil #28 ,% d0
bles L A S T L O O P
CONTLOOP :
subil #27 ,% d0 | . . . D 0 I S L : = K - 2 7
movel #0 ,E N D F L A G ( % a6 )
bras W O R K
LASTLOOP :
clrl % d0 | . . . D 0 I S L : = 0
movel #1 ,E N D F L A G ( % a6 )
WORK :
| - - FIND T H E R E M A I N D E R O F ( R ,r ) W . R . T . 2 * * L * ( P I / 2 ) . L I S S O C H O S E N
| - - THAT I N T ( X * ( 2 / P I ) / 2 * * ( L ) ) < 2 * * 2 9 .
| - - CREATE 2 * * ( - L ) * ( 2 / P I ) , S I G N ( I N A R G ) * 2 * * ( 6 3 ) ,
| - - 2 * * L * ( P I b y 2 _ 1 ) , 2 * * L * ( P I b y 2 _ 2 )
movel #0x00003FFE ,% d2 | . . . B I A S E D E X P O O F 2 / P I
subl % d0 ,% d2 | . . . B I A S E D E X P O O F 2 * * ( - L ) * ( 2 / P I )
movel #0xA2F9836E ,F P _ S C R 1 + 4 ( % a6 )
movel #0x4E44152A ,F P _ S C R 1 + 8 ( % a6 )
movew % d2 ,F P _ S C R 1 ( % a6 ) | . . . F P _ S C R 1 i s 2 * * ( - L ) * ( 2 / P I )
fmovex % f p0 ,% f p2
fmulx F P _ S C R 1 ( % a6 ) ,% f p2
| - - WE M U S T N O W F I N D I N T ( F P 2 ) . S I N C E W E N E E D T H I S V A L U E I N
| - - FLOATING P O I N T F O R M A T , T H E T W O F M O V E ' S F M O V E . L F P < - - > N
| - - WILL B E T O O I N E F F I C I E N T . T H E W A Y A R O U N D I T I S T H A T
| - - ( SIGN( I N A R G ) * 2 * * 6 3 + F P 2 ) - S I G N ( I N A R G ) * 2 * * 6 3 W I L L G I V E
| - - US T H E D E S I R E D V A L U E I N F L O A T I N G P O I N T .
| - - HIDE S I X C Y C L E S O F I N S T R U C T I O N
movel % a1 ,% d2
swap % d2
andil #0x80000000 ,% d2
oril #0x5F000000 ,% d2 | . . . D 2 I S S I G N ( I N A R G ) * 2 * * 6 3 I N S G L
movel % d2 ,T W O T O 6 3 ( % a6 )
movel % d0 ,% d2
addil #0x00003FFF ,% d2 | . . . B I A S E D E X P O O F 2 * * L * ( P I / 2 )
| - - FP2 I S R E A D Y
fadds T W O T O 6 3 ( % a6 ) ,% f p2 | . . . T H E F R A C T I O N A L P A R T O F F P 1 I S R O U N D E D
| - - HIDE 4 C Y C L E S O F I N S T R U C T I O N ; creating 2**(L)*Piby2_1 and 2**(L)*Piby2_2
movew % d2 ,F P _ S C R 2 ( % a6 )
clrw F P _ S C R 2 + 2 ( % a6 )
movel #0xC90FDAA2 ,F P _ S C R 2 + 4 ( % a6 )
clrl F P _ S C R 2 + 8 ( % a6 ) | . . . F P _ S C R 2 i s 2 * * ( L ) * P i b y 2 _ 1
| - - FP2 I S R E A D Y
fsubs T W O T O 6 3 ( % a6 ) ,% f p2 | . . . F P 2 i s N
addil #0x00003FDD ,% d0
movew % d0 ,F P _ S C R 3 ( % a6 )
clrw F P _ S C R 3 + 2 ( % a6 )
movel #0x85A308D3 ,F P _ S C R 3 + 4 ( % a6 )
clrl F P _ S C R 3 + 8 ( % a6 ) | . . . F P _ S C R 3 i s 2 * * ( L ) * P i b y 2 _ 2
movel E N D F L A G ( % a6 ) ,% d0
| - - We a r e n o w r e a d y t o p e r f o r m ( R + r ) - N * P 1 - N * P 2 , P 1 = 2 * * ( L ) * P i b y 2 _ 1 a n d
| - - P2 = 2 * * ( L ) * P i b y 2 _ 2
fmovex % f p2 ,% f p4
fmulx F P _ S C R 2 ( % a6 ) ,% f p4 | . . . W = N * P 1
fmovex % f p2 ,% f p5
fmulx F P _ S C R 3 ( % a6 ) ,% f p5 | . . . w = N * P 2
fmovex % f p4 ,% f p3
| - - we w a n t P + p = W + w b u t | p | < = h a l f u l p o f P
| - - Then, w e n e e d t o c o m p u t e A : = R - P a n d a : = r - p
faddx % f p5 ,% f p3 | . . . F P 3 i s P
fsubx % f p3 ,% f p4 | . . . W - P
fsubx % f p3 ,% f p0 | . . . F P 0 i s A : = R - P
faddx % f p5 ,% f p4 | . . . F P 4 i s p = ( W - P ) + w
fmovex % f p0 ,% f p3 | . . . F P 3 A
fsubx % f p4 ,% f p1 | . . . F P 1 i s a : = r - p
| - - Now w e n e e d t o n o r m a l i z e ( A ,a ) t o " n e w ( R ,r ) " w h e r e R + r = A + a b u t
| - - | r| < = h a l f u l p o f R .
faddx % f p1 ,% f p0 | . . . F P 0 i s R : = A + a
| - - No n e e d t o c a l c u l a t e r i f t h i s i s t h e l a s t l o o p
cmpil #0 ,% d0
bgt R E S T O R E
| - - Need t o c a l c u l a t e r
fsubx % f p0 ,% f p3 | . . . A - R
faddx % f p3 ,% f p1 | . . . F P 1 i s r : = ( A - R ) + a
bra L O O P
RESTORE :
fmovel % f p2 ,N ( % a6 )
movel ( % a7 ) + ,% d2
fmovemx ( % a7 ) + ,% f p2 - % f p5
movel N ( % a6 ) ,% d0
rorl #1 ,% d0
bra T A N C O N T
| end