2009-09-24 14:11:24 +00:00
/ *
* Copyright 2 0 0 8 A n a l o g D e v i c e s I n c .
*
* Licensed u n d e r t h e A D I B S D l i c e n s e o r t h e G P L - 2 ( o r l a t e r )
* /
2009-01-07 23:14:39 +08:00
.align 2
.global _ _ _ muldi3 ;
.type _ _ _ muldi3 , S T T _ F U N C ;
# ifdef C O N F I G _ A R I T H M E T I C _ O P S _ L 1
.section .l1 .text
# else
.text
# endif
/ *
R1 : R0 * R 3 : R 2
= R1 . h : R 1 . l : R 0 . h : R 0 . l * R 3 . h : R 3 . l : R 2 . h : R 2 . l
[ X] = ( R 1 . h * R 3 . h ) * 2 ^ 9 6
[ X] + ( R 1 . h * R 3 . l + R 1 . l * R 3 . h ) * 2 ^ 8 0
[ X] + ( R 1 . h * R 2 . h + R 1 . l * R 3 . l + R 3 . h * R 0 . h ) * 2 ^ 6 4
[ T1 ] + ( R 1 . h * R 2 . l + R 3 . h * R 0 . l + R 1 . l * R 2 . h + R 3 . l * R 0 . h ) * 2 ^ 4 8
[ T2 ] + ( R 1 . l * R 2 . l + R 3 . l * R 0 . l + R 0 . h * R 2 . h ) * 2 ^ 3 2
[ T3 ] + ( R 0 . l * R 2 . h + R 2 . l * R 0 . h ) * 2 ^ 1 6
[ T4 ] + ( R 0 . l * R 2 . l )
We c a n d i s c a r d t h e f i r s t t h r e e l i n e s m a r k e d " X " s i n c e w e p r o d u c e
only a 6 4 b i t r e s u l t . S o , w e n e e d t e n 1 6 - b i t m u l t i p l i e s .
Individual m u l - a c c r e s u l t s :
[ E1 ] = R 1 . h * R 2 . l + R 3 . h * R 0 . l + R 1 . l * R 2 . h + R 3 . l * R 0 . h
[ E2 ] = R 1 . l * R 2 . l + R 3 . l * R 0 . l + R 0 . h * R 2 . h
[ E3 ] = R 0 . l * R 2 . h + R 2 . l * R 0 . h
[ E4 ] = R 0 . l * R 2 . l
We a l s o n e e d t o a d d h i g h p a r t s f r o m l o w e r - l e v e l r e s u l t s t o h i g h e r o n e s :
E[ n ] c = E [ n ] + ( E [ n + 1 ] c > > 1 6 ) , w h e r e E 4 c : = E 4
One i n t e r e s t i n g p r o p e r t y i s t h a t a l l p a r t s o f t h e r e s u l t t h a t d e p e n d
on t h e s i g n o f t h e m u l t i p l i c a t i o n a r e d i s c a r d e d . T h o s e w o u l d b e t h e
multiplications i n v o l v i n g R 1 . h a n d R 3 . h , b u t o n l y t h e t o p 1 6 b i t o f
the 3 2 b i t r e s u l t d e p e n d o n t h e s i g n , a n d s i n c e R 1 . h a n d R 3 . h o n l y
occur i n E 1 , t h e t o p h a l f o f t h e s e r e s u l t s i s c u t o f f .
So, w e c a n j u s t u s e F U m o d e f o r a l l o f t h e 1 6 - b i t m u l t i p l i e s , a n d
ignore q u e s t i o n s o f w h e n t o u s e m i x e d m o d e . * /
___muldi3 :
/ * [ SP] t e c h n i c a l l y i s p a r t o f t h e c a l l e r ' s f r a m e , b u t w e c a n
use i t a s s c r a t c h s p a c e . * /
A0 = R 2 . H * R 1 . L , A 1 = R 2 . L * R 1 . H ( F U ) | | R 3 = [ S P + 1 2 ] ; /* E1 */
A0 + = R 3 . H * R 0 . L , A 1 + = R 3 . L * R 0 . H ( F U ) | | [ S P ] = R 4 ; /* E1 */
A0 + = A 1 ; /* E1 */
R4 = A 0 . w ;
A0 = R 0 . l * R 3 . l ( F U ) ; /* E2 */
A0 + = R 2 . l * R 1 . l ( F U ) ; /* E2 */
A1 = R 2 . L * R 0 . L ( F U ) ; /* E4 */
R3 = A 1 . w ;
A1 = A 1 > > 1 6 ; /* E3c */
A0 + = R 2 . H * R 0 . H , A 1 + = R 2 . L * R 0 . H ( F U ) ; /* E2, E3c */
A1 + = R 0 . L * R 2 . H ( F U ) ; /* E3c */
R0 = A 1 . w ;
A1 = A 1 > > 1 6 ; /* E2c */
A0 + = A 1 ; /* E2c */
R1 = A 0 . w ;
/* low(result) = low(E3c):low(E4) */
R0 = P A C K ( R 0 . l , R 3 . l ) ;
/* high(result) = E2c + (E1 << 16) */
R1 . h = R 1 . h + R 4 . l ( N S ) | | R 4 = [ S P ] ;
RTS;
.size _ _ _ muldi3 , . - _ _ _ m u l d i 3