2005-04-16 15:20:36 -07:00
/ * libgcc1 r o u t i n e s f o r 6 8 0 0 0 w / o f l o a t i n g - p o i n t h a r d w a r e .
Copyright ( C ) 1 9 9 4 , 1 9 9 6 , 1 9 9 7 , 1 9 9 8 F r e e S o f t w a r e F o u n d a t i o n , I n c .
This f i l e i s p a r t o f G N U C C .
GNU C C i s f r e e s o f t w a r e ; you can redistribute it and/or modify it
under t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e a s p u b l i s h e d b y t h e
Free S o f t w a r e F o u n d a t i o n ; either version 2, or (at your option) any
later v e r s i o n .
In a d d i t i o n t o t h e p e r m i s s i o n s i n t h e G N U G e n e r a l P u b l i c L i c e n s e , t h e
Free S o f t w a r e F o u n d a t i o n g i v e s y o u u n l i m i t e d p e r m i s s i o n t o l i n k t h e
compiled v e r s i o n o f t h i s f i l e w i t h o t h e r p r o g r a m s , a n d t o d i s t r i b u t e
those p r o g r a m s w i t h o u t a n y r e s t r i c t i o n c o m i n g f r o m t h e u s e o f t h i s
file. ( T h e G e n e r a l P u b l i c L i c e n s e r e s t r i c t i o n s d o a p p l y i n o t h e r
respects; for example, they cover modification of the file, and
distribution w h e n n o t l i n k e d i n t o a n o t h e r p r o g r a m . )
This f i l e i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l , b u t
WITHOUT A N Y W A R R A N T Y ; without even the implied warranty of
MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e G N U
2014-11-08 19:19:07 +01:00
General P u b l i c L i c e n s e f o r m o r e d e t a i l s . * /
2005-04-16 15:20:36 -07:00
/ * As a s p e c i a l e x c e p t i o n , i f y o u l i n k t h i s l i b r a r y w i t h f i l e s
compiled w i t h G C C t o p r o d u c e a n e x e c u t a b l e , t h i s d o e s n o t c a u s e
the r e s u l t i n g e x e c u t a b l e t o b e c o v e r e d b y t h e G N U G e n e r a l P u b l i c L i c e n s e .
This e x c e p t i o n d o e s n o t h o w e v e r i n v a l i d a t e a n y o t h e r r e a s o n s w h y
the e x e c u t a b l e f i l e m i g h t b e c o v e r e d b y t h e G N U G e n e r a l P u b l i c L i c e n s e . * /
/ * Use t h i s o n e f o r a n y 6 8 0 x0 ; assumes no floating point hardware.
The t r a i l i n g " ' " a p p e a r i n g o n s o m e l i n e s i s f o r A N S I p r e p r o c e s s o r s . Y u k .
Some o f t h i s c o d e c o m e s f r o m M I N I X , v i a t h e f o l k s a t e r i c s s o n .
D. V . H e n k e l - W a l l a c e ( g u m b y @cygnus.com) Fete Bastille, 1992
* /
/* These are predefined by new versions of GNU cpp. */
# ifndef _ _ U S E R _ L A B E L _ P R E F I X _ _
# define _ _ U S E R _ L A B E L _ P R E F I X _ _ _
# endif
# ifndef _ _ R E G I S T E R _ P R E F I X _ _
# define _ _ R E G I S T E R _ P R E F I X _ _
# endif
# ifndef _ _ I M M E D I A T E _ P R E F I X _ _
# define _ _ I M M E D I A T E _ P R E F I X _ _ #
# endif
/* ANSI concatenation macros. */
# define C O N C A T 1 ( a , b ) C O N C A T 2 ( a , b )
# define C O N C A T 2 ( a , b ) a ## b
/* Use the right prefix for global labels. */
# define S Y M ( x ) C O N C A T 1 ( _ _ U S E R _ L A B E L _ P R E F I X _ _ , x )
/* Use the right prefix for registers. */
# define R E G ( x ) C O N C A T 1 ( _ _ R E G I S T E R _ P R E F I X _ _ , x )
/* Use the right prefix for immediate values. */
# define I M M ( x ) C O N C A T 1 ( _ _ I M M E D I A T E _ P R E F I X _ _ , x )
# define d0 R E G ( d0 )
# define d1 R E G ( d1 )
# define d2 R E G ( d2 )
# define d3 R E G ( d3 )
# define d4 R E G ( d4 )
# define d5 R E G ( d5 )
# define d6 R E G ( d6 )
# define d7 R E G ( d7 )
# define a0 R E G ( a0 )
# define a1 R E G ( a1 )
# define a2 R E G ( a2 )
# define a3 R E G ( a3 )
# define a4 R E G ( a4 )
# define a5 R E G ( a5 )
# define a6 R E G ( a6 )
# define f p R E G ( f p )
# define s p R E G ( s p )
.text
.proc
.globl SYM ( _ _ udivsi3 )
SYM ( _ _ u d i v s i 3 ) :
# if ! ( d e f i n e d ( _ _ m c f52 0 0 _ _ ) | | d e f i n e d ( _ _ m c o l d f i r e _ _ ) )
movel d2 , s p @-
movel s p @(12), d1 /* d1 = divisor */
movel s p @(8), d0 /* d0 = dividend */
cmpl I M M ( 0 x10 0 0 0 ) , d1 / * d i v i s o r > = 2 ^ 1 6 ? * /
jcc L 3 / * t h e n t r y n e x t a l g o r i t h m * /
movel d0 , d2
clrw d2
swap d2
divu d1 , d2 / * h i g h q u o t i e n t i n l o w e r w o r d * /
movew d2 , d0 / * s a v e h i g h q u o t i e n t * /
swap d0
movew s p @(10), d2 /* get low dividend + high rest */
divu d1 , d2 / * l o w q u o t i e n t * /
movew d2 , d0
jra L 6
L3 : movel d1 , d2 / * u s e d2 a s d i v i s o r b a c k u p * /
L4 : lsrl I M M ( 1 ) , d1 / * s h i f t d i v i s o r * /
lsrl I M M ( 1 ) , d0 / * s h i f t d i v i d e n d * /
cmpl I M M ( 0 x10 0 0 0 ) , d1 / * s t i l l d i v i s o r > = 2 ^ 1 6 ? * /
jcc L 4
divu d1 , d0 / * n o w w e h a v e 1 6 b i t d i v i s o r * /
andl I M M ( 0 x f f f f ) , d0 / * m a s k o u t d i v i s o r , i g n o r e r e m a i n d e r * /
/ * Multiply t h e 1 6 b i t t e n t a t i v e q u o t i e n t w i t h t h e 3 2 b i t d i v i s o r . B e c a u s e o f
the o p e r a n d r a n g e s , t h i s m i g h t g i v e a 3 3 b i t p r o d u c t . I f t h i s p r o d u c t i s
greater t h a n t h e d i v i d e n d , t h e t e n t a t i v e q u o t i e n t w a s t o o l a r g e . * /
movel d2 , d1
mulu d0 , d1 / * l o w p a r t , 3 2 b i t s * /
swap d2
mulu d0 , d2 / * h i g h p a r t , a t m o s t 1 7 b i t s * /
swap d2 / * a l i g n h i g h p a r t w i t h l o w p a r t * /
tstw d2 / * h i g h p a r t 1 7 b i t s ? * /
jne L 5 / * i f 1 7 b i t s , q u o t i e n t w a s t o o l a r g e * /
addl d2 , d1 / * a d d p a r t s * /
jcs L 5 / * i f s u m i s 3 3 b i t s , q u o t i e n t w a s t o o l a r g e * /
cmpl s p @(8), d1 /* compare the sum with the dividend */
jls L 6 / * i f s u m > d i v i d e n d , q u o t i e n t w a s t o o l a r g e * /
L5 : subql I M M ( 1 ) , d0 / * a d j u s t q u o t i e n t * /
L6 : movel s p @+, d2
rts
# else / * _ _ m c f52 0 0 _ _ | | _ _ m c o l d f i r e _ _ * /
/ * Coldfire i m p l e m e n t a t i o n o f n o n - r e s t o r i n g d i v i s i o n a l g o r i t h m f r o m
Hennessy & P a t t e r s o n , A p p e n d i x A . * /
link a6 ,I M M ( - 1 2 )
moveml d2 - d4 ,s p @
movel a6 @(8),d0
movel a6 @(12),d1
clrl d2 | c l e a r p
moveq I M M ( 3 1 ) ,d4
L1 : addl d0 ,d0 | s h i f t r e g p a i r ( p ,a ) o n e b i t l e f t
addxl d2 ,d2
movl d2 ,d3 | s u b t r a c t b f r o m p , s t o r e i n t m p .
subl d1 ,d3
jcs L 2 | i f n o c a r r y ,
bset I M M ( 0 ) ,d0 | s e t t h e l o w o r d e r b i t o f a t o 1 ,
movl d3 ,d2 | a n d s t o r e t m p i n p .
L2 : subql I M M ( 1 ) ,d4
jcc L 1
moveml s p @,d2-d4 | restore data registers
unlk a6 | a n d r e t u r n
rts
# endif / * _ _ m c f52 0 0 _ _ | | _ _ m c o l d f i r e _ _ * /