2008-11-18 11:33:48 +03:00
/ * Copyright ( C ) 2 0 0 6 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 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 i n t o c o m b i n a t i o n s w i t h o t h e r p r o g r a m s ,
and t o d i s t r i b u t e t h o s e c o m b i n a t i o n 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
from t h e u s e o f t h i s f i l e . ( 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
do a p p l y i n o t h e r r e s p e c t s ; for example, they cover modification of
the f i l e , a n d d i s t r i b u t i o n w h e n n o t l i n k e d i n t o a c o m b i n e
executable. )
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
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 .
You s h o u l d h a v e r e c e i v e d a c o p y 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
along w i t h t h i s p r o g r a m ; see the file COPYING. If not, write to
the F r e e S o f t w a r e F o u n d a t i o n , 5 1 F r a n k l i n S t r e e t , F i f t h F l o o r ,
Boston, M A 0 2 1 1 0 - 1 3 0 1 , U S A . * /
/ * Moderately S p a c e - o p t i m i z e d l i b g c c r o u t i n e s f o r t h e R e n e s a s S H /
STMicroelectronics S T 4 0 C P U s .
Contributed b y J " o r n R e n n e c k e j o e r n . r e n n e c k e @st.com. */
/ * Size : 1 8 6 bytes j o i n t l y f o r u d i v s i 3 _ i 4 i a n d s d i v s i 3 _ i 4 i
sh4 - 2 0 0 r u n t i m e s :
udiv s m a l l d i v i s o r : 5 5 c y c l e s
udiv l a r g e d i v i s o r : 5 2 c y c l e s
sdiv s m a l l d i v i s o r , p o s i t i v e r e s u l t : 5 9 c y c l e s
sdiv l a r g e d i v i s o r , p o s i t i v e r e s u l t : 5 6 c y c l e s
sdiv s m a l l d i v i s o r , n e g a t i v e r e s u l t : 6 5 c y c l e s ( * )
sdiv l a r g e d i v i s o r , n e g a t i v e r e s u l t : 6 2 c y c l e s ( * )
( * ) : r2 i s r e s t o r e d i n t h e r t s d e l a y s l o t a n d h a s a l i n g e r i n g l a t e n c y
of t w o m o r e c y c l e s . * /
.balign 4
.global __udivsi3_i4i
2008-11-20 09:26:35 +03:00
.global __udivsi3_i4
.set _ _ udivsi3 _ i 4 , _ _ u d i v s i 3 _ i 4 i
2008-11-18 11:33:48 +03:00
.type _ _ udivsi3 _ i 4 i , @function
.type _ _ sdivsi3 _ i 4 i , @function
__udivsi3_i4i :
sts p r ,r1
mov. l r4 ,@-r15
extu. w r5 ,r0
cmp/ e q r5 ,r0
swap. w r4 ,r0
shlr1 6 r4
bf/ s l a r g e _ d i v i s o r
div0 u
mov. l r5 ,@-r15
shll1 6 r5
sdiv_small_divisor :
div1 r5 ,r4
bsr d i v6
div1 r5 ,r4
div1 r5 ,r4
bsr d i v6
div1 r5 ,r4
xtrct r4 ,r0
xtrct r0 ,r4
bsr d i v7
swap. w r4 ,r4
div1 r5 ,r4
bsr d i v7
div1 r5 ,r4
xtrct r4 ,r0
mov. l @r15+,r5
swap. w r0 ,r0
mov. l @r15+,r4
jmp @r1
rotcl r0
div7 :
div1 r5 ,r4
div6 :
div1 r5 ,r4 ; div1 r5,r4; div1 r5,r4
div1 r5 ,r4 ; div1 r5,r4; rts; div1 r5,r4
divx3 :
rotcl r0
div1 r5 ,r4
rotcl r0
div1 r5 ,r4
rotcl r0
rts
div1 r5 ,r4
large_divisor :
mov. l r5 ,@-r15
sdiv_large_divisor :
xor r4 ,r0
.rept 4
rotcl r0
bsr d i v x3
div1 r5 ,r4
.endr
mov. l @r15+,r5
mov. l @r15+,r4
jmp @r1
rotcl r0
.global __sdivsi3_i4i
2008-11-20 09:26:35 +03:00
.global __sdivsi3_i4
2008-11-18 11:33:48 +03:00
.global __sdivsi3
2008-11-20 09:26:35 +03:00
.set _ _ sdivsi3 _ i 4 , _ _ s d i v s i 3 _ i 4 i
2008-11-18 11:33:48 +03:00
.set _ _ sdivsi3 , _ _ s d i v s i 3 _ i 4 i
__sdivsi3_i4i :
mov. l r4 ,@-r15
cmp/ p z r5
mov. l r5 ,@-r15
bt/ s p o s _ d i v i s o r
cmp/ p z r4
neg r5 ,r5
extu. w r5 ,r0
bt/ s n e g _ r e s u l t
cmp/ e q r5 ,r0
neg r4 ,r4
pos_result :
swap. w r4 ,r0
bra s d i v _ c h e c k _ d i v i s o r
sts p r ,r1
pos_divisor :
extu. w r5 ,r0
bt/ s p o s _ r e s u l t
cmp/ e q r5 ,r0
neg r4 ,r4
neg_result :
mova n e g a t e _ r e s u l t ,r0
;
mov r0 ,r1
swap. w r4 ,r0
lds r2 ,m a c l
sts p r ,r2
sdiv_check_divisor :
shlr1 6 r4
bf/ s s d i v _ l a r g e _ d i v i s o r
div0 u
bra s d i v _ s m a l l _ d i v i s o r
shll1 6 r5
.balign 4
negate_result :
neg r0 ,r0
jmp @r2
sts m a c l ,r2