2005-04-16 15:20:36 -07:00
|
| ssin. s a 3 . 3 7 / 2 9 / 9 1
|
| The e n t r y p o i n t s S I N c o m p u t e s t h e s i n e o f a n i n p u t a r g u m e n t
| sCOS c o m p u t e s t h e c o s i n e , a n d s S I N C O S c o m p u t e s b o t h . T h e
| corresponding e n t r y p o i n t s w i t h a " d " c o m p u t e s t h e s a m e
| corresponding f u n c t i o n v a l u e s f o r d e n o r m a l i z e d i n p u t s .
|
| 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 f u n c t i o n v a l u e s i n ( X ) o r c o s ( X ) r e t u r n e d i n F p0 i f S I N o r
| COS i s r e q u e s t e d . O t h e r w i s e , f o r S I N C O S , s i n ( X ) i s r e t u r n e d
| in F p0 , a n d c o s ( X ) i s r e t u r n e d i n F p1 .
|
| Modifies : Fp0 f o r S I N o r C O S ; both Fp0 and Fp1 for SINCOS.
|
| 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 1 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 s S I N a n d s C O S t a k e a p p r o x i m a t e l y 1 5 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. T h e s p e e d f o r s S I N C O S i s a p p r o x i m a t e l y 1 9 0 c y c l e s .
|
| Algorithm :
|
| SIN a n d C O S :
| 1 . If S I N i s i n v o k e d , s e t A d j N : = 0 ; otherwise, set AdjN := 1.
|
| 2 . If | X | > = 1 5 P i o r | X | < 2 * * ( - 4 0 ) , g o t o 7 .
|
| 3 . 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 4 , s o i n p a r t i c u l a r , k = 0 ,1 ,2 ,o r 3 . O v e r w r i t e
| k b y k : = k + A d j N .
|
| 4 . If k i s e v e n , g o t o 6 .
|
| 5 . ( k i s o d d ) S e t j : = ( k - 1 ) / 2 , s g n : = ( - 1 ) * * j . R e t u r n s g n * c o s ( r )
| where c o s ( r ) i s a p p r o x i m a t e d b y a n e v e n p o l y n o m i a l i n r ,
| 1 + r* r * ( B 1 + s * ( B 2 + . . . + s * B 8 ) ) , s = r * r .
| Exit.
|
| 6 . ( k i s e v e n ) S e t j : = k / 2 , s g n : = ( - 1 ) * * j . R e t u r n s g n * s i n ( r )
| where s i n ( r ) i s a p p r o x i m a t e d b y a n o d d p o l y n o m i a l i n r
| r + r * s * ( A 1 + s * ( A 2 + . . . + s * A 7 ) ) , s = r * r .
| Exit.
|
| 7 . If | X | > 1 , g o t o 9 .
|
| 8 . ( | X| < 2 * * ( - 4 0 ) ) I f S I N i s i n v o k e d , r e t u r n X ; otherwise return 1.
|
| 9 . 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 3 .
|
| SINCOS :
| 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 4 , s o i n p a r t i c u l a r , k = 0 ,1 ,2 ,o r 3 .
|
| 3 . If k i s e v e n , g o t o 5 .
|
| 4 . ( k i s o d d ) S e t j 1 : = ( k - 1 ) / 2 , j 2 : = j 1 ( E O R ) ( k m o d 2 ) , i . e .
| j1 e x c l u s i v e o r w i t h t h e l . s . b . o f k .
| sgn1 : = ( - 1 ) * * j 1 , s g n 2 : = ( - 1 ) * * j 2 .
| SIN( X ) = s g n 1 * c o s ( r ) a n d C O S ( X ) = s g n 2 * s i n ( r ) w h e r e
| sin( r ) a n d c o s ( r ) a r e c o m p u t e d a s o d d a n d e v e n p o l y n o m i a l s
| in r , r e s p e c t i v e l y . E x i t
|
| 5 . ( k i s e v e n ) S e t j 1 : = k / 2 , s g n 1 : = ( - 1 ) * * j 1 .
| SIN( X ) = s g n 1 * s i n ( r ) a n d C O S ( X ) = s g n 1 * c o s ( r ) w h e r e
| sin( r ) a n d c o s ( r ) a r e c o m p u t e d a s o d d a n d e v e n p o l y n o m i a l s
| in r , r e s p e c t i v e l y . E x i t
|
| 6 . If | X | > 1 , g o t o 8 .
|
| 7 . ( | X| < 2 * * ( - 4 0 ) ) S I N ( X ) = X a n d C O S ( X ) = 1 . 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-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
| SSIN 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
SINA7 : .long 0xBD6AAA77 , 0 xCCC9 9 4 F 5
SINA6 : .long 0x3DE61209 , 0 x7 A A E 8 D A 1
SINA5 : .long 0xBE5AE645 , 0 x2 A 1 1 8 A E 4
SINA4 : .long 0x3EC71DE3 , 0 xA5 3 4 1 5 3 1
SINA3 : .long 0xBF2A01A0 , 0 x1 A 0 1 8 B 5 9 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
SINA2 : .long 0x3FF80000 , 0 x8 8 8 8 8 8 8 8 ,0 x88 8 8 5 9 A F ,0 x00 0 0 0 0 0 0
SINA1 : .long 0xBFFC0000 , 0 xAAAAAAAA,0 x A A A A A A 9 9 ,0 x00 0 0 0 0 0 0
COSB8 : .long 0x3D2AC4D0 , 0 xD6 0 1 1 E E 3
COSB7 : .long 0xBDA9396F , 0 x9 F 4 5 A C 1 9
COSB6 : .long 0x3E21EED9 , 0 x0 6 1 2 C 9 7 2
COSB5 : .long 0xBE927E4F , 0 xB7 9 D 9 F C F
COSB4 : .long 0x3EFA01A0 , 0 x1 A 0 1 D 4 2 3 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
COSB3 : .long 0xBFF50000 , 0 xB6 0 B 6 0 B 6 ,0 x0 B 6 1 D 4 3 8 ,0 x00 0 0 0 0 0 0
COSB2 : .long 0x3FFA0000 , 0 xAAAAAAAA,0 x A A A A A B 5 E
COSB1 : .long 0xBF000000
INVTWOPI : .long 0x3FFC0000 , 0 xA2 F 9 8 3 6 E ,0 x4 E 4 4 1 5 2 A
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
| xref P I T B L
.set INARG,F P _ S C R 4
.set X,F P _ S C R 5
.set XDCARE,X + 2
.set XFRAC,X + 4
.set RPRIME,F P _ S C R 1
.set SPRIME,F P _ S C R 2
.set POSNEG1 ,L _ S C R 1
.set TWOTO6 3 ,L _ S C R 1
.set ENDFLAG,L _ S C R 2
.set N,L _ S C R 2
.set ADJN,L _ S C R 3
| xref t _ f r c i n x
| xref t _ e x t d n r m
| xref s t o _ c o s
.global ssind
ssind :
| - - SIN( 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 scosd
scosd :
| - - COS( X ) = 1 F O R D E N O R M A L I Z E D X
fmoves #0x3F800000 ,% f p0
|
| 9 D2 5 B F i x : S o m e t i m e s t h e p r e v i o u s f m o v e . s s e t s f p s r b i t s
|
fmovel #0 ,% f p s r
|
bra t _ f r c i n x
.global ssin
ssin :
| - - SET A D J N T O 0
movel #0 ,A D J N ( % a6 )
bras S I N B G N
.global scos
scos :
| - - SET A D J N T O 1
movel #1 ,A D J N ( % a6 )
SINBGN :
| - - SAVE F P C R , F P 1 . C H E C K I F | X | I S T O O S M A L L O R L A R G E
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 | . . . C O M P A C T I F Y X
cmpil #0x3FD78000 ,% d0 | . . . | X | > = 2 * * ( - 4 0 ) ?
bges S O K 1
bra S I N S M
SOK1 :
cmpil #0x4004BC7E ,% d0 | . . . | X | < 1 5 P I ?
blts S I N M A I N
bra R E D U C E X
SINMAIN :
| - - 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 H R E E I N S T R U C T I O N S
lea 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 ,N ( % a6 ) | . . . C O N V E R T T O I N T E G E R
movel N ( % a6 ) ,% d0
asll #4 ,% d0
addal % d0 ,% a1 | . . . A 1 I S T H E A D D R E S S O F N * P I B Y 2
| . . .WHICH IS IN T W O P I E C E S 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
SINCONT :
| - - continuation f r o m R E D U C E X
| - - GET N + A D J N A N D S E E I F S I N ( R ) O R C O S ( R ) I S N E E D E D
movel N ( % a6 ) ,% d0
addl A D J N ( % a6 ) ,% d0 | . . . S E E I F D 0 I S O D D O R E V E N
rorl #1 ,% d0 | . . . D 0 W A S O D D I F F D 0 I S N E G A T I V E
cmpil #0 ,% d0
blt C O S P O L Y
SINPOLY :
| - - LET J B E T H E L E A S T S I G . B I T O F D 0 , L E T S G N : = ( - 1 ) * * J .
| - - THEN W E R E T U R N S G N * S I N ( R ) . S G N * S I N ( R ) I S C O M P U T E D B Y
| - - R' + R ' * S * ( A 1 + S ( A 2 + S ( A 3 + S ( A 4 + . . . + S A 7 ) ) ) ) , W H E R E
| - - R' = S G N * R , S =R * R . T H I S C A N B E R E W R I T T E N A S
| - - R' + R ' * S * ( [ A 1 + T ( A 3 + T ( A 5 + T A 7 ) ) ] + [ S ( A 2 + T ( A 4 + T A 6 ) ) ] )
| - - WHERE T =S * S .
| - - NOTE T H A T A 3 T H R O U G H A 7 A R E S T O R E D I N D O U B L E P R E C I S I O N
| - - WHILE A 1 A N D A 2 A R E I N D O U B L E - E X T E N D E D F O R M A T .
fmovex % f p0 ,X ( % a6 ) | . . . X I S R
fmulx % f p0 ,% f p0 | . . . F P 0 I S S
| - - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R F P 0
fmoved S I N A 7 ,% f p3
fmoved S I N A 6 ,% f p2
| - - FP0 I S N O W R E A D Y
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1 | . . . F P 1 I S T
| - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R F P 1
rorl #1 ,% d0
andil #0x80000000 ,% d0
| . . .LEAST SIG. B I T O F D 0 I N S I G N P O S I T I O N
eorl % d0 ,X ( % a6 ) | . . . X I S N O W R ' = S G N * R
fmulx % f p1 ,% f p3 | . . . T A 7
fmulx % f p1 ,% f p2 | . . . T A 6
faddd S I N A 5 ,% f p3 | . . . A 5 + T A 7
faddd S I N A 4 ,% f p2 | . . . A 4 + T A 6
fmulx % f p1 ,% f p3 | . . . T ( A 5 + T A 7 )
fmulx % f p1 ,% f p2 | . . . T ( A 4 + T A 6 )
faddd S I N A 3 ,% f p3 | . . . A 3 + T ( A 5 + T A 7 )
faddx S I N A 2 ,% f p2 | . . . A 2 + T ( A 4 + T A 6 )
fmulx % f p3 ,% f p1 | . . . T ( A 3 + T ( A 5 + T A 7 ) )
fmulx % f p0 ,% f p2 | . . . S ( A 2 + T ( A 4 + T A 6 ) )
faddx S I N A 1 ,% f p1 | . . . A 1 + T ( A 3 + T ( A 5 + T A 7 ) )
fmulx X ( % a6 ) ,% f p0 | . . . R ' * S
faddx % f p2 ,% f p1 | . . . [ A 1 + T ( A 3 + T ( A 5 + T A 7 ) ) ] + [ S ( A 2 + T ( A 4 + T A 6 ) ) ]
| - - FP3 R E L E A S E D , R E S T O R E N O W A N D T A K E S O M E A D V A N T A G E O F H I D I N G
| - - FP2 R E L E A S E D , R E S T O R E N O W A N D T A K E F U L L A D V A N T A G E O F H I D I N G
fmulx % f p1 ,% f p0 | . . . S I N ( R ' ) - R '
| - - FP1 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 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
COSPOLY :
| - - LET J B E T H E L E A S T S I G . B I T O F D 0 , L E T S G N : = ( - 1 ) * * J .
| - - THEN W E R E T U R N S G N * C O S ( R ) . S G N * C O S ( R ) I S C O M P U T E D B Y
| - - SGN + S ' * ( B 1 + S ( B 2 + S ( B 3 + S ( B 4 + . . . + S B 8 ) ) ) ) , W H E R E
| - - S=R * R A N D S ' =SGN * S . T H I S C A N B E R E W R I T T E N A S
| - - SGN + S ' * ( [ B 1 + T ( B 3 + T ( B 5 + T B 7 ) ) ] + [ S ( B 2 + T ( B 4 + T ( B 6 + T B 8 ) ) ) ] )
| - - WHERE T =S * S .
| - - NOTE T H A T B 4 T H R O U G H B 8 A R E S T O R E D I N D O U B L E P R E C I S I O N
| - - WHILE B 2 A N D B 3 A R E I N D O U B L E - E X T E N D E D F O R M A T , B 1 I S - 1 / 2
| - - AND I S T H E R E F O R E S T O R E D A S S I N G L E P R E C I S I O N .
fmulx % f p0 ,% f p0 | . . . F P 0 I S S
| - - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R F P 0
fmoved C O S B 8 ,% f p2
fmoved C O S B 7 ,% f p3
| - - FP0 I S N O W R E A D Y
fmovex % f p0 ,% f p1
fmulx % f p1 ,% f p1 | . . . F P 1 I S T
| - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R F P 1
fmovex % f p0 ,X ( % a6 ) | . . . X I S S
rorl #1 ,% d0
andil #0x80000000 ,% d0
| . . .LEAST SIG. B I T O F D 0 I N S I G N P O S I T I O N
fmulx % f p1 ,% f p2 | . . . T B 8
| - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R T H E X U
eorl % d0 ,X ( % a6 ) | . . . X I S N O W S ' = S G N * S
andil #0x80000000 ,% d0
fmulx % f p1 ,% f p3 | . . . T B 7
| - - HIDE T H E N E X T T W O W H I L E W A I T I N G F O R T H E X U
oril #0x3F800000 ,% d0 | . . . D 0 I S S G N I N S I N G L E
movel % d0 ,P O S N E G 1 ( % a6 )
faddd C O S B 6 ,% f p2 | . . . B 6 + T B 8
faddd C O S B 5 ,% f p3 | . . . B 5 + T B 7
fmulx % f p1 ,% f p2 | . . . T ( B 6 + T B 8 )
fmulx % f p1 ,% f p3 | . . . T ( B 5 + T B 7 )
faddd C O S B 4 ,% f p2 | . . . B 4 + T ( B 6 + T B 8 )
faddx C O S B 3 ,% f p3 | . . . B 3 + T ( B 5 + T B 7 )
fmulx % f p1 ,% f p2 | . . . T ( B 4 + T ( B 6 + T B 8 ) )
fmulx % f p3 ,% f p1 | . . . T ( B 3 + T ( B 5 + T B 7 ) )
faddx C O S B 2 ,% f p2 | . . . B 2 + T ( B 4 + T ( B 6 + T B 8 ) )
fadds C O S B 1 ,% f p1 | . . . B 1 + T ( B 3 + T ( B 5 + T B 7 ) )
fmulx % f p2 ,% f p0 | . . . S ( B 2 + T ( B 4 + T ( B 6 + T B 8 ) ) )
| - - FP3 R E L E A S E D , R E S T O R E N O W A N D T A K E S O M E A D V A N T A G E O F H I D I N G
| - - FP2 R E L E A S E D .
faddx % f p1 ,% f p0
| - - FP1 R E L E A S E D
fmulx 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
fadds P O S N E G 1 ( % 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
SINBORS :
| - - 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
SINSM :
movel A D J N ( % a6 ) ,% d0
cmpil #0 ,% d0
bgts C O S T I N Y
SINTINY :
movew #0x0000 ,X D C A R E ( % a6 ) | . . . J U S T I N C A S E
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
COSTINY :
fmoves #0x3F800000 ,% 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
fsubs #0x00800000 ,% 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 A D J N ( % a6 ) ,% d0
cmpil #4 ,% d0
blt S I N C O N T
bras S C C O N T
.global ssincosd
ssincosd :
| - - SIN A N D C O S O F X F O R D E N O R M A L I Z E D X
fmoves #0x3F800000 ,% f p1
bsr s t o _ c o s | s t o r e c o s i n e r e s u l t
bra t _ e x t d n r m
.global ssincos
ssincos :
| - - SET A D J N T O 4
movel #4 ,A D J N ( % a6 )
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 | . . . C O M P A C T I F Y X
cmpil #0x3FD78000 ,% d0 | . . . | X | > = 2 * * ( - 4 0 ) ?
bges S C O K 1
bra S C S M
SCOK1 :
cmpil #0x4004BC7E ,% d0 | . . . | X | < 1 5 P I ?
blts S C M A I N
bra R E D U C E X
SCMAIN :
| - - 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 H R E E I N S T R U C T I O N S
lea 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 ,N ( % a6 ) | . . . C O N V E R T T O I N T E G E R
movel N ( % a6 ) ,% d0
asll #4 ,% d0
addal % d0 ,% a1 | . . . A D D R E S S O F N * P I B Y 2 , I N Y 1 , Y 2
fsubx ( % a1 ) + ,% f p0 | . . . X - Y 1
fsubs ( % a1 ) ,% f p0 | . . . F P 0 I S R = ( X - Y 1 ) - Y 2
SCCONT :
| - - continuation p o i n t f r o m R E D U C E X
| - - HIDE T H E N E X T T W O
movel N ( % a6 ) ,% d0
rorl #1 ,% d0
cmpil #0 ,% d0 | . . . D 0 < 0 I F F N I S O D D
bge N E V E N
NODD :
| - - REGISTERS S A V E D S O F A R : D 0 , A 0 , F P 2 .
fmovex % f p0 ,R P R I M E ( % a6 )
fmulx % f p0 ,% f p0 | . . . F P 0 I S S = R * R
fmoved S I N A 7 ,% f p1 | . . . A 7
fmoved C O S B 8 ,% f p2 | . . . B 8
fmulx % f p0 ,% f p1 | . . . S A 7
movel % d2 ,- ( % a7 )
movel % d0 ,% d2
fmulx % f p0 ,% f p2 | . . . S B 8
rorl #1 ,% d2
andil #0x80000000 ,% d2
faddd S I N A 6 ,% f p1 | . . . A 6 + S A 7
eorl % d0 ,% d2
andil #0x80000000 ,% d2
faddd C O S B 7 ,% f p2 | . . . B 7 + S B 8
fmulx % f p0 ,% f p1 | . . . S ( A 6 + S A 7 )
eorl % d2 ,R P R I M E ( % a6 )
movel ( % a7 ) + ,% d2
fmulx % f p0 ,% f p2 | . . . S ( B 7 + S B 8 )
rorl #1 ,% d0
andil #0x80000000 ,% d0
faddd S I N A 5 ,% f p1 | . . . A 5 + S ( A 6 + S A 7 )
movel #0x3F800000 ,P O S N E G 1 ( % a6 )
eorl % d0 ,P O S N E G 1 ( % a6 )
faddd C O S B 6 ,% f p2 | . . . B 6 + S ( B 7 + S B 8 )
fmulx % f p0 ,% f p1 | . . . S ( A 5 + S ( A 6 + S A 7 ) )
fmulx % f p0 ,% f p2 | . . . S ( B 6 + S ( B 7 + S B 8 ) )
fmovex % f p0 ,S P R I M E ( % a6 )
faddd S I N A 4 ,% f p1 | . . . A 4 + S ( A 5 + S ( A 6 + S A 7 ) )
eorl % d0 ,S P R I M E ( % a6 )
faddd C O S B 5 ,% f p2 | . . . B 5 + S ( B 6 + S ( B 7 + S B 8 ) )
fmulx % f p0 ,% f p1 | . . . S ( A 4 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( B 5 + . . . )
faddd S I N A 3 ,% f p1 | . . . A 3 + S ( A 4 + . . . )
faddd C O S B 4 ,% f p2 | . . . B 4 + S ( B 5 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( A 3 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( B 4 + . . . )
faddx S I N A 2 ,% f p1 | . . . A 2 + S ( A 3 + . . . )
faddx C O S B 3 ,% f p2 | . . . B 3 + S ( B 4 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( A 2 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( B 3 + . . . )
faddx S I N A 1 ,% f p1 | . . . A 1 + S ( A 2 + . . . )
faddx C O S B 2 ,% f p2 | . . . B 2 + S ( B 3 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( A 1 + . . . )
fmulx % f p2 ,% f p0 | . . . S ( B 2 + . . . )
fmulx R P R I M E ( % a6 ) ,% f p1 | . . . R ' S ( A 1 + . . . )
fadds C O S B 1 ,% f p0 | . . . B 1 + S ( B 2 . . . )
fmulx S P R I M E ( % a6 ) ,% f p0 | . . . S ' ( B 1 + S ( B 2 + . . . ) )
movel % d1 ,- ( % s p ) | r e s t o r e u s e r s m o d e & p r e c i s i o n
andil #0xff ,% d1 | m a s k o f f a l l e x c e p t i o n s
fmovel % d1 ,% F P C R
faddx R P R I M E ( % a6 ) ,% f p1 | . . . C O S ( X )
bsr s t o _ c o s | s t o r e c o s i n e r e s u l t
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
fadds P O S N E G 1 ( % a6 ) ,% f p0 | . . . S I N ( X )
bra t _ f r c i n x
NEVEN :
| - - REGISTERS S A V E D S O F A R : F P 2 .
fmovex % f p0 ,R P R I M E ( % a6 )
fmulx % f p0 ,% f p0 | . . . F P 0 I S S = R * R
fmoved C O S B 8 ,% f p1 | . . . B 8
fmoved S I N A 7 ,% f p2 | . . . A 7
fmulx % f p0 ,% f p1 | . . . S B 8
fmovex % f p0 ,S P R I M E ( % a6 )
fmulx % f p0 ,% f p2 | . . . S A 7
rorl #1 ,% d0
andil #0x80000000 ,% d0
faddd C O S B 7 ,% f p1 | . . . B 7 + S B 8
faddd S I N A 6 ,% f p2 | . . . A 6 + S A 7
eorl % d0 ,R P R I M E ( % a6 )
eorl % d0 ,S P R I M E ( % a6 )
fmulx % f p0 ,% f p1 | . . . S ( B 7 + S B 8 )
oril #0x3F800000 ,% d0
movel % d0 ,P O S N E G 1 ( % a6 )
fmulx % f p0 ,% f p2 | . . . S ( A 6 + S A 7 )
faddd C O S B 6 ,% f p1 | . . . B 6 + S ( B 7 + S B 8 )
faddd S I N A 5 ,% f p2 | . . . A 5 + S ( A 6 + S A 7 )
fmulx % f p0 ,% f p1 | . . . S ( B 6 + S ( B 7 + S B 8 ) )
fmulx % f p0 ,% f p2 | . . . S ( A 5 + S ( A 6 + S A 7 ) )
faddd C O S B 5 ,% f p1 | . . . B 5 + S ( B 6 + S ( B 7 + S B 8 ) )
faddd S I N A 4 ,% f p2 | . . . A 4 + S ( A 5 + S ( A 6 + S A 7 ) )
fmulx % f p0 ,% f p1 | . . . S ( B 5 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( A 4 + . . . )
faddd C O S B 4 ,% f p1 | . . . B 4 + S ( B 5 + . . . )
faddd S I N A 3 ,% f p2 | . . . A 3 + S ( A 4 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( B 4 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( A 3 + . . . )
faddx C O S B 3 ,% f p1 | . . . B 3 + S ( B 4 + . . . )
faddx S I N A 2 ,% f p2 | . . . A 2 + S ( A 3 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( B 3 + . . . )
fmulx % f p0 ,% f p2 | . . . S ( A 2 + . . . )
faddx C O S B 2 ,% f p1 | . . . B 2 + S ( B 3 + . . . )
faddx S I N A 1 ,% f p2 | . . . A 1 + S ( A 2 + . . . )
fmulx % f p0 ,% f p1 | . . . S ( B 2 + . . . )
fmulx % f p2 ,% f p0 | . . . s ( a1 + . . . )
fadds C O S B 1 ,% f p1 | . . . B 1 + S ( B 2 . . . )
fmulx R P R I M E ( % a6 ) ,% f p0 | . . . R ' S ( A 1 + . . . )
fmulx S P R I M E ( % a6 ) ,% f p1 | . . . S ' ( B 1 + S ( B 2 + . . . ) )
movel % d1 ,- ( % s p ) | s a v e u s e r s m o d e & p r e c i s i o n
andil #0xff ,% d1 | m a s k o f f a l l e x c e p t i o n s
fmovel % d1 ,% F P C R
fadds P O S N E G 1 ( % a6 ) ,% f p1 | . . . C O S ( X )
bsr s t o _ c o s | s t o r e c o s i n e r e s u l t
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 R P R I M E ( % a6 ) ,% f p0 | . . . S I N ( X )
bra t _ f r c i n x
SCBORS :
cmpil #0x3FFF8000 ,% d0
bgt R E D U C E X
SCSM :
movew #0x0000 ,X D C A R E ( % a6 )
fmoves #0x3F800000 ,% f p1
movel % d1 ,- ( % s p ) | s a v e u s e r s m o d e & p r e c i s i o n
andil #0xff ,% d1 | m a s k o f f a l l e x c e p t i o n s
fmovel % d1 ,% F P C R
fsubs #0x00800000 ,% f p1
bsr s t o _ c o s | s t o r e c o s i n e r e s u l t
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
fmovex X ( % a6 ) ,% f p0
bra t _ f r c i n x
| end