slaa329

Upload: tinchu-shrivastava

Post on 03-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 slaa329

    1/15

    1 I n t r o d u c t i o n

    2 H o r n e r s M e t h o d

    2 . 1 M u l t i p l i c a t i o n

    2 . 1 . 1 E x a m p l e 1 : U n s i g n e d M u l t i p l i c a t i o n o f T w o F r a c t i o n s

    A p p l i c a t i o n R e p o r t S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 K r i p a s a g a r V e n k a t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . M S P 4 3 0

    A B S T R A C T

    M u l t i p l i c a t i o n a n d d i v i s i o n i n t h e a b s e n c e o f a h a r d w a r e m u l t i p l i e r r e q u i r e m a n y i n s t r u c t i o n c y c l e s , e s p e c i a l l y i n C . T h i s r e p o r t d i s c u s s e s a m e t h o d t h a t d o e s n o t n e e d a h a r d w a r e m u l t i p l i e r a n d c a n p e r f o r m m u l t i p l i c a t i o n a n d d i v i s i o n w i t h o n l y s h i f t a n d a d d i n s t r u c t i o n s . T h e m e t h o d d e s c r i b e d i n t h i s a p p l i c a t i o n r e p o r t i s b a s e d o n H o r n e r s m e t h o d . T h e M S P 4 3 0 m i c r o c o n t r o l l e r C P U c a n p e r f o r m a r e g i s t e r s h i f t o r a d d i n o n e i n s t r u c t i o n c y c l e . T h i s a l l o w s f a s t e x e c u t i o n o f m u l t i p l i c a t i o n s a n d d i v i s i o n s u s i n g H o r n e r s m e t h o d . T h i s m e t h o d n o t o n l y p r o d u c e s a c c u r a t e r e s u l t s b u t a l s o p r o v i d e s a v e r y g o o d d y n a m i c r a n g e a s i t d o e s n o t t o t a l l y d e p e n d o n f i n i t e w o r d l e n g t h e f f e c t s l i k e

    s o m e o f t h e c o n v e n t i o n a l m e t h o d s . A l s o d i s c u s s e d i s t h e C a n o n i c a l S i g n e d D i g i t ( C S D ) r e p r e s e n t a t i o n o f n u m b e r s w h i c h f u r t h e r r e d u c e s t h e c o m p u t a t i o n a l l o a d w h e n u s e d w i t h t h i s m e t h o d f o r m u l t i p l i c a t i o n a n d d i v i s i o n . N o t e t h a t H o r n e r ' s m e t h o d r e q u i r e s t h e m u l t i p l i e r o r t h e d i v i s o r t o b e k n o w n i n a d v a n c e t o f u n c t i o n .

    N u m b e r s c a n b e b r o a d l y c l a s s i f i e d a s f i x e d p o i n t a n d f l o a t i n g p o i n t . T h e f i x e d - p o i n t n u m b e r r e p r e s e n t a t i o n i s l i m i t e d t o p o s i t i v e a n d n e g a t i v e i n t e g e r s , w h e r e a s t h e f l o a t i n g - p o i n t n u m b e r r e p r e s e n t a t i o n c a n a c c o m m o d a t e f r a c t i o n s a s w e l l . M i c r o c o n t r o l l e r s a r e f i x e d - p o i n t m a c h i n e s a n d d e a l w i t h o n l y f i x e d - p o i n t a r i t h m e t i c . H e n c e , a l t e r n a t e m e t h o d s n e e d t o b e d e v i s e d t o h a n d l e f l o a t i n g - p o i n t a r i t h m e t i c . T h i s a l s o

    l e a d s t o a l o s s i n p r e c i s i o n d u e t o f i n i t e w o r d l e n g t h e f f e c t s . M o s t m i c r o c o n t r o l l e r s d o n o t h a v e a h a r d w a r e m u l t i p l i e r a n d r e l y o n a l g o r i t h m s b a s e d o n r e p e a t e d a d d i t i o n t o p e r f o r m m u l t i p l i c a t i o n a n d d i v i s i o n o p e r a t i o n s . T h i s c o n s u m e s a l o t o f i n s t r u c t i o n c y c l e s a n d a l s o e x h i b i t s l i m i t e d p r e c i s i o n . T h e H o r n e r s m e t h o d d i s c u s s e d h e r e i s t a i l o r - m a d e f o r s u c h m a c h i n e s w i t h o u t m u c h l o s s i n p r e c i s i o n .

    T h e H o r n e r s m e t h o d r e q u i r e s t h e m u l t i p l i e r o r t h e d i v i s o r t o b e k n o w n i n a d v a n c e . T h i s i s n o t a s e r i o u s l i m i t a t i o n , s i n c e f e w a p p l i c a t i o n s p e r f o r m m u l t i p l i c a t i o n o r d i v i s i o n o f n u m b e r s t h a t c h a n g e a t r u n t i m e . O n c e t h i s i s e s t a b l i s h e d , t h e m u l t i p l i c a t i o n o r d i v i s i o n c a n b e p e r f o r m e d e f f i c i e n t l y w i t h j u s t s h i f t a n d a d d o p e r a t i o n s . T h e o p e r a n d i s d e n o t e d b y X , t h e m u l t i p l i e r b y M , a n d t h e d i v i s o r b y D .

    I n e x p l a i n i n g t h i s m e t h o d , f i r s t i s c o n s i d e r e d t h e m u l t i p l i c a t i o n o f t w o u n s i g n e d f r a c t i o n s .

    L e t t h e n u m b e r 0 . 1 2 3 4 5 b e m u l t i p l i e d b y t h e c o n s t a n t 0 . 1 4 3 2 5 . T h e 1 2 - b i t b i n a r y r e p r e s e n t a t i o n s o f t h e s e n u m b e r s a r e :

    X = 0 . 1 2 3 4 5 = 0 . 0 0 0 1 1 1 1 1 1 0 0 1 bM = 0 . 1 4 3 2 5 = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 1

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    2/15

    www.ti.com

    H o r n e r s M e t h o d

    T h e c o n v e n t i o n a l m e t h o d t o p e r f o r m t h i s m u l t i p l i c a t i o n i s :

    0 . 1 2 3 4 5 0 . 1 4 3 2 5 = ( 0 . 0 0 0 1 1 1 1 1 1 0 0 1 b) ( 2 3 + 2 6 + 2 9 + 2 1 1 )

    = 0 . 0 0 0 0 0 0 1 1 1 1 1 1 b +

    0 . 0 0 0 0 0 0 0 0 0 1 1 1 b +0 . 0 0 0 0 0 0 0 0 0 0 0 1 b +

    0 . 0 0 0 0 0 0 0 0 0 0 0 0 b0 . 0 0 0 0 0 1 0 0 0 1 1 1 b = 0 . 0 1 7 3 3 3 9 8 4 3 7 5

    T h e c o r r e c t r e s u l t o f t h i s m u l t i p l i c a t i o n i s 0 . 0 1 7 6 8 4 2 1 2 5 , a n d t h e a b o v e m e t h o d r e s u l t s i n a n a b s o l u t e e r r o r o f 0 . 0 0 0 3 5 0 2 2 8 1 2 5 , w h i c h i s a p p r o x i m a t e l y 1 . 5 L S B . T h i s e r r o r c a n b e a t t r i b u t e d t o f i n i t e w o r d l e n g t h e f f e c t s d u e t o r e g i s t e r w i d t h l i m i t a t i o n s . A s t h e n u m b e r o f b i t s a l l o c a t e d f o r t h e f r a c t i o n s i n c r e a s e t h i s e r r o r i s r e d u c e d . T h e H o r n e r s m e t h o d a i m s t o r e d u c e t h i s e r r o r w h i l e m a i n t a i n i n g t h e s a m e r e g i s t e r w i d t h s .

    T h e H o r n e r s a l g o r i t h m i s b a s e d o n t h e p o s i t i o n s o f t h e 1 s i n t h e m u l t i p l i e r a n d t h e i r d i s t a n c e t o t h e i m m e d i a t e 1 t o t h e i r l e f t . T h i s i s d o n e s t a r t i n g f r o m t h e r i g h t m o s t b i t p o s i t i o n a n d m o v i n g l e f t u n t i l t h e l a s t 1 b e f o r e t h e b i n a r y p o i n t .

    I n t h e b i n a r y e q u i v a l e n t o f t h e m u l t i p l i e r 0 . 1 4 3 2 5 = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b, s t a r t i n g f r o m t h e r i g h t t h e f i r s t 1 o c c u r s a t b i t p o s i t i o n 2 1 1 . T h e d i f f e r e n c e i n p o s i t i o n o f t h i s 1 t o i t s i m m e d i a t e 1 t o t h e l e f t i s t w o . S i m i l a r l y

    t h e d i f f e r e n c e f o r t h e 1 i n b i t p o s i t i o n 2 9 i s t h r e e a n d s o o n .

    I f t h e n u m b e r t o b e m u l t i p l i e d i s d e n o t e d a s X , t h e d e s i g n e q u a t i o n s c a n b e w r i t t e n a s :

    S t e p 1 : S e t t h e i n t e r m e d i a t e r e s u l t e q u a l t o t h e o p e r a n d X a n d s t a r t w i t h t h e r i g h t m o s t 1

    X 2 2 + X = X 1 F o r t h e f i r s t i t e r a t i o n , t h e w e i g h t 2 2 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t a s t h e

    d i s t a n c e o f t h e r i g h t m o s t 1 ( b i t p o s i t i o n 2 1 1 ) i n t h e m u l t i p l i e r t o i t s n e x t 1 ( b i t

    p o s i t i o n 2 9) i s t w o . T h e o p e r a n d X i s a d d e d t o a c c o u n t t h e o c c u r r e n c e o f t h e 1 a t b i t p o s i t i o n 2 9. T h e r e s u l t o f t h i s a d d i t i o n i s n o w s t o r e d a s t h e i n t e r m e d i a t e r e s u l t

    a f t e r t h i s s t e p .

    S t e p 2 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 9

    X1 2 3 + X = X 2 T h e w e i g h t 2

    3 i s n o w a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 1 ) s i n c e

    t h e d i s t a n c e o f t h e 1 i n b i t p o s i t i o n 2 9 t o i t s n e x t 1 ( b i t p o s i t i o n 2 6) i s t h r e e . T h e o p e r a n d i s a g a i n a d d e d f o r t h e r e a s o n e x p l a i n e d i n S t e p 1 .

    S t e p 3 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 6

    X2 2 3 + X = X 3 T h e w e i g h t 2

    3 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 2 ) a n d t h e o p e r a n d a d d e d .

    S t e p 4 : P r o c e e d t o t h e l a s t 1 i n b i t p o s i t i o n 2 3

    F i n a l r e s u l t = X 3 2 3 T h e f a c t o r 2 3 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 3 ) , a s i t i s t h e w e i g h t a t t h e p o s i t i o n o f t h e l e f t m o s t 1 . T h e o p e r a n d i s n o t a d d e d t h i s t i m e ,

    s i n c e a l l t h e 1 s h a v e b e e n t a k e n i n t o a c c o u n t .

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 2 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    3/15

    www.ti.com

    2 . 2 D i v i s i o n

    2 . 2 . 1 E x a m p l e 2 : U n s i g n e d D i v i s i o n o f a n I n t e g e r b y a F l o a t i n g P o i n t N u m b e r

    H o r n e r s M e t h o d

    T h i s a p p r o a c h c a n b e v a l i d a t e d b y b a c k s u b s t i t u t i n g t h e i n t e r m e d i a t e r e s u l t s .

    F i n a l r e s u l t = X 3 2 3 = ( X2 2

    3 + X ) 2 3 = [ ( X 1 2 3 + X ) 2 3 + X ] 2 3

    = { [ ( X 2 2 2 + X ) 2 3 + X ] 2 3 + X } 2 3

    = X ( 2 1 1 + 2 9 + 2 6 + 2 3)

    T h i s r e s u l t m a t c h e s w i t h t h e m u l t i p l i c a t i o n d i s c u s s e d e a r l i e r . T h e a l g o r i t h m w i t h X = 0 . 0 0 0 1 1 1 1 1 1 0 0 1 bw h e n i m p l e m e n t e d g i v e s :

    X1 = X 2 2 + X = 0 . 0 0 0 0 0 1 1 1 1 1 1 0 b +

    0 . 0 0 0 1 1 1 1 1 1 0 0 1 b

    X1 0 . 0 0 1 0 0 1 1 1 0 1 1 1 b

    S i m i l a r l y ,

    X2 = X1 2 3 + X = 0 . 0 0 0 0 0 1 0 0 1 1 1 0 b +

    0 . 0 0 0 1 1 1 1 1 1 0 0 1 b

    X2 0 . 0 0 1 0 0 1 0 0 0 1 1 1 b

    A n d ,

    X3 = X2 2 3 + X = 0 . 0 0 0 0 0 1 0 0 1 0 0 0 b +

    0 . 0 0 0 1 1 1 1 1 1 0 0 1 b

    X3 0 . 0 0 1 0 0 1 0 0 0 0 0 1 b

    T h e f i n a l r e s u l t i s

    F i n a l r e s u l t = X 3 2 3 = 0 . 0 0 0 0 0 1 0 0 1 0 0 0 b = 0 . 0 1 7 5 7 8 1 2 5 .

    T h i s h a s a n a b s o l u t e e r r o r o f 0 . 0 0 0 1 0 6 0 8 7 5 w h i c h i s j u s t 0 . 4 3 4 5 3 4 L S B . T h u s H o r n e r s m e t h o d g i v e s a b e t t e r r e s u l t f o r t h e s a m e w i d t h l i m i t a t i o n s . A l s o , t h e m e t h o d d e s c r i b e d u s e s o n l y s h i f t a n d a d d o p e r a t i o n s . T h e p r o c e d u r e r e m a i n s t h e s a m e i f t h e o p e r a n d i s a n e g a t i v e f r a c t i o n . N u m e r i c a l e x a m p l e s f o r v a r i o u s c o m b i n a t i o n s o f t h e o p e r a n d ( X ) a n d m u l t i p l i e r s ( M ) a r e g i v e n i n A p p e n d i x A .

    N o w t h a t H o r n e r s m e t h o d i s s h o w n t o w o r k f o r m u l t i p l i c a t i o n w i t h g o o d a c c u r a c y , i t i s e a s i l y e x t e n d e d t o d i v i s i o n . T h e f a c t t h a t d i v i s i o n b y a n u m b e r i s a m u l t i p l i c a t i o n b y i t s r e c i p r o c a l i s u s e d t o e x p l a i n t h e a p p r o a c h . T h e e x a m p l e s s h o w n i n A p p e n d i x A i n d i c a t e t h a t H o r n e r s m e t h o d w o r k s f l a w l e s s l y f o r a l l t y p e s o f m u l t i p l i e r s . H e n c e , o n l y a s i n g l e e x a m p l e i s s h o w n t h a t i m p l e m e n t s d i v i s i o n .

    C o n s i d e r t h e d i v i s i o n o f t h e n u m b e r X = 4 4 1 b y t h e f a c t o r 4 1 . 8 3 7 5 .

    X = 4 4 1 = 0 1 1 0 1 1 1 0 0 1 b

    D = 4 1 . 8 3 7 5 = 0 1 0 1 0 0 1 . 1 1 0 1 0 1 1 0 0 1 b

    M = 1 / 4 1 . 8 3 7 5 = 0 . 0 2 3 9 0 2 0 0 1 8 = 0 . 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 0 b

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 3

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    4/15

    www.ti.com

    2 . 3 C a n o n i c a l S i g n e d D i g i t R e p r e s e n t a t i o n ( C S D )

    H o r n e r s M e t h o d

    T h e d e s i g n e q u a t i o n s f o r t h i s d i v i s i o n a r e :

    S t e p 1 : S e t t h e i n t e r m e d i a t e r e s u l t e q u a l t o t h e o p e r a n d X a n d s t a r t w i t h t h e r i g h t m o s t 1

    X 2 1 + X = X 1 F o r t h e f i r s t i t e r a t i o n , t h e w e i g h t 2 1 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t a s t h e

    d i s t a n c e o f t h e r i g h t m o s t 1 ( b i t p o s i t i o n 2 1 5) i n t h e m u l t i p l i e r t o i t s n e x t 1 ( b i t

    p o s i t i o n 2 1 4) i s o n e . T h e o p e r a n d X i s a d d e d t o a c c o u n t t h e o c c u r r e n c e o f t h e 1 a t

    b i t p o s i t i o n 2 1 4

    . T h e r e s u l t o f t h i s a d d i t i o n i s n o w s t o r e d a s t h e i n t e r m e d i a t e r e s u l t a f t e r t h i s s t e p .

    S t e p 2 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 1 4

    X1 2 1 + X = X 2 T h e w e i g h t 2

    1 i s n o w a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 1 ) s i n c e

    t h e d i s t a n c e o f t h e 1 i n b i t p o s i t i o n 2 1 4 t o i t s n e x t 1 i s o n e . T h e o p e r a n d i s a g a i n a d d e d f o r t h e r e a s o n e x p l a i n e d i n S t e p 1 .

    S t e p 3 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 1 3

    X2

    2 1 + X = X 3

    T h e w e i g h t 2 1 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 2 ) a n d t h e o p e r a n d a d d e d .

    S t e p 4 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 1 2

    X3 2 5 + X = X 4 T h e w e i g h t 2

    5 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 3 ) a n d t h e o p e r a n d a d d e d .

    S t e p 5 : P r o c e e d t o t h e n e x t 1 i n b i t p o s i t i o n 2 7

    X4 2 1 + X = X 5 T h e w e i g h t 2

    1 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 4 ) a n d t h e o p e r a n d a d d e d .

    S t e p 6 : P r o c e e d t o t h e l a s t 1 i n b i t p o s i t i o n 2 6

    F i n a l r e s u l t = X 5 2 6 T h e f a c t o r 2 6 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 5 ) a s i t i s

    t h e w e i g h t a t t h e p o s i t i o n o f t h e l e f t m o s t 1 . T h e o p e r a n d i s n o t a d d e d t h i s

    t i m e , s i n c e a l l t h e 1 s h a v e b e e n t a k e n i n t o a c c o u n t .

    T h e c o r r e c t r e s u l t f o r t h i s d i v i s i o n i s 1 0 . 5 4 0 7 8 2 7 , a n d t h e r e s u l t o b t a i n e d i s 1 0 w i t h t h e f r a c t i o n a l p a r t d i s c a r d e d w i t h a n e r r o r o f 0 . 5 4 0 7 8 2 7 , s i m i l a r t o t h e e r r o r i n c o n v e n t i o n a l m e t h o d s .

    A l l t y p e s o f o p e r a n d s a n d m u l t i p l i e r s s h o w n i n t h e p r e v i o u s s e c t i o n a n d A p p e n d i x A c a n b e e x t e n d e d t o t h e p r o c e s s o f d i v i s i o n t o p r o d u c e t h e d e s i r e d r e s u l t s .

    T h e e f f i c i e n c y o f H o r n e r s m e t h o d c a n b e f u r t h e r i m p r o v e d b y u s i n g t h e C a n o n i c a l S i g n e d D i g i t ( C S D ) f o r m a t t o r e p r e s e n t t h e m u l t i p l i e r o r d i v i s o r . T h e C S D f o r m a t a i m s t o r e d u c e t h e n u m b e r o f a d d o p e r a t i o n s d u r i n g m u l t i p l i c a t i o n a n d d i v i s i o n . T h e C S D f o r m a t h a s a t e r n a r y s e t a s o p p o s e d t o a b i n a r y s e t i n n u m b e r r e p r e s e n t a t i o n . T h e s y m b o l s u s e d i n t h i s f o r m a t a r e { 0 , 1 , 1 } , w i t h 1 r e p r e s e n t i n g 1 . T h e g o a l i s t o g r o u p c o n s e c u t i v e 1 s a n d c h a n g e t h e m t o a t e r n a r y r e p r e s e n t a t i o n f r o m b i n a r y r e p r e s e n t a t i o n . T h i s i s d o n e s t a r t i n g f r o m t h e r i g h t m o s t 1 a n d p r o c e e d i n g l e f t u n t i l t h e l a s t 1 . B y d o i n g s o , t h e f i n a l C S D r e p r e s e n t a t i o n n e v e r h a s a d j a c e n t 1 s o r 1 s . T h i s r e p r e s e n t a t i o n i s e f f e c t i v e w h e n t h e r e a r e m a n y a d j a c e n t 1 s i n t h e b i n a r y r e p r e s e n t a t i o n .

    4 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    5/15

    www.ti.com

    2 . 3 . 1 E x a m p l e 3 : U n s i g n e d M u l t i p l i c a t i o n o f F r a c t i o n s U s i n g H o r n e r s M e t h o d a n d C S D

    ~1. 1 1 0 1 1 1 1 1 1 1 1 1 b

    ~1 = S i g n b i t

    H o r n e r s M e t h o d

    C o n s i d e r t h e 1 2 - b i t r e p r e s e n t a t i o n o f 0 . 1 2 3 4 5 = 0 . 0 0 0 1 1 1 1 1 1 0 0 1 b.

    T h e C S D f o r m a t c a n b e u s e d h e r e t o g r o u p t h e c o n s e c u t i v e 1 s . S t a r t i n g f r o m t h e r i g h t m o s t b i t , t h e f i r s t 1 o c c u r s a t t h e p o s i t i o n 2 1 2. T h i s 1 d o e s n o t h a v e a n a d j a c e n t 1 t o i t s l e f t a n d h e n c e n o t m o d i f i e d . T h e n e x t 1 a t p o s i t i o n 2 9 h a s f i v e a d j a c e n t 1 s t o t h e l e f t o f i t . T h e s e s i x 1 s a r e c o m b i n e d a n d 1 i s p l a c e d a t t h e r i g h t m o s t b i t p o s i t i o n ( 2 9) , z e r o s a t t h e r e m a i n i n g p o s i t i o n s ( 2 8 t o 2 4) a n d a 1 a t t h e b i t p o s i t i o n 2 3 ( o n e p o s i t i o n l e f t t o l e f t m o s t 1 o f t h e o r i g i n a l s e q u e n c e ) . T h i s p r o c e s s i s r e p e a t e d f o r a d d i t i o n a l g r o u p s o f 1 s

    t h a t a r e e n c o u n t e r e d . T h e C S D r e p r e s e n t a t i o n n o w b e c o m e s : 0 . 1 2 3 4 5 = 0 . 0 0 1 0 0 0 0 0 1 0 0 1 C S D

    H o r n e r s m e t h o d u s i n g C S D f o r m a t r e d u c e s t h e n u m b e r o f a d d o p e r a t i o n s d u r i n g m u l t i p l i c a t i o n . T h e E x a m p l e 3 s h o w n i s s a m e a s E x a m p l e 1 , w i t h t h e r o l e s o f t h e m u l t i p l i e r a n d m u l t i p l i c a n d i n t e r c h a n g e d . T h e m e t h o d g i v e s e x a c t r e s u l t s w i t h r e d u c e d n u m b e r o f a d d o p e r a t i o n s .

    R e p r e s e n t a t i o n

    X = 0 . 1 4 3 2 5 = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    M = 0 . 1 2 3 4 5 = 0 . 0 0 1 0 0 0 0 0 1 0 0 1 C S D

    T h e t e r n a r y r e p r e s e n t a t i o n r e s u l t s i n a s l i g h t m o d i f i c a t i o n t o H o r n e r s m e t h o d . T h e d e s i g n e q u a t i o n n o w

    f o r a n o p e r a n d X b e c o m e s :

    S t e p 1 : S e t t h e i n t e r m e d i a t e r e s u l t e q u a l t o t h e o p e r a n d X a n d s t a r t w i t h t h e r i g h t m o s t 1 .

    X 2 3 X = X1 F o r t h e f i r s t i t e r a t i o n , t h e w e i g h t 2 3 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t a s t h e

    d i s t a n c e o f t h e r i g h t m o s t 1 ( b i t p o s i t i o n 2 1 2) i n t h e m u l t i p l i e r t o i t s n e x t 1 o r 1 ( b i t p o s i t i o n 2 9) i s t h r e e . T h e o p e r a n d X i s n o w s u b t r a c t e d ( i n s t e a d o f b e i n g a d d e d ) t o

    a c c o u n t t h e o c c u r r e n c e o f t h e 1 ( i n s t e a d o f a 1 ) a t b i t p o s i t i o n 2 9. T h e r e s u l t o f t h i s s u b t r a c t i o n i s n o w s t o r e d a s t h e i n t e r m e d i a t e r e s u l t a f t e r t h i s s t e p .

    S t e p 2 : P r o c e e d t o t h e n e x t 1 o r 1 ( i n t h i s e x a m p l e ) a t b i t p o s i t i o n 2 9

    X1 2 6 + X = X 2 T h e w e i g h t 2

    6 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 1 ) a n d o p e r a n d

    a d d e d s i n c e 1 i s e n c o u n t e r e d a t b i t p o s i t i o n 2 3.

    S t e p 3 : P r o c e e d t o t h e l a s t 1 i n b i t p o s i t i o n 2 3

    F i n a l r e s u l t = X 2 2 3 T h e f a c t o r 2 3 i s a p p l i e d t o t h e i n t e r m e d i a t e r e s u l t ( u p d a t e d i n S t e p 2 ) a s i t i s

    t h e w e i g h t a t t h e p o s i t i o n o f t h e l e f t m o s t 1 ( o r 1 ) . T h e o p e r a n d i s n o t a d d e d t h i s t i m e , s i n c e a l l t h e 1 s ( o r 1 s ) h a v e b e e n t a k e n i n t o a c c o u n t .

    T h e a l g o r i t h m w i t h X = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b w h e n i m p l e m e n t e d g i v e s :

    X1 = X 2 3 X = 0 . 0 0 0 0 0 1 0 0 1 0 0 1 b

    0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    X1

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 5

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    6/15

    www.ti.com

    ~1. 1 1 1 1 1 1 1 1 0 1 1 1 b +

    2 . 4 S u m m a r y

    2 . 4 . 1 R e s u l t s

    H o r n e r s M e t h o d

    S i m i l a r l y ,

    X2 = X1 2 6 + X =

    0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    X2 0 . 0 0 1 0 0 1 0 0 0 0 0 1 b

    F i n a l r e s u l t = X 2 2 3 = 0 . 0 0 0 0 0 1 0 0 1 0 0 0 b = 0 . 0 1 7 5 7 8 1 2 5

    B y g r o u p i n g c o n s e c u t i v e 1 s , t h e n u m b e r o f a d d o p e r a t i o n s i s r e d u c e d f r o m 6 t o 2 . A f e w t h i n g s c a n b e o b s e r v e d w i t h t h e r e s u l t s o b t a i n e d . I n t h i s e x a m p l e , i n t e r c h a n g i n g t h e r o l e s o f m u l t i p l i e r a n d m u l t i p l i c a n d p r o d u c e d s i m i l a r r e s u l t s . H e n c e , t h e a b s o l u t e e r r o r i n t h i s c a s e i s a l s o 0 . 0 0 0 1 0 6 0 8 7 5 , w h i c h i s j u s t 0 . 4 3 4 5 3 4 L S B .

    T h e C S D r e p r e s e n t a t i o n h o l d s f o r i n t e g e r s a s w e l l , w i t h a s i m i l a r p r o c e d u r e . A d d i t i o n a l c a r e m u s t b e t a k e n w h i l e g r o u p i n g t h e 1 s i n d o i n g t h e c o n v e r s i o n t o C S D o f f r a c t i o n s a n d i n t e g e r s . T h e g r o u p i n g o f 1 s m u s t b e d o n e t a k i n g e a c h g r o u p i n d e p e n d e n t l y , o n e a t a t i m e . A n e x a m p l e o f t h e i n t e g e r 4 4 1 r e p r e s e n t e d i n C S D i s s h o w n b e l o w :

    4 4 1 = 0 1 1 0 1 1 1 0 0 1 b = 1 0 0 1 0 0 1 0 0 1 C S D

    S t e p 1 4 4 1 = 0 1 1 0 1 1 1 0 0 1 b = 0 1 1 1 0 0 1 0 0 1 C S D

    S t e p 2 4 4 1 = 0 1 1 1 0 0 1 0 0 1 C S D = 1 0 0 1 0 0 1 0 0 1 C S D

    A d d i t i o n a l e x a m p l e s u s i n g t h e C S D f o r m a t i n c o n j u n c t i o n w i t h H o r n e r s m e t h o d i s s h o w n i n A p p e n d i x A .

    T h e p e r f o r m a n c e o f H o r n e r s m e t h o d w i t h a n d w i t h o u t C S D r e p r e s e n t a t i o n s h a s b e e n i m p l e m e n t e d o n t h e M S P 4 3 0 a r c h i t e c t u r e . C o m p a r i s o n s o f t h e n u m b e r o f i n s t r u c t i o n c y c l e s f o r e a c h m u l t i p l y a n d d i v i d e i s m a d e f o r H o r n e r s m e t h o d a g a i n s t i t s C e q u i v a l e n t a n d t h e e x i s t i n g a l g o r i t h m s . T h e C c o d e a n d t h e a s s o c i a t e d a s s e m b l y f i l e s h a v e b e e n i n c l u d e d i n a z i p f i l e a c c o m p a n y i n g t h i s a p p l i c a t i o n r e p o r t . T h e i r d e s c r i p t i o n s a r e p r o v i d e d i n A p p e n d i x B . T h e e x a m p l e s c o n s i d e r e d a r e ( 4 1 4 4 1 ) , ( 4 1 4 4 1 . 8 3 7 5 ) ,

    ( 9 2 8 0 / 4 1 ) , a n d ( 1 5 0 0 / 3 7 . 1 2 3 4 5 ) f o r i n t e g e r - i n t e g e r a n d i n t e g e r - f l o a t m u l t i p l i c a t i o n a n d d i v i s i o n , r e s p e c t i v e l y .

    T a b l e 1 s h o w s a c o m p a r i s o n a m o n g t h e m e t h o d s . F o r t h e i n t e g e r - f l o a t m u l t i p l i c a t i o n e x a m p l e , t h e a c c u r a c y o f H o r n e r s m e t h o d i s a l m o s t p e r f e c t , w h i c h i s n o t t h e c a s e w i t h e x i s t i n g c o n v e n t i o n a l a l g o r i t h m s . A l s o , i f t h e m u l t i p l i e r w e r e a p u r e f r a c t i o n , s c a l i n g o f t h e m u l t i p l i e r t o t h e n e a r e s t i n t e g e r m u s t b e d o n e b e f o r e t h e u s e o f c o n v e n t i o n a l a l g o r i t h m s .

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 6 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    7/15

    www.ti.com

    2 . 4 . 2 T r a d e o f f s

    H o r n e r s M e t h o d

    T a b l e 1 . O b s e r v a t i o n s f o r t h e M e t h o d s D i s c u s s e d

    I n s t r u c t i o n C o d e S i z e T y p e M e t h o d s R e s u l t s A b s o l u t e E r r o r

    C y c l e s ( b y t e s )

    C L I B ( 1 ) 7 7 5 0 1 8 0 8 1 0

    I n t e g e r - I n t e g e r E x i s t i n g m e t h o d s ( 2 ) 1 0 7 5 4 1 8 0 8 1 0 M u l t i p l i c a t i o n

    H o r n e r 1 5 3 2 1 8 0 8 1 0 ( 4 1 4 4 1 ) H o r n e r + C S D 1 3 3 0 1 8 0 8 1 0

    C L I B 1 8 3 8 0 2 2 6 0

    I n t e g e r - I n t e g e r E x i s t i n g m e t h o d s 1 9 1 2 8 2 2 6 0 D i v i s i o n

    H o r n e r 2 3 4 8 2 2 6 0 ( 9 2 8 0 / 4 1 )

    H o r n e r + C S D 2 1 4 4 2 2 6 0

    C L I B 4 2 7 ( 3 ) 3 2 2 1 8 1 1 5 . 3 3 7 5 0

    I n t e g e r - F l o a t E x i s t i n g m e t h o d s 1 0 7 5 4 1 8 0 8 1 3 4 . 3 3 7 5 M u l t i p l i c a t i o n

    H o r n e r 3 2 6 6 1 8 1 1 5 0 . 3 3 7 5 ( 4 1 4 4 1 . 8 3 7 5 )

    H o r n e r + C S D 2 9 6 0 1 8 1 1 5 0 . 3 3 7 5

    C L I B 4 7 6 5 0 0 4 0 . 4 0 5 7 0

    I n t e g e r - F l o a t E x i s t i n g m e t h o d s 1 9 1 2 8 4 0 0 . 4 0 5 7

    D i v i s i o n H o r n e r 2 4 5 0 4 0 0 . 4 0 5 7 ( 1 5 0 0 / 3 7 . 1 2 3 4 5 )

    H o r n e r + C S D 2 2 4 6 4 0 0 . 4 0 5 7

    ( 1 ) T h e C l i b r a r y i s p a r t o f t h e I A R E m b e d d e d W o r k b e n c h V e r . 3 . 4 1 A , w r i t t e n f o r M S P 4 3 0 f a m i l y o f d e v i c e s . ( 2 ) T h e a l g o r i t h m s h a v e b e e n e x p l a i n e d i n t h e b o o k C o m p u t e r O r g a n i z a t i o n , C a r l H a m a c h e r , Z v o n k o V r a n e s i c , a n d S a f a w a t Z a k y ,

    3 r d E d i t i o n , M c G r a w H i l l P u b l i c a t i o n , 1 9 9 0 . ( 3 ) I n c l u d e s c y c l e s f o r t y p e c o n v e r s i o n f r o m f l o a t t o i n t e g e r a s p a r t o f a r e q u i r e m e n t o f t h e a l g o r i t h m u s e d .

    T a b l e 1 r e s u l t s a r e u s e d a s a c o m p a r i s o n o f s p e e d , a c c u r a c y a n d m e m o r y r e q u i r e m e n t s . T h e M S P 4 3 0 C P U i m p l e m e n t s H o r n e r s a l g o r i t h m s e x t r e m e l y q u i c k l y w i t h i t s s i n g l e c y c l e s h i f t a n d a d d o p e r a t i o n s . T h e H o r n e r ' s m e t h o d , w h e n c o m p a r e d t o t h e e x i s t i n g m e t h o d s , i s e x t r e m e l y f a s t a n d m a i n t a i n s t h e s a m e l e v e l o f a c c u r a c y f o r i n t e g e r - i n t e g e r m u l t i p l i c a t i o n s a n d b e t t e r a c c u r a c y f o r i n t e g e r - f l o a t m u l t i p l i c a t i o n s . D i v i s i o n i s a l s o p e r f o r m e d e x t r e m e l y f a s t w i t h l i m i t e d a c c u r a c y . T h e e r r o r i n H o r n e r ' s m e t h o d i s s i m i l a r t o e x i s t i n g

    m e t h o d s f o r i n t e g e r - i n t e g e r d i v i s i o n . T h e r e s u l t s f o r i n t e g e r - f l o a t d i v i s i o n s c a n b e i m p r o v e d b y r e p r e s e n t i n g t h e d i v i s o r b y a h i g h e r n u m b e r o f b i t s , w i t h a n i n s i g n i f i c a n t i n c r e a s e i n c y c l e c o u n t . T h e r e i s n o p r o v i s i o n t o o b t a i n t h e r e m a i n d e r d u r i n g d i v i s i o n i n H o r n e r ' s m e t h o d , w h i c h i s n o t t h e c a s e w i t h t h e e x i s t i n g a l g o r i t h m s . T h e m o s t i m p o r t a n t b e n e f i t o f H o r n e r ' s m e t h o d i s t h e m u l t i p l i e r s a n d d i v i s o r s s u f f e r v e r y l i t t l e f r o m f i n i t e w o r d l e n g t h e f f e c t s . A l t h o u g h t h e e x a m p l e s c o n s i d e r e d h a d o n l y 1 2 - o r 1 6 - b i t w o r d l e n g t h s , e a c h o f t h e m c a n b e i m p l e m e n t e d w i t h l a r g e p r e c i s i o n w i t h p r o p o r t i o n a l i n c r e a s e i n t h e n u m b e r o f s h i f t a n d a d d o p e r a t i o n s . T h e m e m o r y r e q u i r e m e n t i s m u c h h i g h e r f o r H o r n e r ' s m e t h o d s i n c e , f o r e a c h m u l t i p l i e r o r d i v i s o r , t h e c o d e i s d i f f e r e n t . I n c a s e s w h e r e s p e e d i s o f p r i m e c o n c e r n , t h i s i s n o t a s e r i o u s l i m i t a t i o n . A l s o H o r n e r ' s m e t h o d r e q u i r e s t h e m u l t i p l i e r o r t h e d i v i s o r t o b e k n o w n i n a d v a n c e , w h i c h i s n o t t h e c a s e w i t h t h e o t h e r m e t h o d s . T h i s d o e s n o t p o s e a n y l i m i t a t i o n t o f i l t e r i n g o p e r a t i o n s a n d o t h e r s t a n d a r d c o n v e r s i o n s , w h e r e t h e m u l t i p l i e r s a n d d i v i s o r s d o n o t c h a n g e d u r i n g r u n t i m e .

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 7

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    8/15

    www.ti.com

    A p p e n d i x A

    A . 1 E x a m p l e 4 : S i g n e d M u l t i p l i c a t i o n o f F r a c t i o n s W i t h M u l t i p l i c a n d N e g a t i v e

    X = 0 . 1 2 3 4 5 = ~1. 1 1 1 0 0 0 0 0 0 1 1 1 b

    w h e r e ~1 i s t h e s i g n b i t r e p r e s e n t i n g 1 .

    A . 2 E x a m p l e 5 : S i g n e d M u l t i p l i c a t i o n o f F r a c t i o n s W i t h M u l t i p l i e r N e g a t i v e

    M = 0 . 1 2 3 4 5 = ~1. 1 1 1 0 0 0 0 0 0 1 1 1 b

    w h e r e ~1 i s t h e s i g n b i t r e p r e s e n t i n g 1 .

    A p p e n d i x A

    I n t h i s a p p e n d i x , s e v e r a l n u m e r i c a l e x a m p l e s a r e g i v e n f o r b e t t e r u n d e r s t a n d i n g o f H o r n e r s m e t h o d f o r v a r i o u s t y p e s o f o p e r a n d s a n d m u l t i p l i e r s .

    C o n s i d e r t h e e x a m p l e w h e n 0 . 1 2 3 4 5 i s m u l t i p l i e d b y t h e c o n s t a n t 0 . 1 4 3 2 5 . T h e r e p r e s e n t a t i o n o f t h i s n e g a t i v e f r a c t i o n i n t h e 2 s c o m p l e m e n t f o r m a t i s :

    M = 0 . 1 4 3 2 5 = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    T h e d e s i g n e q u a t i o n s f o r t h i s n u m e r i c a l e x a m p l e a r e s h o w n .

    X1 = X 2 2 + X = 1 . 1 1 1 1 1 0 0 0 0 0 0 1 b +

    1 . 1 1 1 0 0 0 0 0 0 1 1 1 b

    X1 1 . 1 1 0 1 1 0 0 0 1 0 0 0 b

    X2 = X1 2 3 + X = 1 . 1 1 1 1 1 0 1 1 0 0 0 1 b +

    1 . 1 1 1 0 0 0 0 0 0 1 1 1 b

    X2 1 . 1 1 0 1 1 0 1 1 1 0 0 0 b

    X3 = X2 2 3 + X = 1 . 1 1 1 1 1 0 1 1 0 1 1 1 b +

    1 . 1 1 1 0 0 0 0 0 0 1 1 1 b

    X3 1 . 1 1 0 1 1 0 1 1 1 1 1 0 b

    F i n a l r e s u l t = X 3 2 3 = 1 . 1 1 1 1 1 0 1 1 0 1 1 1 b = 0 . 0 1 7 8 2 2 2 6 5 6 2 5 , w h i c h h a s a n a b s o l u t e e r r o r o f

    0 . 0 0 0 1 3 8 0 5 3 1 2 5 , w h i c h i s j u s t 0 . 5 6 5 4 6 6 L S B .

    T h e a b o v e e x a m p l e s h o w s t h a t t h e m e t h o d i s a c c u r a t e , r e g a r d l e s s o f t h e s i g n o f t h e o p e r a n d X . I f t h e m u l t i p l i e r w e r e a n e g a t i v e n u m b e r , t h e a b o v e p r o c e d u r e r e m a i n s e x a c t l y t h e s a m e , e x c e p t t h a t i n t h e e n d t h e o p e r a n d X i s s u b t r a c t e d d u e t o t h e s i g n b i t o f t h e m u l t i p l i e r . T h e d e s i g n e q u a t i o n s f o r t h i s a r e s h o w n i n E x a m p l e 5 .

    I f t h e m u l t i p l i e r i s n o w c o n s i d e r e d t o b e 0 . 1 2 3 4 5 a n d t h e o p e r a n d X t o b e 0 . 1 4 3 2 5 . T h e b i n a r y

    r e p r e s e n t a t i o n s a r e :

    X = 0 . 1 4 3 2 5 = 0 . 0 0 1 0 0 1 0 0 1 0 1 0 b

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 8 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    9/15

    www.ti.com

    A . 3 E x a m p l e 6 : U n s i g n e d M u l t i p l i c a t i o n o f I n t e g e r s

    A . 4 E x a m p l e 7 : S i g n e d M u l t i p l i c a t i o n o f I n t e g e r s W i t h M u l t i p l i e r N e g a t i v e

    M = 4 4 1 = ~10 0 1 0 0 0 1 1 1 b

    E x a m p l e 6 : U n s i g n e d M u l t i p l i c a t i o n o f I n t e g e r s

    X 2 1 + X = X 1

    X1 2 1 + X = X 2

    X2 2 7 + X = X 3

    X3 2 1 + X = X 4

    X4 2 1 + X = X 5

    F i n a l r e s u l t = X 5 2 1 X .

    W i t h t h e p r e s e n t o p e r a n d s t h e a b s o l u t e e r r o r o b t a i n e d i s 0 . 0 0 0 1 3 8 0 5 3 1 2 5 , w h i c h i s 0 . 5 6 5 4 6 6 L S B .

    T h e p r e v i o u s e x a m p l e s c o n s i d e r e d f r a c t i o n - f r a c t i o n m u l t i p l i c a t i o n e x h i b i t i n g t h e b e t t e r a c c u r a c y o f t h i s m e t h o d o v e r o t h e r s . T h i s m e t h o d c a n a l s o b e e m p l o y e d w h e n t h e m u l t i p l i e r i s a n y i n t e g e r o r r e a l n u m b e r . T h e p r o c e d u r e f o r t h i s i s v e r y s i m i l a r t o t h e p r e v i o u s m e t h o d , w i t h a s l i g h t c h a n g e . I n m i c r o c o n t r o l l e r s , t h e o p e r a n d X i s u s u a l l y d a t a c o m i n g f r o m t h e a n a l o g - t o - d i g i t a l c o n v e r t e r ( A D C ) , w h i c h i s a f i x e d - p o i n t n u m b e r . T y p i c a l e x a m p l e s a r e c o n s i d e r e d w i t h t h e o p e r a n d X a f i x e d p o i n t a n d t h e m u l t i p l i e r a n i n t e g e r o r a r e a l n u m b e r .

    C o n s i d e r t h e v a l u e o f X t o b e 4 1 a n d t h e m u l t i p l i e r i s 4 4 1 .

    X = 4 1 = 0 1 0 1 0 0 1 b

    M = 4 4 1 = 0 1 1 0 1 1 1 0 0 1 b

    T h e o n l y c h a n g e w h e n t h e m u l t i p l i e r i s a n i n t e g e r i s t h e a l g o r i t h m s t a r t s l o o k i n g f o r 1 s s t a r t i n g f r o m t h e l e f t m o s t b i t a n d m o v e s r i g h t . S i m i l a r t o t h e a p p r o a c h f o r f r a c t i o n s t h e d i f f e r e n c e i n b i t p o s i t i o n s o f t h e n e i g h b o r i n g 1 s i s u s e d a s w e i g h t s . S i n c e t h e d i r e c t i o n i s f r o m l e f t t o r i g h t t h e w e i g h t s a l l b e c o m e p o s i t i v e p o w e r s o f 2 r a t h e r t h a n n e g a t i v e . T h e d e s i g n e q u a t i o n f o r t h i s e x a m p l e i s :

    X 21 + X = X 1

    X1 22 + X = X 2

    X2 21 + X = X 3

    X3 21 + X = X 4

    X4 23 + X = X 5

    F i n a l r e s u l t = X 5 20.

    T h e f i n a l r e s u l t b e c o m e s t h e r e s u l t X 5 w e i g h t e d b y 2 0 ( t h e b i t p o s i t i o n o f t h e r i g h t m o s t 1 ) .

    T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l i c a t i o n i s z e r o .

    T h e d e s i g n e q u a t i o n s w o u l d s l i g h t l y c h a n g e i f t h e m u l t i p l i e r w a s n e g a t i v e . C o n s i d e r t h e m u l t i p l i e r t o b e

    4 4 1 i n s t e a d f o r t h e s a m e X .

    X = 4 1 = 0 1 0 1 0 0 1 b

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 9

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    10/15

    www.ti.com

    A . 5 E x a m p l e 8 : U n s i g n e d I n t e g e r - F l o a t m u l t i p l i c a t i o n

    E x a m p l e 8 : U n s i g n e d I n t e g e r - F l o a t m u l t i p l i c a t i o n

    T h e d e s i g n e q u a t i o n s n o w b e c o m e :

    X 23 + X = X 1 T h e s i g n b i t c a u s e s t h e o p e r a n d t o b e n e g a t i v e i n t h e f i r s t e q u a t i o n .

    X1 24 + X = X 2

    X2 21 + X = X 3

    X3

    21 + X = X 4

    F i n a l r e s u l t = X 4 20.

    T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l i c a t i o n i s z e r o .

    I f t h e m u l t i p l i e r i s a r e a l n u m b e r w i t h a n i n t e g e r p a r t a n d f r a c t i o n a l p a r t , t h e m e t h o d i s j u s t a c o m b i n a t i o n o f t h e t w o t y p e s d i s c u s s e d s o f a r . T h e a l g o r i t h m i s n o w d i v i d e d i n t o t w o p a r t s , o n e f o r t h e i n t e g e r p a r t o f t h e m u l t i p l i e r a n d t h e o t h e r f o r t h e f r a c t i o n a l p a r t o f t h e m u l t i p l i e r . T h i s a p p r o a c h i s e x p l a i n e d i n E x a m p l e 8 .

    C o n s i d e r t h e m u l t i p l i e r t o b e d e f i n e d a s 4 4 1 . 8 3 7 5 a n d t h e o p e r a n d X i s 4 1 .

    X = 4 1 = 0 1 0 1 0 0 1 b

    M = 4 4 1 . 8 3 7 5 = 0 1 1 0 1 1 1 0 0 1 . 1 1 0 1 0 1 1 0 0 1 b

    T h e f a c t t o n o t e h e r e i s t h a t t h i s m e t h o d i s i n d e p e n d e n t o f w o r d l e n g t h f o r t h e m u l t i p l i e r . T h e o v e r h e a d w o u l d o n l y b e i n t h e n u m b e r o f s h i f t s a n d a d d s t o b e d o n e .

    T h e d e s i g n e q u a t i o n s f o r t h i s e x a m p l e i s g i v e n b y :

    X 21 + X = X 1

    X1 22 + X = X 2

    X2 21 + X = X 3

    X3 21 + X = X 4

    X4 23 + X = X 5

    I n t e r m e d i a t e r e s u l t d u e t o i n t e g e r p a r t = X 5 20.

    X 2 3 + X = X 1

    X1 2 1 + X = X 2

    X2 2 2 + X = X 3

    X3 2 2 + X = X 4

    X4 2 1 + X = X 5

    I n t e r m e d i a t e r e s u l t d u e t o f r a c t i o n a l p a r t = X 5 2 1 .

    A d d i n g t h e a b o v e t w o r e s u l t s g i v e s u s t h e f i n a l s o l u t i o n . T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l y i s j u s t t h e f r a c t i o n a l p a r t a n d i s 0 . 3 3 7 5 L S B .

    T h e p r o c e d u r e i s v e r y s i m i l a r i f t h e m u l t i p l i e r i s a n e g a t i v e r e a l n u m b e r , a s s h o w n i n E x a m p l e 9 .

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 1 0 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    11/15

    www.ti.com

    A . 6 E x a m p l e 9 : S i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h M u l t i p l i e r N e g a t i v e

    M = 4 4 1 . 8 3 7 5 = ~10 0 1 0 0 0 1 1 0 . 0 0 1 0 1 0 0 1 1 1 b

    A . 7 E x a m p l e 1 0 : U n s i g n e d I n t e g e r M u l t i p l i c a t i o n W i t h C S D

    E x a m p l e 9 : S i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h M u l t i p l i e r N e g a t i v e

    C o n s i d e r t h e m u l t i p l i e r t o b e d e f i n e d a s 4 4 1 . 8 3 7 5 , a n d t h e o p e r a n d X i s 4 1 .

    X = 4 1 = 0 1 0 1 0 0 1 b

    T h e d e s i g n e q u a t i o n s f o r t h i s e x a m p l e i s g i v e n b y :

    X 23 + X = X 1

    X1 24 + X = X 2

    X2 21 + X = X 3

    I n t e r m e d i a t e r e s u l t d u e t o i n t e g e r p a r t = X 3 21 .

    X 2 1 + X = X 1

    X1 2 1 + X = X 2

    X2 2 3 + X = X 3

    X3 2 2 + X = X 4

    I n t e r m e d i a t e r e s u l t d u e t o f r a c t i o n a l p a r t = X 4 2 3.

    A d d i n g t h e a b o v e t w o r e s u l t s g i v e s u s t h e f i n a l s o l u t i o n . T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l y i s j u s t t h e f r a c t i o n a l p a r t a n d i s 0 . 6 6 2 5 L S B .

    C o n s i d e r t h e e x a m p l e o f a n i n t e g e r - i n t e g e r m u l t i p l i c a t i o n u s i n g H o r n e r s m e t h o d u s i n g t h e C S D f o r m a t , w i t h t h e o p e r a n d X b e i n g 4 1 a n d m u l t i p l i e r 4 4 1 .

    X = 4 1 = 0 1 0 1 0 0 1 b

    M = 4 4 1 = 0 1 1 0 1 1 1 0 0 1 b = 1 0 0 1 0 0 1 0 0 1 C S D

    T h e d e s i g n e q u a t i o n s a r e

    X1 = X 23 X = 0 0 1 0 1 0 0 1 0 0 0b

    0 0 0 0 0 1 0 1 0 0 1 b

    X1 0 0 1 0 0 0 1 1 1 1 1 b

    X2 = X1 23 X = 1 0 0 0 1 1 1 1 1 0 0 0b

    0 0 0 0 0 0 1 0 1 0 0 1 b

    X2 1 0 0 0 1 1 0 0 1 1 1 1 b

    X3 = X2 23 + X = 1 0 0 0 1 1 0 0 1 1 1 1 0 0 0 b +

    0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 b

    X3 1 0 0 0 1 1 0 1 0 1 0 0 0 0 1 b

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 1 1

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    12/15

    www.ti.com

    A . 8 E x a m p l e 1 1 : U n s i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h C S D F o r m a t

    A . 9 E x a m p l e 1 2 : S i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h M u l t i p l i e r N e g a t i v e i n C S D F o r m a t

    M = 4 4 1 . 8 3 7 5 = 1 0 0 1 0 0 0 1 1 0 . 0 0 1 0 1 0 0 1 1 1 b = ~10 0 1 0 0 1 0 1 0 . 0 0 1 0 1 0 1 0 0 1 C S D

    E x a m p l e 1 1 : U n s i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h C S D F o r m a t

    F i n a l r e s u l t = X 3 = ( 1 0 0 0 1 1 0 1 0 1 0 0 0 0 1 ) b = 1 8 0 8 1 .

    T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l i c a t i o n i s z e r o .

    T h e d e s i g n e q u a t i o n s r e m a i n t h e s a m e i f t h e o p e r a n d X w e r e a n e g a t i v e n u m b e r .

    W h e n t h e m u l t i p l i e r i s a r e a l n u m b e r s a y 4 4 1 . 8 3 7 5 a n d t h e o p e r a n d X i s a p o s i t i v e i n t e g e r s a y 4 1 , t h e d e s i g n e q u a t i o n s b e c o m e :

    X = 4 1 = 0 1 0 1 0 0 1 b

    M = 4 4 1 . 8 3 7 5 = 0 1 1 0 1 1 1 0 0 1 . 1 1 0 1 0 1 1 0 0 1 b = 1 0 0 1 0 0 1 0 1 0 . 0 0 1 0 1 0 1 0 0 1 C S D

    T h e d e s i g n e q u a t i o n s f o r t h i s e x a m p l e i s g i v e n b y :

    X 23 X = X1

    X1 23 X = X2

    X2 22 + X = X 3

    I n t e r m e d i a t e r e s u l t d u e t o i n t e g e r p a r t = X 3 21 .

    X 2 3 X = X1

    X1 2 2 X = X2

    X2 2 2 X = X3

    I n t e r m e d i a t e r e s u l t d u e t o f r a c t i o n a l p a r t = X 3 2 3

    A d d i n g t h e a b o v e t w o r e s u l t s g i v e s u s t h e f i n a l s o l u t i o n . T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l i c a t i o n i s j u s t t h e f r a c t i o n a l p a r t a n d i s 0 . 3 3 7 5 L S B .

    A p o i n t t o b e n o t e d h e r e i s i f t h e r i g h t m o s t b i t i s 1 , t h e d e s i g n e q u a t i o n s s t a r t w i t h a n e g a t i v e X w e i g h t e d a n d a d d e d o r s u b t r a c t e d w i t h X d e p e n d i n g o n t h e n e x t b i t b e i n g 1 o r 1 , r e s p e c t i v e l y .

    C o n s i d e r t h e e x a m p l e i f t h e m u l t i p l i e r w a s n e g a t i v e a n d t h e o p e r a n d X a p o s i t i v e n u m b e r 4 1 w i t h t h e m u l t i p l i e r 4 4 1 . 8 3 7 5 .

    X = 4 1 = 0 1 0 1 0 0 1 b

    T h e d e s i g n e q u a t i o n s a r e :

    X 23 + X = X 1

    X1 23 + X = X 2

    X2 22 X = X3

    I n t e r m e d i a t e r e s u l t d u e t o i n t e g e r p a r t = X 3 21 .

    E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 1 2 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    13/15

    www.ti.com

    E x a m p l e 1 2 : S i g n e d I n t e g e r - F l o a t M u l t i p l i c a t i o n W i t h M u l t i p l i e r N e g a t i v e i n C S D F o r m a t

    X 2 3 + X = X 1

    X1 2 2 + X = X 2

    X2 2 2 + X = X 3

    I n t e r m e d i a t e r e s u l t d u e t o f r a c t i o n a l p a r t = X 3

    2 3.

    A d d i n g t h e a b o v e t w o r e s u l t s g i v e s t h e f i n a l s o l u t i o n . T h e a b s o l u t e e r r o r o b t a i n e d f o r t h i s m u l t i p l i c a t i o n i s j u s t t h e f r a c t i o n a l p a r t a n d i s 0 . 6 6 2 5 L S B .

    S L A A 3 2 9 S e p t e m b e r 2 0 0 6 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 1 3

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    14/15

    www.ti.com

    A p p e n d i x B M S P 4 3 0 C o d e

    B . 1 M S P 4 3 0 C o d e

    A p p e n d i x B

    T h e M S P 4 3 0 c o d e s t h a t i m p l e m e n t m u l t i p l i c a t i o n a n d d i v i s i o n a r e s h o w n b e l o w . F o r s o m e o f t h e s e

    e x a m p l e s , i t c a n b e a s s u m e d t h a t t h e t h e i n c o m i n g o p e r a n d i s a 1 2 - b i t s a m p l e f r o m t h e A D C . T h e c o d e s u s e d a n d t h e i r f u n c t i o n a l i t y a r e g i v e n b e l o w .

    m u l t i p l y _ i n t . c s o u r c e f i l e c a l l i n g f o u r m a t h f u n c t i o n s . A l l t h e f u n c t i o n s p e r f o r m m u l t i p l i c a t i o n o f t w o 1 6 - b i t i n t e g e r s t o g i v e a 1 6 - b i t i n t e g e r r e s u l t . T h e " m a i n ( ) " f u n c t i o n c a l l s e a c h o f t h e s e f u n c t i o n s .

    m u l . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g a n e x i s t i n g s c h e m e f o r i n t e g e r - i n t e g e r m u l t i p l i c a t i o n u s i n g o n l y s h i f t a n d a d d o p e r a t i o n s . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e m u l t i p l y _ i n t . c a n d m u l t i p l y _ f l o a t . c .

    h o r n e r _ m u l _ i n t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e f o r i n t e g e r - i n t e g e r m u l t i p l i c a t i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e m u l t i p l y _ i n t . c .

    c s d _ m u l _ i n t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e u s i n g t h e C S D f o r m a t f o r i n t e g e r - i n t e g e r m u l t i p l i c a t i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e m u l t i p l y _ i n t . c .

    m u l t i p l y _ f l o a t . c s o u r c e f i l e c a l l i n g f o u r m a t h f u n c t i o n s . A l l t h e f u n c t i o n s p e r f o r m m u l t i p l i c a t i o n o f a 1 6 - b i t i n t e g e r w i t h a f l o a t i n g p o i n t n u m b e r t o g i v e a 1 6 - b i t i n t e g e r o r f l o a t r e s u l t . T h e " m a i n ( ) " f u n c t i o n c a l l s e a c h o f t h e s e f u n c t i o n s .

    h o r n e r _ m u l _ f l o a t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e f o r i n t e g e r - f l o a t m u l t i p l i c a t i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e m u l t i p l y _ f l o a t . c .

    c s d _ m u l _ f l o a t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e u s i n g t h e C S D f o r m a t f o r i n t e g e r - f l o a t m u l t i p l i c a t i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e m u l t i p l y _ f l o a t . c .

    d i v _ i n t . c s o u r c e f i l e c a l l i n g f o u r m a t h f u n c t i o n s . A l l t h e f u n c t i o n s p e r f o r m d i v i s i o n o f t w o 1 6 - b i t i n t e g e r s t o g i v e a 1 6 - b i t i n t e g e r r e s u l t . T h e " m a i n ( ) " f u n c t i o n c a l l s e a c h o f t h e s e f u n c t i o n s .

    d i v . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g a n e x i s t i n g s c h e m e f o r i n t e g e r - i n t e g e r d i v i s i o n u s i n g o n l y s h i f t a n d a d d o p e r a t i o n s . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e d i v _ i n t . c a n d d i v _ f l o a t . c .

    h o r n e r _ d i v _ i n t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e f o r i n t e g e r - i n t e g e r d i v i s i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e d i v _ i n t . c .

    c s d _ d i v _ i n t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e u s i n g t h e C S D f o r m a t f o r i n t e g e r - i n t e g e r d i v i s i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e d i v _ i n t . c .

    d i v _ f l o a t . c s o u r c e f i l e c a l l i n g f o u r m a t h f u n c t i o n s . A l l t h e f u n c t i o n s p e r f o r m d i v i s i o n o f a 1 6 - b i t i n t e g e r w i t h a f l o a t i n g p o i n t n u m b e r t o g i v e a 1 6 - b i t i n t e g e r o r f l o a t r e s u l t . T h e " m a i n ( ) " f u n c t i o n c a l l s e a c h o f t h e s e f u n c t i o n s .

    h o r n e r _ d i v _ f l o a t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e f o r i n t e g e r - f l o a t d i v i s i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e d i v _ f l o a t . c .

    c s d _ d i v _ f l o a t . s 4 3 a s s e m b l y s o u r c e f i l e c o n t a i n i n g t h e H o r n e r s s c h e m e u s i n g t h e C S D f o r m a t f o r i n t e g e r - f l o a t m u l t i p l i c a t i o n . T h i s s o u r c e f i l e i s c a l l e d b y f u n c t i o n " m a i n ( ) " i n t h e s o u r c e f i l e d i v _ f l o a t . c .

    T h e s e f i l e s a r e p r o v i d e d a s a z i p f i l e d o w n l o a d a b l e w i t h t h i s a p p l i c a t i o n r e p o r t .

    1 4 E f f i c i e n t M u l t i p l i c a t i o n a n d D i v i s i o n U s i n g M S P 4 3 0 S L A A 3 2 9 S e p t e m b e r 2 0 0 6

    S u b m i t D o c u m e n t a t i o n F e e d b a c k

    http://www.go-dsp.com/forms/techdoc/doc_feedback.htm?litnum=SLAA329
  • 7/28/2019 slaa329

    15/15

    IMPORTANT NOTICE

    Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,

    enhancements, improvements, and other changes to its products and services at any time and to discontinue

    any product or service without notice. Customers should obtain the latest relevant information before placing

    orders and should verify that such information is current and complete. All products are sold subject to TIs terms

    and conditions of sale supplied at the time of order acknowledgment.

    TI warrants performance of its hardware products to the specifications applicable at the time of sale in

    accordance with TIs standard warranty. Testing and other quality control techniques are used to the extent TI

    deems necessary to support this warranty. Except where mandated by government requirements, testing of all

    parameters of each product is not necessarily performed.

    TI assumes no liability for applications assistance or customer product design. Customers are responsible for

    their products and applications using TI components. To minimize the risks associated with customer products

    and applications, customers should provide adequate design and operating safeguards.

    TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right,

    copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process

    in which TI products or services are used. Information published by TI regarding third-party products or services

    does not constitute a license from TI to use such products or services or a warranty or endorsement thereof.Use of such information may require a license from a third party under the patents or other intellectual property

    of the third party, or a license from TI under the patents or other intellectual property of TI.

    Reproduction of information in TI data books or data sheets is permissible only if reproduction is without

    alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction

    of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for

    such altered documentation.

    Resale of TI products or services with statements different from or beyond the parameters stated by TI for that

    product or service voids all express and any implied warranties for the associated TI product or service and

    is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.

    Following are URLs where you can obtain information on other Texas Instruments products and application

    solutions:

    Products Applications

    Amplifiers amplifier.ti.com Audio www.ti.com/audio

    Data Converters dataconverter.ti.com Automotive www.ti.com/automotive

    DSP dsp.ti.com Broadband www.ti.com/broadband

    Interface interface.ti.com Digital Control www.ti.com/digitalcontrol

    Logic logic.ti.com Military www.ti.com/military

    Power Mgmt power.ti.com Optical Networking www.ti.com/opticalnetwork

    Microcontrollers microcontroller.ti.com Security www.ti.com/security

    Low Power Wireless www.ti.com/lpw Telephony www.ti.com/telephony

    Video & Imaging www.ti.com/video

    Wireless www.ti.com/wireless

    Mailing Address: Texas Instruments

    Post Office Box 655303 Dallas, Texas 75265

    Copyright 2006, Texas Instruments Incorporated