2005-04-17 02:20:36 +04:00
|
| slog2 . s a 3 . 1 1 2 / 1 0 / 9 0
|
| The e n t r y p o i n t s l o g 1 0 c o m p u t e s t h e b a s e - 1 0
| logarithm o f a n i n p u t a r g u m e n t X .
| slog1 0 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 .
| sLog2 a n d s L o g 2 d a r e t h e b a s e - 2 a n a l o g u e s .
|
| 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
| by a d d r e s s r e g i s t e r a0 .
|
| OUTPUT : log_ 1 0 ( X ) o r l o g _ 2 ( X ) r e t u r n e d i n f l o a t i n g - p o i n t
| register 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 1 . 7
| ulps i n 6 4 s i g n i f i c a n t b i t , i . e . w i t h i n 0 . 5 0 0 3 u l p
| to 5 3 b i t s i f t h e r e s u l t i s s u b s e q u e n t l y r o u n d e d
| to d o u b l e p r e c i s i o n . T h e r e s u l t i s p r o v a b l y m o n o t o n i c
| in d o u b l e p r e c i s i o n .
|
| SPEED : Two t i m i n g s a r e m e a s u r e d , b o t h i n t h e c o p y - b a c k m o d e .
| The f i r s t o n e i s m e a s u r e d w h e n t h e f u n c t i o n i s i n v o k e d
| the f i r s t t i m e ( s o t h e i n s t r u c t i o n s a n d d a t a a r e n o t
| in c a c h e ) , a n d t h e s e c o n d o n e i s m e a s u r e d w h e n t h e
| function i s r e i n v o k e d a t t h e s a m e i n p u t a r g u m e n t .
|
| ALGORITHM a n d I M P L E M E N T A T I O N N O T E S :
|
| slog10d :
|
| Step 0 . I f X < 0 , c r e a t e a N a N a n d r a i s e t h e i n v a l i d o p e r a t i o n
| flag. O t h e r w i s e , s a v e F P C R i n D 1 ; set FpCR to default.
| Notes : Default m e a n s r o u n d - t o - n e a r e s t m o d e , n o f l o a t i n g - p o i n t
| traps, a n d p r e c i s i o n c o n t r o l = d o u b l e e x t e n d e d .
|
| Step 1 . C a l l s l o g n d t o o b t a i n Y = l o g ( X ) , t h e n a t u r a l l o g o f X .
| Notes : Even i f X i s d e n o r m a l i z e d , l o g ( X ) i s a l w a y s n o r m a l i z e d .
|
| Step 2 . C o m p u t e l o g _ 1 0 ( X ) = l o g ( X ) * ( 1 / l o g ( 1 0 ) ) .
| 2 .1 Restore the u s e r F P C R
| 2 .2 Return ans : = Y * I N V _ L 1 0 .
|
|
| slog10 :
|
| Step 0 . I f X < 0 , c r e a t e a N a N a n d r a i s e t h e i n v a l i d o p e r a t i o n
| flag. O t h e r w i s e , s a v e F P C R i n D 1 ; set FpCR to default.
| Notes : Default m e a n s r o u n d - t o - n e a r e s t m o d e , n o f l o a t i n g - p o i n t
| traps, a n d p r e c i s i o n c o n t r o l = d o u b l e e x t e n d e d .
|
| Step 1 . C a l l s L o g N t o o b t a i n Y = l o g ( X ) , t h e n a t u r a l l o g o f X .
|
| Step 2 . C o m p u t e l o g _ 1 0 ( X ) = l o g ( X ) * ( 1 / l o g ( 1 0 ) ) .
| 2 .1 Restore the u s e r F P C R
| 2 .2 Return ans : = Y * I N V _ L 1 0 .
|
|
| sLog2d :
|
| Step 0 . I f X < 0 , c r e a t e a N a N a n d r a i s e t h e i n v a l i d o p e r a t i o n
| flag. O t h e r w i s e , s a v e F P C R i n D 1 ; set FpCR to default.
| Notes : Default m e a n s r o u n d - t o - n e a r e s t m o d e , n o f l o a t i n g - p o i n t
| traps, a n d p r e c i s i o n c o n t r o l = d o u b l e e x t e n d e d .
|
| Step 1 . C a l l s l o g n d t o o b t a i n Y = l o g ( X ) , t h e n a t u r a l l o g o f X .
| Notes : Even i f X i s d e n o r m a l i z e d , l o g ( X ) i s a l w a y s n o r m a l i z e d .
|
| Step 2 . C o m p u t e l o g _ 1 0 ( X ) = l o g ( X ) * ( 1 / l o g ( 2 ) ) .
| 2 .1 Restore the u s e r F P C R
| 2 .2 Return ans : = Y * I N V _ L 2 .
|
|
| sLog2 :
|
| Step 0 . I f X < 0 , c r e a t e a N a N a n d r a i s e t h e i n v a l i d o p e r a t i o n
| flag. O t h e r w i s e , s a v e F P C R i n D 1 ; set FpCR to default.
| Notes : Default m e a n s r o u n d - t o - n e a r e s t m o d e , n o f l o a t i n g - p o i n t
| traps, a n d p r e c i s i o n c o n t r o l = d o u b l e e x t e n d e d .
|
| Step 1 . I f X i s n o t a n i n t e g e r p o w e r o f t w o , i . e . , X ! = 2 ^ k ,
| go t o S t e p 3 .
|
| Step 2 . R e t u r n k .
| 2 .1 Get integer k , X = 2 ^ k .
| 2 .2 Restore the u s e r F P C R .
| 2 .3 Return ans : = c o n v e r t - t o - d o u b l e - e x t e n d e d ( k ) .
|
| Step 3 . C a l l s L o g N t o o b t a i n Y = l o g ( X ) , t h e n a t u r a l l o g o f X .
|
| Step 4 . C o m p u t e l o g _ 2 ( X ) = l o g ( X ) * ( 1 / l o g ( 2 ) ) .
| 4 .1 Restore the u s e r F P C R
| 4 .2 Return ans : = Y * I N V _ L 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
| SLOG2 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 _ f r c i n x
| xref t _ o p e r r
| xref s l o g n
| xref s l o g n d
INV_L10 : .long 0x3FFD0000 , 0 xDE5 B D 8 A 9 ,0 x37 2 8 7 1 9 5 ,0 x00 0 0 0 0 0 0
INV_L2 : .long 0x3FFF0000 , 0 xB8 A A 3 B 2 9 ,0 x5 C 1 7 F 0 B C ,0 x00 0 0 0 0 0 0
.global slog10d
slog10d :
| - - entry p o i n t f o r L o g 1 0 ( X ) , X i s d e n o r m a l i z e d
movel ( % a0 ) ,% d0
blt i n v a l i d
movel % d1 ,- ( % s p )
clrl % d1
bsr s l o g n d | . . . l o g ( X ) , X d e n o r m .
fmovel ( % s p ) + ,% f p c r
fmulx I N V _ L 1 0 ,% f p0
bra t _ f r c i n x
.global slog10
slog10 :
| - - entry p o i n t f o r L o g 1 0 ( X ) , X i s n o r m a l i z e d
movel ( % a0 ) ,% d0
blt i n v a l i d
movel % d1 ,- ( % s p )
clrl % d1
bsr s l o g n | . . . l o g ( X ) , X n o r m a l .
fmovel ( % s p ) + ,% f p c r
fmulx I N V _ L 1 0 ,% f p0
bra t _ f r c i n x
.global slog2d
slog2d :
| - - entry p o i n t f o r L o g 2 ( X ) , X i s d e n o r m a l i z e d
movel ( % a0 ) ,% d0
blt i n v a l i d
movel % d1 ,- ( % s p )
clrl % d1
bsr s l o g n d | . . . l o g ( X ) , X d e n o r m .
fmovel ( % s p ) + ,% f p c r
fmulx I N V _ L 2 ,% f p0
bra t _ f r c i n x
.global slog2
slog2 :
| - - entry p o i n t f o r L o g 2 ( X ) , X i s n o r m a l i z e d
movel ( % a0 ) ,% d0
blt i n v a l i d
movel 8 ( % a0 ) ,% d0
bnes c o n t i n u e | . . . X i s n o t 2 ^ k
movel 4 ( % a0 ) ,% d0
andl #0x7FFFFFFF ,% d0
tstl % d0
bnes c o n t i n u e
| - - X = 2 ^ k .
movew ( % a0 ) ,% d0
andl #0x00007FFF ,% d0
subl #0x3FFF ,% d0
fmovel % d1 ,% f p c r
fmovel % d0 ,% f p0
bra t _ f r c i n x
continue :
movel % d1 ,- ( % s p )
clrl % d1
bsr s l o g n | . . . l o g ( X ) , X n o r m a l .
fmovel ( % s p ) + ,% f p c r
fmulx I N V _ L 2 ,% f p0
bra t _ f r c i n x
invalid :
bra t _ o p e r r
| end