2005-04-17 02:20:36 +04:00
|
| util. s a 3 . 7 7 / 2 9 / 9 1
|
| This f i l e c o n t a i n s r o u t i n e s u s e d b y o t h e r p r o g r a m s .
|
| ovf_res : used b y o v e r f l o w t o f o r c e t h e c o r r e c t
| result. o v f _ r _ k , o v f _ r _ x2 , o v f _ r _ x3 a r e
| derivatives o f t h i s r o u t i n e .
| get_fline : get u s e r ' s o p c o d e w o r d
| g_dfmtou : returns t h e d e s t i n a t i o n f o r m a t .
| g_opcls : returns t h e o p c l a s s o f t h e f l o a t i n s t r u c t i o n .
| g_rndpr : returns t h e r o u n d i n g p r e c i s i o n .
| reg_dest : write b y t e , w o r d , o r l o n g d a t a t o D n
|
|
| 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
| UTIL 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 m e m _ r e a d
.global g_dfmtou
.global g_opcls
.global g_rndpr
.global get_fline
.global reg_dest
|
| Final r e s u l t t a b l e f o r o v f _ r e s . N o t e t h a t t h e n e g a t i v e c o u n t e r p a r t s
| are u n n e c e s s a r y a s o v f _ r e s a l w a y s r e t u r n s t h e s i g n s e p a r a t e l y f r o m
| the e x p o n e n t .
| ;+inf
EXT_PINF : .long 0x7fff0000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;largest +ext
EXT_PLRG : .long 0x7ffe0000 , 0 xffffffff,0 x f f f f f f f f ,0 x00 0 0 0 0 0 0
| ;largest magnitude +sgl in ext
SGL_PLRG : .long 0x407e0000 , 0 xffffff0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;largest magnitude +dbl in ext
DBL_PLRG : .long 0x43fe0000 , 0 xffffffff,0 x f f f f f80 0 ,0 x00 0 0 0 0 0 0
| ;largest -ext
tblovfl :
.long EXT_RN
.long EXT_RZ
.long EXT_RM
.long EXT_RP
.long SGL_RN
.long SGL_RZ
.long SGL_RM
.long SGL_RP
.long DBL_RN
.long DBL_RZ
.long DBL_RM
.long DBL_RP
.long error
.long error
.long error
.long error
|
| ovf_ r _ k - - - o v e r f l o w r e s u l t c a l c u l a t i o n
|
| This e n t r y p o i n t i s u s e d b y k e r n e l _ e x .
|
| This f o r c e s t h e d e s t i n a t i o n p r e c i s i o n t o b e e x t e n d e d
|
| Input : operand i n E T E M P
| Output : a r e s u l t i s i n E T E M P ( i n t e r n a l e x t e n d e d f o r m a t )
|
.global ovf_r_k
ovf_r_k :
lea E T E M P ( % a6 ) ,% a0 | a0 p o i n t s t o s o u r c e o p e r a n d
bclrb #s i g n _ b i t , E T E M P _ E X ( % a 6 )
sne E T E M P _ S G N ( % a6 ) | c o n v e r t t o i n t e r n a l I E E E f o r m a t
|
| ovf_ r _ x2 - - - o v e r f l o w r e s u l t c a l c u l a t i o n
|
| This e n t r y p o i n t u s e d b y x _ o v f l . ( o p c l a s s 0 a n d 2 )
|
| Input a0 p o i n t s t o a n o p e r a n d i n t h e i n t e r n a l e x t e n d e d f o r m a t
| Output a0 p o i n t s t o t h e r e s u l t i n t h e i n t e r n a l e x t e n d e d f o r m a t
|
| This s e t s t h e r o u n d p r e c i s i o n a c c o r d i n g t o t h e u s e r ' s F P C R u n l e s s t h e
| instruction i s f s g l d i v o r f s g l m u l o r f s a d d , f d a d d , f s u b , f d s u b , f s m u l ,
| fdmul, f s d i v , f d d i v , f s s q r t , f s m o v e , f d m o v e , f s a b s , f d a b s , f s n e g , f d n e g .
| If t h e i n s t r u c t i o n i s f s g l d i v o f f s g l m u l , t h e r o u n d i n g p r e c i s i o n m u s t b e
| extended. I f t h e i n s t r u c t i o n i s n o t f s g l d i v o r f s g l m u l b u t a f o r c e -
| precision i n s t r u c t i o n , t h e r o u n d i n g p r e c i s i o n i s t h e n s e t t o t h e f o r c e
| precision.
.global ovf_r_x2
ovf_r_x2 :
btstb #E 3 ,E _ B Y T E ( % a6 ) | c h e c k f o r n u e x c e p t i o n
beql o v f _ e 1 _ e x c | i t i s c u e x c e p t i o n
ovf_e3_exc :
movew C M D R E G 3 B ( % a6 ) ,% d0 | g e t t h e c o m m a n d w o r d
andiw #0x00000060 ,% d0 | c l e a r a l l b i t s e x c e p t 6 a n d 5
cmpil #0x00000040 ,% d0
beql o v f f _ s g l | f o r c e p r e c i s i o n i s s i n g l e
cmpil #0x00000060 ,% d0
beql o v f f _ d b l | f o r c e p r e c i s i o n i s d o u b l e
movew C M D R E G 3 B ( % a6 ) ,% d0 | g e t t h e c o m m a n d w o r d a g a i n
andil #0x7f ,% d0 | c l e a r a l l e x c e p t o p e r a t i o n
cmpil #0x33 ,% d0
beql o v f _ f s g l | f s g l m u l o r f s g l d i v
cmpil #0x30 ,% d0
beql o v f _ f s g l
bra o v f _ f p c r | i n s t r u c t i o n i s n o n e o f t h e a b o v e
| ;use FPCR
ovf_e1_exc :
movew C M D R E G 1 B ( % a6 ) ,% d0 | g e t c o m m a n d w o r d
andil #0x00000044 ,% d0 | c l e a r a l l b i t s e x c e p t 6 a n d 2
cmpil #0x00000040 ,% d0
beql o v f f _ s g l | t h e i n s t r u c t i o n i s f o r c e s i n g l e
cmpil #0x00000044 ,% d0
beql o v f f _ d b l | t h e i n s t r u c t i o n i s f o r c e d o u b l e
movew C M D R E G 1 B ( % a6 ) ,% d0 | a g a i n g e t t h e c o m m a n d w o r d
andil #0x0000007f ,% d0 | c l e a r a l l e x c e p t t h e o p c o d e
cmpil #0x00000027 ,% d0
beql o v f _ f s g l | f s g l m u l
cmpil #0x00000024 ,% d0
beql o v f _ f s g l | f s g l d i v
bra o v f _ f p c r | n o n e o f t h e a b o v e , u s e F P C R
|
|
| Inst i s e i t h e r f s g l d i v o r f s g l m u l . F o r c e e x t e n d e d p r e c i s i o n .
|
ovf_fsgl :
clrl % d0
bra o v f _ r e s
ovff_sgl :
movel #0x00000001 ,% d0 | s e t s i n g l e
bra o v f _ r e s
ovff_dbl :
movel #0x00000002 ,% d0 | s e t d o u b l e
bra o v f _ r e s
|
| The p r e c i s i o n i s i n t h e f p c r .
|
ovf_fpcr :
bfextu F P C R _ M O D E ( % a6 ) { #0 : #2 } ,% d0 | s e t r o u n d p r e c i s i o n
bra o v f _ r e s
|
|
| ovf_ r _ x3 - - - o v e r f l o w r e s u l t c a l c u l a t i o n
|
| This e n t r y p o i n t u s e d b y x _ o v f l . ( o p c l a s s 3 o n l y )
|
| Input a0 p o i n t s t o a n o p e r a n d i n t h e i n t e r n a l e x t e n d e d f o r m a t
| Output a0 p o i n t s t o t h e r e s u l t i n t h e i n t e r n a l e x t e n d e d f o r m a t
|
| This s e t s t h e r o u n d p r e c i s i o n a c c o r d i n g t o t h e d e s t i n a t i o n s i z e .
|
.global ovf_r_x3
ovf_r_x3 :
bsr g _ d f m t o u | g e t d e s t f m t i n d0 { 1 : 0 }
| ;for fmovout, the destination format
| ;is the rounding precision
|
| ovf_ r e s - - - o v e r f l o w r e s u l t c a l c u l a t i o n
|
| Input :
| a0 p o i n t s t o o p e r a n d i n i n t e r n a l e x t e n d e d f o r m a t
| Output :
| a0 p o i n t s t o r e s u l t i n i n t e r n a l e x t e n d e d f o r m a t
|
.global ovf_res
ovf_res :
lsll #2 ,% d0 | m o v e r o u n d p r e c i s i o n t o d0 { 3 : 2 }
bfextu F P C R _ M O D E ( % a6 ) { #2 : #2 } ,% d1 | s e t r o u n d m o d e
orl % d1 ,% d0 | i n d e x i s f m t : m o d e i n d0 { 3 : 0 }
leal t b l o v f l ,% a1 | l o a d a1 w i t h t a b l e a d d r e s s
movel % a1 @(%d0:l:4),%a1 |use d0 as index to the table
jmp ( % a1 ) | g o t o t h e c o r r e c t r o u t i n e
|
| case D E S T _ F M T = E X T
|
EXT_RN :
leal E X T _ P I N F ,% a1 | a n s w e r i s + / - i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bra s e t _ s i g n | n o w g o s e t t h e s i g n
EXT_RZ :
leal E X T _ P L R G ,% a1 | a n s w e r i s + / - l a r g e n u m b e r
bra s e t _ s i g n | n o w g o s e t t h e s i g n
EXT_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs e _ r m _ p o s
e_rm_neg :
leal E X T _ P I N F ,% a1 | a n s w e r i s n e g a t i v e i n f i n i t y
orl #n e g i n f _ m a s k , U S E R _ F P S R ( % a 6 )
bra e n d _ o v f r
e_rm_pos :
leal E X T _ P L R G ,% a1 | a n s w e r i s l a r g e p o s i t i v e n u m b e r
bra e n d _ o v f r
EXT_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs e _ r p _ p o s
e_rp_neg :
leal E X T _ P L R G ,% a1 | a n s w e r i s l a r g e n e g a t i v e n u m b e r
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ o v f r
e_rp_pos :
leal E X T _ P I N F ,% a1 | a n s w e r i s p o s i t i v e i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ o v f r
|
| case D E S T _ F M T = D B L
|
DBL_RN :
leal E X T _ P I N F ,% a1 | a n s w e r i s + / - i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bra s e t _ s i g n
DBL_RZ :
leal D B L _ P L R G ,% a1 | a n s w e r i s + / - l a r g e n u m b e r
bra s e t _ s i g n | n o w g o s e t t h e s i g n
DBL_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs d _ r m _ p o s
d_rm_neg :
leal E X T _ P I N F ,% a1 | a n s w e r i s n e g a t i v e i n f i n i t y
orl #n e g i n f _ m a s k , U S E R _ F P S R ( % a 6 )
bra e n d _ o v f r | i n f i s s a m e f o r a l l p r e c i s i o n s ( e x t ,d b l ,s g l )
d_rm_pos :
leal D B L _ P L R G ,% a1 | a n s w e r i s l a r g e p o s i t i v e n u m b e r
bra e n d _ o v f r
DBL_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs d _ r p _ p o s
d_rp_neg :
leal D B L _ P L R G ,% a1 | a n s w e r i s l a r g e n e g a t i v e n u m b e r
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ o v f r
d_rp_pos :
leal E X T _ P I N F ,% a1 | a n s w e r i s p o s i t i v e i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ o v f r
|
| case D E S T _ F M T = S G L
|
SGL_RN :
leal E X T _ P I N F ,% a1 | a n s w e r i s + / - i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bras s e t _ s i g n
SGL_RZ :
leal S G L _ P L R G ,% a1 | a n s w e r i s + / - l a r g e n u m b e r
bras s e t _ s i g n
SGL_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs s _ r m _ p o s
s_rm_neg :
leal E X T _ P I N F ,% a1 | a n s w e r i s n e g a t i v e i n f i n i t y
orl #n e g i n f _ m a s k , U S E R _ F P S R ( % a 6 )
bras e n d _ o v f r
s_rm_pos :
leal S G L _ P L R G ,% a1 | a n s w e r i s l a r g e p o s i t i v e n u m b e r
bras e n d _ o v f r
SGL_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs s _ r p _ p o s
s_rp_neg :
leal S G L _ P L R G ,% a1 | a n s w e r i s l a r g e n e g a t i v e n u m b e r
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bras e n d _ o v f r
s_rp_pos :
leal E X T _ P I N F ,% a1 | a n s w e r i s p o s i t i v e i n f i n i t y
bsetb #i n f _ b i t , F P S R _ C C ( % a 6 )
bras e n d _ o v f r
set_sign :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs e n d _ o v f r
neg_sign :
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
end_ovfr :
movew L O C A L _ E X ( % a1 ) ,L O C A L _ E X ( % a0 ) | d o n o t o v e r w r i t e s i g n
movel L O C A L _ H I ( % a1 ) ,L O C A L _ H I ( % a0 )
movel L O C A L _ L O ( % a1 ) ,L O C A L _ L O ( % a0 )
rts
|
| ERROR
|
error :
rts
|
| get_ f l i n e - - - g e t f - l i n e o p c o d e o f i n t e r r u p t e d i n s t r u c t i o n
|
| Returns o p c o d e i n t h e l o w w o r d o f d0 .
|
get_fline :
movel U S E R _ F P I A R ( % a6 ) ,% a0 | o p c o d e a d d r e s s
movel #0 ,- ( % a7 ) | r e s e r v e a w o r d o n t h e s t a c k
leal 2 ( % a7 ) ,% a1 | p o i n t t o l o w w o r d o f t e m p o r a r y
movel #2 ,% d0 | c o u n t
bsrl m e m _ r e a d
movel ( % a7 ) + ,% d0
rts
|
| g_ r n d p r - - - p u t r o u n d i n g p r e c i s i o n i n d0 { 1 : 0 }
|
| valid r e t u r n c o d e s a r e :
| 0 0 - extended
| 0 1 - single
| 1 0 - double
|
| begin
| get r o u n d i n g p r e c i s i o n ( c m d r e g 3 b { 6 : 5 } )
| begin
| case o p c l a s s = 0 1 1 ( m o v e o u t )
| get d e s t i n a t i o n f o r m a t - t h i s i s t h e a l s o t h e r o u n d i n g p r e c i s i o n
|
| case o p c l a s s = 0 x0
| if E 3
| * case R n d P r ( f r o m c m d r e g 3 b { 6 : 5 } = 1 1 t h e n R N D _ P R E C = D B L
| * case R n d P r ( f r o m c m d r e g 3 b { 6 : 5 } = 1 0 t h e n R N D _ P R E C = S G L
| case R n d P r ( f r o m c m d r e g 3 b { 6 : 5 } = 0 0 | 0 1
| use p r e c i s i o n f r o m F P C R { 7 : 6 }
| case 0 0 t h e n R N D _ P R E C = E X T
| case 0 1 t h e n R N D _ P R E C = S G L
| case 1 0 t h e n R N D _ P R E C = D B L
| else E 1
| use p r e c i s i o n i n F P C R { 7 : 6 }
| case 0 0 t h e n R N D _ P R E C = E X T
| case 0 1 t h e n R N D _ P R E C = S G L
| case 1 0 t h e n R N D _ P R E C = D B L
| end
|
g_rndpr :
bsr g _ o p c l s | g e t o p c l a s s i n d0 { 2 : 0 }
cmpw #0x0003 ,% d0 | c h e c k f o r o p c l a s s 0 1 1
bnes o p _ 0 x0
|
| For m o v e o u t i n s t r u c t i o n s ( o p c l a s s 0 1 1 ) t h e d e s t i n a t i o n f o r m a t
| is t h e s a m e a s t h e r o u n d i n g p r e c i s i o n . P a s s r e s u l t s f r o m g _ d f m t o u .
|
bsr g _ d f m t o u
rts
op_0x0 :
btstb #E 3 ,E _ B Y T E ( % a6 )
beql u n f _ e 1 _ e x c | b r a n c h t o e 1 u n d e r f l o w
unf_e3_exc :
movel C M D R E G 3 B ( % a6 ) ,% d0 | r o u n d i n g p r e c i s i o n i n d0 { 1 0 : 9 }
bfextu % d0 { #9 : #2 } ,% d0 | m o v e t h e r o u n d i n g p r e c b i t s t o d0 { 1 : 0 }
cmpil #0x2 ,% d0
beql u n f f _ s g l | f o r c e p r e c i s i o n i s s i n g l e
cmpil #0x3 ,% d0 | f o r c e p r e c i s i o n i s d o u b l e
beql u n f f _ d b l
movew C M D R E G 3 B ( % a6 ) ,% d0 | g e t t h e c o m m a n d w o r d a g a i n
andil #0x7f ,% d0 | c l e a r a l l e x c e p t o p e r a t i o n
cmpil #0x33 ,% d0
beql u n f _ f s g l | f s g l m u l o r f s g l d i v
cmpil #0x30 ,% d0
beql u n f _ f s g l | f s g l d i v o r f s g l m u l
bra u n f _ f p c r
unf_e1_exc :
movel C M D R E G 1 B ( % a6 ) ,% d0 | g e t 3 2 b i t s o f f t h e s t a c k , 1 s t 1 6 b i t s
| ;are the command word
andil #0x00440000 ,% d0 | c l e a r a l l b i t s e x c e p t b i t s 6 a n d 2
cmpil #0x00400000 ,% d0
beql u n f f _ s g l | f o r c e s i n g l e
cmpil #0x00440000 ,% d0 | f o r c e d o u b l e
beql u n f f _ d b l
movel C M D R E G 1 B ( % a6 ) ,% d0 | g e t t h e c o m m a n d w o r d a g a i n
andil #0x007f0000 ,% d0 | c l e a r a l l b i t s e x c e p t t h e o p e r a t i o n
cmpil #0x00270000 ,% d0
beql u n f _ f s g l | f s g l m u l
cmpil #0x00240000 ,% d0
beql u n f _ f s g l | f s g l d i v
bra u n f _ f p c r
|
| Convert t o r e t u r n f o r m a t . T h e v a l u e s f r o m c m d r e g 3 b a n d t h e r e t u r n
| values a r e :
| cmdreg3 b r e t u r n p r e c i s i o n
| - - - - - - - - - - - - - - - - - - - - - - -
| 0 0 , 0 1 0 ext
| 1 0 1 sgl
| 1 1 2 dbl
| Force s i n g l e
|
unff_sgl :
movel #1 ,% d0 | r e t u r n 1
rts
|
| Force d o u b l e
|
unff_dbl :
movel #2 ,% d0 | r e t u r n 2
rts
|
| Force e x t e n d e d
|
unf_fsgl :
movel #0 ,% d0
rts
|
| Get r o u n d i n g p r e c i s i o n s e t i n F P C R { 7 : 6 } .
|
unf_fpcr :
movel U S E R _ F P C R ( % a6 ) ,% d0 | r o u n d i n g p r e c i s i o n b i t s i n d0 { 7 : 6 }
bfextu % d0 { #24 : #2 } ,% d0 | m o v e t h e r o u n d i n g p r e c b i t s t o d0 { 1 : 0 }
rts
|
| g_ o p c l s - - - p u t o p c l a s s i n d0 { 2 : 0 }
|
g_opcls :
btstb #E 3 ,E _ B Y T E ( % a6 )
beqs o p c _ 1 b | i f s e t , g o t o c m d r e g 1 b
opc_3b :
clrl % d0 | i f E 3 , o n l y o p c l a s s 0 x0 i s p o s s i b l e
rts
opc_1b :
movel C M D R E G 1 B ( % a6 ) ,% d0
bfextu % d0 { #0 : #3 } ,% d0 | s h i f t o p c l a s s b i t s d0 { 3 1 : 2 9 } t o d0 { 2 : 0 }
rts
|
| g_ d f m t o u - - - p u t d e s t i n a t i o n f o r m a t i n d0 { 1 : 0 }
|
| If E 1 , t h e f o r m a t i s f r o m c m d r e g 1 b { 1 2 : 1 0 }
| If E 3 , t h e f o r m a t i s e x t e n d e d .
|
| Dest. F m t .
| extended 0 1 0 - > 0 0
| single 0 0 1 - > 0 1
| double 1 0 1 - > 1 0
|
g_dfmtou :
btstb #E 3 ,E _ B Y T E ( % a6 )
beqs o p01 1
clrl % d0 | i f E 1 , s i z e i s a l w a y s e x t
rts
op011 :
movel C M D R E G 1 B ( % a6 ) ,% d0
bfextu % d0 { #3 : #3 } ,% d0 | d e s t f m t f r o m c m d r e g 1 b { 1 2 : 1 0 }
cmpb #1 ,% d0 | c h e c k f o r s i n g l e
bnes n o t _ s g l
movel #1 ,% d0
rts
not_sgl :
cmpb #5 ,% d0 | c h e c k f o r d o u b l e
bnes n o t _ d b l
movel #2 ,% d0
rts
not_dbl :
clrl % d0 | m u s t b e e x t e n d e d
rts
|
|
| Final r e s u l t t a b l e f o r u n f _ s u b . N o t e t h a t t h e n e g a t i v e c o u n t e r p a r t s
| are u n n e c e s s a r y a s u n f _ s u b a l w a y s r e t u r n s t h e s i g n s e p a r a t e l y f r o m
| the e x p o n e n t .
| ;+zero
EXT_PZRO : .long 0x00000000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;+zero
SGL_PZRO : .long 0x3f810000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;+zero
DBL_PZRO : .long 0x3c010000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;smallest +ext denorm
EXT_PSML : .long 0x00000000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 1 ,0 x00 0 0 0 0 0 0
| ;smallest +sgl denorm
SGL_PSML : .long 0x3f810000 , 0 x0 0 0 0 0 1 0 0 ,0 x00 0 0 0 0 0 0 ,0 x00 0 0 0 0 0 0
| ;smallest +dbl denorm
DBL_PSML : .long 0x3c010000 , 0 x0 0 0 0 0 0 0 0 ,0 x00 0 0 0 8 0 0 ,0 x00 0 0 0 0 0 0
|
| UNF_ S U B - - - u n d e r f l o w r e s u l t c a l c u l a t i o n
|
| Input :
| d0 c o n t a i n s r o u n d p r e c i s i o n
| a0 p o i n t s t o i n p u t o p e r a n d i n t h e i n t e r n a l e x t e n d e d f o r m a t
|
| Output :
| a0 p o i n t s t o c o r r e c t i n t e r n a l e x t e n d e d p r e c i s i o n r e s u l t .
|
tblunf :
.long uEXT_RN
.long uEXT_RZ
.long uEXT_RM
.long uEXT_RP
.long uSGL_RN
.long uSGL_RZ
.long uSGL_RM
.long uSGL_RP
.long uDBL_RN
.long uDBL_RZ
.long uDBL_RM
.long uDBL_RP
.long uDBL_RN
.long uDBL_RZ
.long uDBL_RM
.long uDBL_RP
.global unf_sub
unf_sub :
lsll #2 ,% d0 | m o v e r o u n d p r e c i s i o n t o d0 { 3 : 2 }
bfextu F P C R _ M O D E ( % a6 ) { #2 : #2 } ,% d1 | s e t r o u n d m o d e
orl % d1 ,% d0 | i n d e x i s f m t : m o d e i n d0 { 3 : 0 }
leal t b l u n f ,% a1 | l o a d a1 w i t h t a b l e a d d r e s s
movel % a1 @(%d0:l:4),%a1 |use d0 as index to the table
jmp ( % a1 ) | g o t o t h e c o r r e c t r o u t i n e
|
| case D E S T _ F M T = E X T
|
uEXT_RN :
leal E X T _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra u s e t _ s i g n | n o w g o s e t t h e s i g n
uEXT_RZ :
leal E X T _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra u s e t _ s i g n | n o w g o s e t t h e s i g n
uEXT_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e u n d e r f l o w
beqs u e _ r m _ p o s
ue_rm_neg :
leal E X T _ P S M L ,% a1 | a n s w e r i s n e g a t i v e s m a l l e s t d e n o r m
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ u n f r
ue_rm_pos :
leal E X T _ P Z R O ,% a1 | a n s w e r i s p o s i t i v e z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ u n f r
uEXT_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e u n d e r f l o w
beqs u e _ r p _ p o s
ue_rp_neg :
leal E X T _ P Z R O ,% a1 | a n s w e r i s n e g a t i v e z e r o
oril #n e g z _ m a s k , U S E R _ F P S R ( % a 6 )
bra e n d _ u n f r
ue_rp_pos :
leal E X T _ P S M L ,% a1 | a n s w e r i s p o s i t i v e s m a l l e s t d e n o r m
bra e n d _ u n f r
|
| case D E S T _ F M T = D B L
|
uDBL_RN :
leal D B L _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra u s e t _ s i g n
uDBL_RZ :
leal D B L _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra u s e t _ s i g n | n o w g o s e t t h e s i g n
uDBL_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs u d _ r m _ p o s
ud_rm_neg :
leal D B L _ P S M L ,% a1 | a n s w e r i s s m a l l e s t d e n o r m a l i z e d n e g a t i v e
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ u n f r
ud_rm_pos :
leal D B L _ P Z R O ,% a1 | a n s w e r i s p o s i t i v e z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bra e n d _ u n f r
uDBL_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs u d _ r p _ p o s
ud_rp_neg :
leal D B L _ P Z R O ,% a1 | a n s w e r i s n e g a t i v e z e r o
oril #n e g z _ m a s k , U S E R _ F P S R ( % a 6 )
bra e n d _ u n f r
ud_rp_pos :
leal D B L _ P S M L ,% a1 | a n s w e r i s s m a l l e s t d e n o r m a l i z e d n e g a t i v e
bra e n d _ u n f r
|
| case D E S T _ F M T = S G L
|
uSGL_RN :
leal S G L _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bras u s e t _ s i g n
uSGL_RZ :
leal S G L _ P Z R O ,% a1 | a n s w e r i s + / - z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bras u s e t _ s i g n
uSGL_RM :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs u s _ r m _ p o s
us_rm_neg :
leal S G L _ P S M L ,% a1 | a n s w e r i s s m a l l e s t d e n o r m a l i z e d n e g a t i v e
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
bras e n d _ u n f r
us_rm_pos :
leal S G L _ P Z R O ,% a1 | a n s w e r i s p o s i t i v e z e r o
bsetb #z _ b i t , F P S R _ C C ( % a 6 )
bras e n d _ u n f r
uSGL_RP :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs u s _ r p _ p o s
us_rp_neg :
leal S G L _ P Z R O ,% a1 | a n s w e r i s n e g a t i v e z e r o
oril #n e g z _ m a s k , U S E R _ F P S R ( % a 6 )
bras e n d _ u n f r
us_rp_pos :
leal S G L _ P S M L ,% a1 | a n s w e r i s s m a l l e s t d e n o r m a l i z e d p o s i t i v e
bras e n d _ u n f r
uset_sign :
tstb L O C A L _ S G N ( % a0 ) | i f n e g a t i v e o v e r f l o w
beqs e n d _ u n f r
uneg_sign :
bsetb #n e g _ b i t , F P S R _ C C ( % a 6 )
end_unfr :
movew L O C A L _ E X ( % a1 ) ,L O C A L _ E X ( % a0 ) | b e c a r e f u l n o t t o o v e r w r i t e s i g n
movel L O C A L _ H I ( % a1 ) ,L O C A L _ H I ( % a0 )
movel L O C A L _ L O ( % a1 ) ,L O C A L _ L O ( % a0 )
rts
|
| reg_ d e s t - - - w r i t e b y t e , w o r d , o r l o n g d a t a t o D n
|
|
| Input :
| L_SCR1 : Data
| d1 : data s i z e a n d d e s t r e g i s t e r n u m b e r f o r m a t t e d a s :
|
| 3 2 5 4 3 2 1 0
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| | 0 | Size | D e s t R e g # |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| Size i s :
| 0 - Byte
| 1 - Word
| 2 - Long/ S i n g l e
|
pregdst :
.long byte_d0
.long byte_d1
.long byte_d2
.long byte_d3
.long byte_d4
.long byte_d5
.long byte_d6
.long byte_d7
.long word_d0
.long word_d1
.long word_d2
.long word_d3
.long word_d4
.long word_d5
.long word_d6
.long word_d7
.long long_d0
.long long_d1
.long long_d2
.long long_d3
.long long_d4
.long long_d5
.long long_d6
.long long_d7
reg_dest :
leal p r e g d s t ,% a0
movel % a0 @(%d1:l:4),%a0
jmp ( % a0 )
byte_d0 :
moveb L _ S C R 1 ( % a6 ) ,U S E R _ D 0 + 3 ( % a6 )
rts
byte_d1 :
moveb L _ S C R 1 ( % a6 ) ,U S E R _ D 1 + 3 ( % a6 )
rts
byte_d2 :
moveb L _ S C R 1 ( % a6 ) ,% d2
rts
byte_d3 :
moveb L _ S C R 1 ( % a6 ) ,% d3
rts
byte_d4 :
moveb L _ S C R 1 ( % a6 ) ,% d4
rts
byte_d5 :
moveb L _ S C R 1 ( % a6 ) ,% d5
rts
byte_d6 :
moveb L _ S C R 1 ( % a6 ) ,% d6
rts
byte_d7 :
moveb L _ S C R 1 ( % a6 ) ,% d7
rts
word_d0 :
movew L _ S C R 1 ( % a6 ) ,U S E R _ D 0 + 2 ( % a6 )
rts
word_d1 :
movew L _ S C R 1 ( % a6 ) ,U S E R _ D 1 + 2 ( % a6 )
rts
word_d2 :
movew L _ S C R 1 ( % a6 ) ,% d2
rts
word_d3 :
movew L _ S C R 1 ( % a6 ) ,% d3
rts
word_d4 :
movew L _ S C R 1 ( % a6 ) ,% d4
rts
word_d5 :
movew L _ S C R 1 ( % a6 ) ,% d5
rts
word_d6 :
movew L _ S C R 1 ( % a6 ) ,% d6
rts
word_d7 :
movew L _ S C R 1 ( % a6 ) ,% d7
rts
long_d0 :
movel L _ S C R 1 ( % a6 ) ,U S E R _ D 0 ( % a6 )
rts
long_d1 :
movel L _ S C R 1 ( % a6 ) ,U S E R _ D 1 ( % a6 )
rts
long_d2 :
movel L _ S C R 1 ( % a6 ) ,% d2
rts
long_d3 :
movel L _ S C R 1 ( % a6 ) ,% d3
rts
long_d4 :
movel L _ S C R 1 ( % a6 ) ,% d4
rts
long_d5 :
movel L _ S C R 1 ( % a6 ) ,% d5
rts
long_d6 :
movel L _ S C R 1 ( % a6 ) ,% d6
rts
long_d7 :
movel L _ S C R 1 ( % a6 ) ,% d7
rts
| end