2005-04-17 02:20:36 +04:00
|
| sint. s a 3 . 1 1 2 / 1 0 / 9 0
|
| The e n t r y p o i n t s I N T c o m p u t e s t h e r o u n d e d i n t e g e r
| equivalent o f t h e i n p u t a r g u m e n t , s I N T R Z c o m p u t e s
| the i n t e g e r r o u n d e d t o z e r o o f t h e i n p u t a r g u m e n t .
|
| Entry p o i n t s s i n t a n d s i n t r z a r e c a l l e d f r o m d o _ f u n c
| to e m u l a t e t h e f i n t a n d f i n t r z u n i m p l e m e n t e d i n s t r u c t i o n s ,
| respectively. E n t r y p o i n t s i n t d o i s u s e d b y b i n d e c .
|
| Input : ( Entry p o i n t s s i n t a n d s i n t r z ) D o u b l e - e x t e n d e d
| number X i n t h e E T E M P s p a c e i n t h e f l o a t i n g - p o i n t
| save s t a c k .
| ( Entry p o i n t s i n t d o ) D o u b l e - e x t e n d e d n u m b e r X i n
| location p o i n t e d t o b y t h e a d d r e s s r e g i s t e r a0 .
| ( Entry p o i n t s i n t d ) D o u b l e - e x t e n d e d d e n o r m a l i z e d
| number X i n t h e E T E M P s p a c e i n t h e f l o a t i n g - p o i n t
| save s t a c k .
|
| Output : The f u n c t i o n r e t u r n s i n t ( X ) o r i n t r z ( X ) i n f p0 .
|
| Modifies : fp0 .
|
| Algorithm : ( sint a n d s i n t r z )
|
| 1 . If e x p ( X ) > = 6 3 , r e t u r n X .
| If e x p ( X ) < 0 , r e t u r n + / - 0 o r + / - 1 , a c c o r d i n g t o
| the r o u n d i n g m o d e .
|
| 2 . ( X i s i n r a n g e ) s e t r s c = 6 3 - e x p ( X ) . U n n o r m a l i z e t h e
| result t o t h e e x p o n e n t $ 4 0 3 e .
|
| 3 . Round t h e r e s u l t i n t h e m o d e g i v e n i n U S E R _ F P C R . F o r
| sintrz, f o r c e r o u n d - t o - z e r o m o d e .
|
| 4 . Normalize t h e r o u n d e d r e s u l t ; store in fp0.
|
| For t h e d e n o r m a l i z e d c a s e s , f o r c e t h e c o r r e c t r e s u l t
| for t h e g i v e n s i g n a n d r o u n d i n g m o d e .
|
| Sign( X )
| RMODE + -
| - - - - - - - - - - - - -
| RN + 0 - 0
| RZ + 0 - 0
| RM + 0 - 1
| RP + 1 - 0
|
|
| 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
| SINT 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 "
| xref d n r m _ l p
| xref n r m _ s e t
| xref r o u n d
| xref t _ i n x2
| xref l d _ p o n e
| xref l d _ m o n e
| xref l d _ p z e r o
| xref l d _ m z e r o
| xref s n z r i n x
|
| FINT
|
.global sint
sint :
bfextu F P C R _ M O D E ( % a6 ) { #2 : #2 } ,% d1 | u s e u s e r ' s m o d e f o r r o u n d i n g
| ;implicitly has extend precision
| ;in upper word.
movel % d1 ,L _ S C R 1 ( % a6 ) | s a v e m o d e b i t s
bras s i n t e x c
|
| FINT w i t h e x t e n d e d d e n o r m i n p u t s .
|
.global sintd
sintd :
btstb #5 ,F P C R _ M O D E ( % a6 )
beq s n z r i n x | i f r o u n d n e a r e s t o r r o u n d z e r o , + / - 0
btstb #4 ,F P C R _ M O D E ( % a6 )
beqs r n d _ m n s
rnd_pls :
btstb #s i g n _ b i t , L O C A L _ E X ( % a 0 )
bnes s i n t m z
bsr l d _ p o n e | i f r o u n d p l u s i n f a n d p o s , a n s w e r i s + 1
bra t _ i n x2
rnd_mns :
btstb #s i g n _ b i t , L O C A L _ E X ( % a 0 )
beqs s i n t p z
bsr l d _ m o n e | i f r o u n d m n s i n f a n d n e g , a n s w e r i s - 1
bra t _ i n x2
sintpz :
bsr l d _ p z e r o
bra t _ i n x2
sintmz :
bsr l d _ m z e r o
bra t _ i n x2
|
| FINTRZ
|
.global sintrz
sintrz :
movel #1 ,L _ S C R 1 ( % a6 ) | u s e r z m o d e f o r r o u n d i n g
| ;implicitly has extend precision
| ;in upper word.
bras s i n t e x c
|
| SINTDO
|
| Input : a0 p o i n t s t o a n I E E E e x t e n d e d f o r m a t o p e r a n d
| Output : fp0 h a s t h e r e s u l t
|
| Exceptions :
|
| If t h e s u b r o u t i n e r e s u l t s i n a n i n e x a c t o p e r a t i o n , t h e i n x2 a n d
| ainx b i t s i n t h e U S E R _ F P S R a r e s e t .
|
|
.global sintdo
sintdo :
bfextu F P C R _ M O D E ( % a6 ) { #2 : #2 } ,% d1 | u s e u s e r ' s m o d e f o r r o u n d i n g
| ;implicitly has ext precision
| ;in upper word.
movel % d1 ,L _ S C R 1 ( % a6 ) | s a v e m o d e b i t s
|
| Real w o r k o f s i n t i s i n s i n t e x c
|
sintexc :
bclrb #s i g n _ b i t , L O C A L _ E X ( % a 0 ) | c o n v e r t t o i n t e r n a l e x t e n d e d
| ;format
sne L O C A L _ S G N ( % a0 )
cmpw #0x403e ,L O C A L _ E X ( % a0 ) | c h e c k i f ( u n b i a s e d ) e x p > 6 3
bgts o u t _ r n g e | b r a n c h i f e x p < 6 3
cmpw #0x3ffd ,L O C A L _ E X ( % a0 ) | c h e c k i f ( u n b i a s e d ) e x p < 0
bgt i n _ r n g e | i f 6 3 > = e x p > 0 , d o c a l c
|
| Input i s l e s s t h a n z e r o . R e s t o r e s i g n , a n d c h e c k f o r d i r e c t e d
| rounding m o d e s . L _ S C R 1 c o n t a i n s t h e r m o d e i n t h e l o w e r b y t e .
|
un_rnge :
btstb #1 ,L _ S C R 1 + 3 ( % a6 ) | c h e c k f o r r n a n d r z
beqs u n _ r n r z
tstb L O C A L _ S G N ( % a0 ) | c h e c k f o r s i g n
bnes u n _ r m r p _ n e g
|
| Sign i s + . I f r p , l o a d + 1 . 0 , i f r m , l o a d + 0 . 0
|
cmpib #3 ,L _ S C R 1 + 3 ( % a6 ) | c h e c k f o r r p
beqs u n _ l d p o n e | i f r p , l o a d + 1 . 0
bsr l d _ p z e r o | i f r m , l o a d + 0 . 0
bra t _ i n x2
un_ldpone :
bsr l d _ p o n e
bra t _ i n x2
|
| Sign i s - . I f r m , l o a d - 1 . 0 , i f r p , l o a d - 0 . 0
|
un_rmrp_neg :
cmpib #2 ,L _ S C R 1 + 3 ( % a6 ) | c h e c k f o r r m
beqs u n _ l d m o n e | i f r m , l o a d - 1 . 0
bsr l d _ m z e r o | i f r p , l o a d - 0 . 0
bra t _ i n x2
un_ldmone :
bsr l d _ m o n e
bra t _ i n x2
|
| Rmode i s r n o r r z ; return signed zero
|
un_rnrz :
tstb L O C A L _ S G N ( % a0 ) | c h e c k f o r s i g n
bnes u n _ r n r z _ n e g
bsr l d _ p z e r o
bra t _ i n x2
un_rnrz_neg :
bsr l d _ m z e r o
bra t _ i n x2
|
| Input i s g r e a t e r t h a n 2 ^ 6 3 . A l l b i t s a r e s i g n i f i c a n t . R e t u r n
| the i n p u t .
|
out_rnge :
bfclr L O C A L _ S G N ( % a0 ) { #0 : #8 } | c h a n g e b a c k t o I E E E e x t f o r m a t
beqs i n t p s
bsetb #s i g n _ b i t , L O C A L _ E X ( % a 0 )
intps :
fmovel % f p c r ,- ( % s p )
fmovel #0 ,% f p c r
fmovex L O C A L _ E X ( % a0 ) ,% f p0 | i f e x p > 6 3
| ;then return X to the user
| ;there are no fraction bits
fmovel ( % s p ) + ,% f p c r
rts
in_rnge :
| ;shift off fraction bits
clrl % d0 | c l e a r d0 - i n i t i a l g ,r ,s f o r
| ;dnrm_lp
movel #0x403e ,% d1 | s e t t h r e s h o l d f o r d n r m _ l p
| ;assumes a0 points to operand
bsr d n r m _ l p
| ;returns unnormalized number
| ;pointed by a0
| ;output d0 supplies g,r,s
| ;used by round
movel L _ S C R 1 ( % a6 ) ,% d1 | u s e s e l e c t e d r o u n d i n g m o d e
|
|
bsr r o u n d | r o u n d t h e u n n o r m b a s e d o n u s e r s
| ;input a0 ptr to ext X
| ; d0 g,r,s bits
| ; d1 PREC/MODE info
| ;output a0 ptr to rounded result
| ;inexact flag set in USER_FPSR
| ;if initial grs set
|
| normalize t h e r o u n d e d r e s u l t a n d s t o r e v a l u e i n f p0
|
bsr n r m _ s e t | n o r m a l i z e t h e u n n o r m
| ;Input: a0 points to operand to
| ;be normalized
| ;Output: a0 points to normalized
| ;result
bfclr L O C A L _ S G N ( % a0 ) { #0 : #8 }
beqs n r m r n d p
bsetb #s i g n _ b i t , L O C A L _ E X ( % a 0 ) | r e t u r n t o I E E E e x t e n d e d f o r m a t
nrmrndp :
fmovel % f p c r ,- ( % s p )
fmovel #0 ,% f p c r
fmovex L O C A L _ E X ( % a0 ) ,% f p0 | m o v e r e s u l t t o f p0
fmovel ( % s p ) + ,% f p c r
rts
| end