42
1 E  C E  3   6   6   C  o m   p  u  t   e r r  c h i    t   e  c  t   u r  e I  n  s  t  r  u  c  t   o r  :  S h  a n  t   a n  u D  u  t   t  D  e   p  a r  t  m  e n  t   o f  E l   e  c  t  r i   c  a l   a n  d  C  o m   p  u  t   e r E n   g i  n  e  e r i  n   g  U n i   v  e r  s i   t    y  o f  I  l  l  i  n  o i   s  a  t   C h i   c  a   g  o L  e  c  t   u r  e  N  o  t   e  s # 1  0  C  O M P  U T E A R I  T M E T I   C  : I   t   e   g  e r A  d  d i   t  i   o  a n  d M  u l   t  i    p l  i   c  a  t  i   o n  c  S h  a  t   a n  u  u  t   t   ,  U I   C 1 

Integer Add and Mult

Embed Size (px)

Citation preview

Page 1: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 1/42

E  CE  3   6   6  

 C om  p u t   e r Ar  c h i    t  

 e  c  t   ur  e 

I  n s  t  r  u c  t   or  :  S h  a n t   a n uD u t   t  

D e   p a r  t  m e n t   o

f  E l   e  c  t  r i   c  a l   a n d  C  om  p u t   e r E n  gi  n e  e r i  n  g

 Uni   v e r  s i   t    y of  I  l  l  i  n oi   s  a  t   C h i   c  a   g o

L  e  c  t   ur  e  N o t   e  s # 1  0 

 C  O

MP  UT E RARI  T H

ME T I   C  : 

I  n t   e   g e r A d  d i   t  i   on a n d M ul   t  i    pl  i   c  a  t  i   on

 c   

 S h  a n t   a n uD u t   t   , UI   C 

Page 2: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 2/42

ADDE R S 

¡

F  ul  l  A d  d  e r F A : 

Y i  

X i  

 C i   +1 

 C i  

 S i  

F A i  

I  n  p u t   s 

¢

£

¤

¥

£

¤ ¦

£

 O u t    p u t   s  a r  e 

¨

£

¤¦

£

©

 , w

h  e r  e ¨

£

¢

£

¥

£

¦

£

¦

£

©

¢

£

¥

£

¦

£

¢

£

¦

£

¥

£

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

Page 3: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 3/42

 3 

Ri     p  pl    e - C ar r   yA d  d  e 

r  (  R CA )  

F A 0     y

 0  

x 0  

 c  0  

  y1  

x1  

 c 1  

F A1  

x2  

  y2  

F A2  

 c 2  

 c  3  

  y 3  

x 3  F 

A 3  

 c 4  

  y4  

x4  F 

A4  

 c  5  

  y 5  

x 5  

F A 5  

 c  6  

  y 6  

x 6  F 

A 6  

F A 6  

 c  7  

  y 7  

x 7  

 c  o u t   

 S  7  

 S  6  

 S  5  

 S 4  

 S  3  

 S 2  

 S 1  

 S  0  

P r  o b l   e m : D e l   a   yi   s 

  g a  t   e  d  e l   a   y s  or 

— e  a  c h F Ah  a  s  a 2 -  g a  t   e  d  e l   a   y .T h  u s 

i   s  e  a  c h 

  g a  t   e h  a  s  a  d  e l   a   y of  2 n s  , d  e l   a   yf   or  a  3 

2 - b i   t  R C Ai   s  6 4 n s  .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3 

Page 4: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 4/42

 O v e r fl  o wi  nA d  d 

i   t  i   on

¡

 O v er   fl   o w o c  c  ur  s  wh  e n

 t  h  e r  e  s  ul   t   of   t  h  e  o  p e r  a  t  i   on d  o e  s n o t  fi 

 t  i  n t  h  e r  e   pr  e -

 s  e n t   a  t  i   on b  e i  n  g u s  e  d 

¡

F  or 

 e x a m  pl   e  ,i  f  4 - b i   t  

 un s i    gn e  d n um b  e r  s  6 =

!

!

"

 a n d 1 2 =!

!

"

 a r  e 

 a  d  d 

 e  d  t  h  e  s  um (  1  8  )   o v

 e r fl  o w s  s i  n c  e i   t   s  b i  n a r   y e   q ui   v a l   e n t  

!

!

"

 d  o e  s n o t  

fi  t  i  n4  b i   t   s 

¡

 O v e r fl  o wi   s  d  e  t   e  c  t   e  d f   or  un s i    gn e  d  a  d  d i   t  i   on wh  e n t  h  e  c  a r r   y

 o u t  ¦

#

 of   t  h  e 

fi n a 

l  F  ul  l  A d  d  e r i   s 1 

¡

F  or 

2 ’   s  c  om  pl   e m e n t  r  e   pr  e  s  e n t   a  t  i   on of   s 

i    gn e  d n um b  e r  s  o v

 e r fl  o w o c  c  ur  s 

 wh  e n t  h  e  c  a r r   yi  n t   o t  h  e M S B (  m o s  t   s i    gni  fi  c  a n t   b i   t   )   , wh i   c h i   s  a l   s  o t  h  e  s i    gn

 b i   t   ,

i   s  d i  f  f   e r  e n t  f  r  om t  h  e  c  a r r   y o u t   of   t  h  a 

 t   b i   t   .T h  e  c  a r r   y o u t   of   t  h  e M S B

 a l   w a   y s r  e   pr  e  s  e n t   s  t  h  e  s i    gn b i   t   of   t  h  e  s i    gn- e x t   e n d  e  d 

!

 b i   t  r  e   pr  e  s  e n t   a  t  i   on

 of   t  h  e  s  um

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

Page 5: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 5/42

 5 

ADDE R S  (   C  on

 t   d  . )  

 S   p e  e  d i  n  g u  p a  d  d 

i   t  i   on

¡

Af   a  s  t   e r  a  d  d  e r  : T h  e  t  r  a  d i   t  i   on a l   c  a r r   y-l   o ok  a h  e  a  d  a  d  d  e r  (   C L A

 )   : 

D e fi n e  t   w o e x t  r  a f   un c  t  i   on s  : 

$

£

¢

£

¥

£

%

£

¢

£

¥

£

Y i  

X i  

 S i F 

A i  i  

i   G

i   C 

T  o c  ar r  y − g en.

l   o gi   c 

F r  om  c  ar r  y −

 g en.

l   o gi   c 

¡

$

£

i   s  t  h  e   g e n er  a t   e b i   t   , wh i   c h i   s 1  onl    yi  f   a  c  a r r   y o u t  i   s  t   o

 b  e   g e n e r  a  t   e  d 

i  r r  e  s   p e  c  t  i   v e  of   t  h  e i  n  p u t   c  a r r   y .T h i   s  o b  vi   o u s l    yi   s  t  h  e  c  a  s  e  onl    y wh  e n

¢

£

¥

£

!

¡

%

£ i   s  t  h  e   pr  o  p a  g a t   e b i   t   , wh i   c h i   s 1  onl    yi  f   t  h  e  o u t    p u t   c  a r r   yi   s  t   o b  e  t  h  e  s  a m e 

 a  s  t  h  e i  n  p u t   c  a r r   y ,i   . e  . ,

¦

£

©

¦

£ .T h i   s  wi  l  l   b  e  t  h  e  c  a  s  e  onl    y wh  e n e i   t  h  e r 

¢

£

 or ¥

 (   b  u t  n o t   b  o t  h  )  i   s 

¡

T h  u

 s  t  h  e  c  a r r   y o u t  

¦

£

©

 of   t  h  e 

' t  h  s  t   a   g e 

 c  a n b  e  e x  pr  e  s  s  e  d 

 a  s  : ¦

£

©

$

£

%

£

¦

£

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 5 

Page 6: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 6/42

 6 

T r  a  d i   t  i   on a l   C L AA d  d  e r  (   C  on t   d  . )  

¡

 C  on s i   d  e r  a 4 - b i   t   a  d  d  e r  : 

 N o t   e  t  h  a  t  

$

£ a n d %

£ c  a n b  e   g e n e r  a  t   e  d i  n c  on s  t   a n t   t  i  m e  (   s   p e  c i  fi  c  a l  l    y ,1   g a  t   e 

 d  e l   a   y )   b   y e  a  c h m o d i  fi  e  d f   ul  l   a  d  d  e r  (  MF A

 )   .

¦

$(

%

(

¦

(

¦

"

$

%

¦

$

%

$ (

%

(

¦

(

$

%

$(

%

%

(

¦

(

¦

)

$

"

%

"

¦

"

$

"

%

"

$

%

"

%

$ (

%

"

%

%

(

¦

(

¦

0

$

)

%

)

¦

)

$

)

%

)

$

"

%

)

%

"

$

%

)

%

"

%

$ (

%

)

%

"

%

%

(

¦

(

T h  e 

¦

£ s  a r  e   g e n e r  a  t   e  d  b   y a  c ar r   y-  g e n er  a t   i    o n u n i    t   a  s  s h  o wn b  e l   o w .

X  S 

 G  C 

X  S 

F A 

 G  C 

X  S 

F A 

 G

X  S 

F A 

 G  C  0   0 

 0 

 0 

 0 

 0 

 0 

 3  3 

 3 

 3 

 3  3 

 C  3 

 C 4 

 C A R R Y  GE N E R A T I   O

N L  O GI   C 

¡

I  n t  h i   s  C L A t  h  e 

¦

£ s  u s  e 

2 -l   e  v e l  l   o  gi   c  a n d  t  h  u s h  a  v e  a  d  e l   a   y of   3   g a  t   e  d  e l   a   y s 

 (  1 f  

 or  e  a  c h $

£

¤

%

£ , a n d 2 f   or  t  h  e 

¦

£ ’   s  )   , a  s  o

  p  p o s  e  d  t   o

1

2   

3

  g a  t   e  d  e l   a   y s 

f   or  a 4 - b i   t  R C A .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 6 

Page 7: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 7/42

 7 

T r  a  d i   t  i   on a l   C L AA d  d  e r  (   C  on t   d  . )  

¡

Di   s  a  d  v a n t   a   g e  : F  or  a 1  6 - b i   t   a  d  d  e r  ,f   or  e x a m  pl   e  , w e  c  a nn o t    g o on  g e n e r -

 a  t  i  n

  g t  h  e ¦

£ s i  n t  h i   s m

 a nn e r  , s i  n c  e  t  h  e h  a r  d  w a r  e  b  e  c  om e  s  s 

 e x e  c  s  s i   v e  a n d 

m e  s  s   y

¡

A1 

 6 - b i   t   a  d  d  e r  c  a n b  e 

  p a r  t  i   t  i   on e  d i  n t   o  gr  o u  p s  of  4 4 - b i   t   C L A a  d  d  e r  s  , wi   t  h 

 t  h  e 

i  n t   e r -  gr  o u  p c  a r r i   e  s 

r i    p  pl  i  n  g t  h r  o u  gh  t  h  e f   o ur   gr  o u  p s  : 

 C  0 

4 − b i   t   C L A 

 S  3 − 0 

X  3 − 0 

Y  3 − 0 

 C 4 

4 − b i   t   C L A 

 S 

 C 

4 − b i   t   C L A 

 S 

 C 

4 − b i   t   C L A 

 C 

7 −4 

7 −4 

7 −4 

1 1 − 8  1 

1 − 8 

1 1 − 8 

1  5 −1 2 

1  5 −1 2 

 S 1  5 −1 2 

 8 

1 2 

1  6 1 

 6 

 S =

¡

 S  u c 

h  a 1  6 - b i   t   a  d  d  e r h  a  s  a  d  e l   a   y of  1 2   g a  t   e 

 d  e l   a   y s  (  =2 4 n s f   or 

 a   g a  t   e  d  e l   a   y of  

2 n s  )   a  s  o  p  p o s  e  d  t   o a  d 

 e l   a   y of  

1

!

4

= 3 2   g a  t   e  d  e l   a   y s  (  =

1

5

= 6 4 n s  )  i  n

 a 1  6 - b i   t  R C A

¡

I  n  g

 e n e r  a l  f   or  a n

- b i   t    gr  o u  p- C L A a  d  d  e r  wi   t  h 4 - b i   t   C L A c  e l  l   s  , t  h  e  d  e l   a   y

i   s 5

6

2   

  g a  t   e  d  e l   a   y s  a  s  o  p  p o s  e  d  t   o

  g a  t   e 

 d  e l   a   y s f   or  t  h  e r i    p  p

l   e - c  a r r   y a  d  d  e r 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 7 

Page 8: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 8/42

 8 

T r  a  d i   t  i   on a l   C L AA d  d  e r  (   C  on t   d  . )  

¡

An

 o t   e  of   c  a  u t  i   on : 

7

-i  n  p u t    g a  t   e  s h  a  v e   gr  e  a  t   e r  d  e l   a   y s  t  h  a n

2 -i  n  p u t    g a  t   e  s 

f   or 7

8

 . W e h  a  d  a  s  s  um e  d  t  h  a  t  f   or  a 

4 - b i   t   C L A t  h  e  5 -

i  n  p u t   OR a n d 

A N

D  g a  t   e  s h  a  v e  t  h  e  s  a m e  d  e l   a   y a  s  a 2 -i  n

  p u t    g a  t   e  .

¡

T h  e 

 d  e l   a   y of   a  5 -i  n  p u t    g a  t   e  wi  l  l   b  e   gr  e  a  t   e r  b  e  c  a  u s  e  : 

V  d  d 

 Gn d 

V  d  d 

A B 

A B 

A B 

A B 

A B  C D 

V  d  d 

 Gn d 

V  d  d 

A B  C D E 

 C 

A B  C D E 

A B  C D E 

A B 

 C 

A  +B  + C  +D  +

 s 

 (   c  )   5 −

i   /   p OR 

 u s i  n g2 −i   /   p g a t   e s :  d  el   a y =4  t   +7 R  C 

 s 

 (   a )  2 

−i   /   p OR 

 g a t   e:  d  el   a y =2  t   + 3 R  C 

 s 

 (   b  )   5 −i   /   p OR 

 g a t   e:  d  el   a y =2  t   + 6 R  C 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 8 

Page 9: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 9/42

 9 

T r  a  d i   t  i   on a l   C L AA d  d  e r  (   C  on t   d  . )  

¡

L  e  t  

9

@

 b  e  t  h  e m a x . of   t  h  e  s  wi   t   c h i  n  g on

 a n d  t  h  e  s  wi   t   c h i  n  g

 of  f   t  i  m e  of   a 

M O

 S  t  r  a n s i   s  t   or  ,i   . e  . , t  h  e m a x . of   t  h  e  t  i  m e f   or  c h  a r   g e  t   o

 c  ol  l   e  c  t   a  t   t  h  e 

 c h  a nn e l   or  t  h  e  t  i  m e f   or  t  h  e  c h  a r   g e  t   o b  e r  e m o v e  d f  r  om t  h  e  c h  a nn e l  

¡

L  e  t  

A

 b  e  t  h  e r  e  s i   s  t   a n c 

 e  of   a  c h  a nn e l   , a n d 

B

6

 t  h  e i  n  p u t    g a  t   e  c  a   p a  c i   t   a n c  e 

 of   a 

 t  r  a n s i   s  t   or 

¡

T h  e 

n , a 2 -i   /    pA ND /   OR  g a  t   e h  a  s  a  d  e l   a   y of  

9

@

5

A

B

 a  5 -i   /    p  g a  t   e h  a  s  a  d  e l   a   y of  

9

@

4

A

B

 wh i  l   e  a  5 -i   /    pA ND /   OR c k  t   .f   or m e  d  of   c  a  s  c  a  d  e  d 2 -i   /    p  g a  t   e  s  wi  l  l  h  a  v e  a 

 d  e l   a   y of  

2   

9

@

C

A

B

¡

T h  u

 s  , wh i  l   e  a  5 -i   /    pA

 ND /   OR  g a  t   e  wi  l  l   b  e  s l   o w e r  t  h  a n a 2 

-i   /    pA ND /   OR

  g a  t   e  ,i   t   wi  l  l   b  e f   a  s  t   e r  t  h  a n a  c  a  s  c  a  d  e  d i  m  pl   e m e n t   a  t  i   on of   a  5 

-i   /    pA ND /   OR

 c k  t   .T h  e l   a  t   t   e r i   s   pr i  m a r i  l    y b  e  c  a  u s  e m or  e 

 t  r  a n s i   s  t   or  s  s  wi   t   c h 

 oni  n  p a r  a l  l   e l  

i  n a 

 5 -i   /    pA ND /   OR  g a 

 t   e  t  h  a ni  n a  5 -i   /    pA

 ND /   OR c k  t   .

Page 10: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 10/42

1  0 

¡

I  n a 4 - b i   t   C L A a  d  d  e r  , w e  a r  e  e  s  s  e n t   a l  l    y

r  e   pl   a  c i  n  g a  s  e r i   e  s  of  2 -i   /    p c  a  s -

 c  a  d  e  d  (  m ul   t  i  -l   e  v e l   )  l   o  gi   c  b   y a m ul   t  i    pl   e -i  n  p u t  2 -l   e  v e l  l   o  gi   c 

¡

 N o t   e  t  h  a  t   t  h  e  d  e l   a   y of  

 a n

- b i   t    gr  o u  p- C L 

A a  d  d  e r  wi   t  h 4 - b i   t   c  e l  l   s  wi  l  l   b  e 

 s  om

 e  wh  a  t  m or  e  t  h  a n

5

6

2   

2 -i   /    p  g a  t   e  d  e l   a   y s  .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  0 

Page 11: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 11/42

1 1 

F  a  s  t   e r  a  d  d  e r  s 

¡

 C  a n

 w e  d  o b  e  t   t   e r  t  h  a n

 a  d  e l   a   y t  h  a  t  i   s l  i  n e 

 a r i  n t  h  e n um b  e r  o

f   b i   t   s 

 ?  

¡

Y e  s 

 , b   y u s i  n  g a  c ar r   y- s 

 e l    e c t   a  d  d  e r  (  

D

 t  i  m e  )   , OR b   y u s i  n  g a   p ar  a l    l    e l   

  pr  e  fi  

 x c i  r  c  ui   t   t   o  g e n e r  a  t   e  a l  l   c  a r r i   e  s i  n t  i  m

 e 

E

G

H

¡

 C  a r 

r   y- S  e l   e  c  t   a  d  d  e r  : 

 c i  n

 0 1 

A  d  d 

M ux 

A  d  d 

 c i  n

 c i  n

 c  o u t  

 0 1 

A  d  d 

M ux 

A  d  d 

 c i  n

 c  o u t  

n−1 

 s n

 c i  n

 c  o u t  

 0 1 

A  d  d 

M ux 

A  d  d 

 c i  n

 c  o u t  

 c i  n

 c  o u t  

A  d  d 

 s  0 

 0 

 0 

 , y 

n−1 

 , y 

¡

I  f    g

r  o u  p s i  z  e i   s 

¢ , t  i  m e  t   a k  e ni   s 

¢

6

¢ I

 (  2 -i   /    p )    g a  t   e  d  e l   a   y s 

¡

F  or 

¢

Q

 , t  h  e  t  i  m

 e mi  ni  mi  z  e  s  t   o

2   

D

I

2   

2   

D

 (  2 -i   /    p )    g a  t   e 

 d  e l   a   y s 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1 1 

Page 12: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 12/42

1 2 

T h 

 e   p a r  a l  l   e l  -  pr  e fi x C 

L A a  d  d  e r 

¡

F  or 

 t  h  e ' t  h f   ul  l   a  d  d  e r  , d  e fi n e  t  h  e  s   ym b  ol   s 

R : k 

i  l  l  i  n c  omi  n  g c  a r r   y

 (   wh  e n¢ S

£

¥

S

£

!

 )  

% :   p

r  o  p a   g a  t   e i  n c  omi  n  g c  a r r   y (   wh  e n

¢

£

¥

£

!

 )  

$ :   g

 e n e r  a  t   e  a  c  a r r   y (   wh  e n

¢

£

¥

£

!

 )  

 W e 

 c  a n e n c  o d  e  t  h  e  s  e 

 s   ym b  ol   s  a  s 

R

¤

%

!

¤

$

!

 a n d  c  a l  l   t  h  e  s  e 

  p a i  r  of   b i   t   s 

U

£ .E  a  c h F A c  a n  pr  o d  u c  e 

U

£ i  n

 c  on s  t   a n t   t  i  m e 

¡

A s 

 a m a  t   t   e r  of  f   a  c  t   ,

U

£

$

£

¤

%

£ , wh  e r  e 

$

£

 a n d %

£

 a r  e  t  h  e 

  g e n e r  a  t   e  a n d 

  pr  o  p a   g a  t   e  b i   t   s  of   a F A

 d i   s  c  u s  s  e  d  e  a r l  i   e r 

¡

D e fi n e  o  p e r  a  t   or 

V a  s  : 

U

£

 !  

R

%

$

R

R

R

R

U

£

©

%

R

%

$

$

$

$

$

¡

 N o t   e  t  h  a  t  

Vi   s  a n a s  s  o c i    a t   i    v e o  p e r  a  t   or  ,i   . e  . , W

V

Y

V

¦

W

V

Y

V

¦

¡

Al   s  o ,Vi   s n o t   a  c o m m u t   a t   i    v e o  p e r  a  t   or  ,i   . e 

 . ,WV

Y

`

Y

V

W

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1 2 

Page 13: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 13/42

1  3 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

¡

D e fi n e 

a

£ f   or  t  h  e 

' t  h  s  t   a   g e  a  s 

a

£

U

£

V

U

£ b

V d

d

d

V

U

(

a

£ i   s  t  h  e 

' t  h   pr  e  fi   x of   t  h  e  a  s  s  o c i   a  t  i   v e  c  om  p u t   a  t  i   on : 

U

#

b

V

U

#

b

"

V d

d

d

V

U

(

¡

I  f   w

 e  c  a n c  om  p u t   e  e  a  c 

h a

£  q ui   c k l    y , t  h  e n w e  c  a n o b  t   a i  n t  h  e  c 

 a r r   y-i  n¦

£

©

 of  

 t  h  e 

'

!

 t  h F A a  s f   ol  

l   o w s  : 

I  f  a

£

R

 t  h  e n¦

£

©

 e l   s  e 

i  f  a

£

%

 t  h  e n¦

£

©

¦

(

 e l   s  e 

i  f  a

£

$

 t  h  e n¦

£

©

!

¡

T h  e 

¦

£ ’   s  c  a n b  e  c  om  p u

 t   e  d i  n c  on s  t   a n t   t  i  m

 e  a f   t   e r  t  h  e 

a

£ ’   s  a r  e 

 a  v a i  l   a  b l   e 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  3 

Page 14: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 14/42

1 4 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

 C  om  p u

 t  i  n  g t  h  e 

a

£ ’   s   q ui   c k l    y : 

¡

D e fi n e 

a

£

f

g

 a  s 

a

£

f

g

U

£

V

U

£ b

Vd

d

d

V

U

g

T h  u

 s  ,a

£

a

£

f

(

¡

 S i  n c  e 

Vi   s  a  s  s  o c i   a  t  i   v e  , w e h  a  v e 

a

£

f

g

a

£

f h

V

a

h

b

f

g  .

i  

k −1 

 j  

!  

r i   ,k 

r k −1  , j  

r i   , j  

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1 4 

Page 15: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 15/42

1  5 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

¡

 W e 

 c  a n u s  e  t  h  e  a  b  o v e   pr  o  p e r  t    y t   of   or m1 -l   e  v e l  

a

£

f

g ’   s  b   y c  om

 b i  ni  n  g2  a  d   j   a -

 c  e n t  U

£ ’   s  , t  h  e n2 -l   e  v e l  

a

£

f

g ’   s  b   y c  om b i  ni  n  g t   w o a  d   j   a  c  e n t  1 -l   e  v e l  

a

£

f

g ’   s  , e  t   c  .

T h i   s   yi   e l   d  s  a  t  r  e  e - s  t  r  u c  t   ur  e  d  c i  r  c  ui   t   wi   t  h 

 a Vl   o  gi   c  a  t   e  v e r   yn o d  e  ;  t  h i   s  c k  t   .

  gi   v e  s  u s  onl    y t  h  o s  e 

a

£ ’   s f   or  wh i   c h 

'

p

I

!

f   or  s  om e 

r

!  

!  

!  

!  

 q 0 

 q

 q

 q

 3 

!  

!  

!  

 q

 q

 q

 q

 5 

 6 

7  ,4 

7  , 6 

 5  ,4 

 3  ,2 

7  , 0 

 3  , 0 

1  , 0 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  5 

Page 16: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 16/42

1  6 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

¡

T  o o b  t   a i  n a l  l  

a

£ ’   s  , t  h  e  t  r  e  e h  a  s  t   o b  e  a  u  gm

 e n t   e  d  a  s  s h  o wn b  e 

l   o w .

 q 0 

 q

 q

 q2 

 3 

 q

 q

 q

 5 

 q 6 

7  ,4 

7  , 6 

 5  ,4 

r  3 

 ,2 

7  , 0 

r  3  , 0 

1  , 0 

!  !  

!  !  

!  !  

!  !  

!  !  

 p

!  

r  3  , 0 

r 1  , 0 

r  5  , 0 

r  6  , 0 

4  , 0 

2  , 0 

!  !  

!  !  

 a

 b 

 c 

x  y 

!  

!  

 a

 b 

 c 

 y 

L  e g en d : 

¡

T h i   s  c i  r  c  ui   t  i   s  c  a l  l   e  d  a 

  p a r  a l  l   e l    pr  e fi x c i  r  c 

 ui   t   , a n d  c  a n b  e  u s  e  d  t   o o b  t   a i  n t  h  e 

  pr  e fi x e  s  of   a n  y a  s  s  o c i   a  t  i   v e  o  p e r  a  t  i   on (  l  i  k  e A ND , OR , a  d  d i   t  i   on ,m ul   t  i    pl  i  -

 c  a  t  i   on , e  t   c  . )  

¡

T h  e 

 d  e l   a   yi   s 

E

G

H

I

!

V-l   o  gi   c  s  t   e   p s  ,

E

G

H

 s  t   e   p s  t   o  g o u  p t  h  e  t  r  e  e  a n d 

E

G

H

I

!

 s  t   e   p s  t   o c  om

 e  d  o wn

¡

E x t  r  a h  a r  d  w a r  e  u s  e  d  : 

s

u

v

#

I

!

I

!

I

!

I

!

Vl   o  g

i   c  uni   t   s 

¡

 VL  S I   a r  e  a r  e   q d  . : 

E

G

H

–h  e i    gh  t   of   t  r  e  e i   s 

E

G

H

 , wi   d  t  h  of   t  r  e  e i   s 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  6 

Page 17: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 17/42

1  7 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

An o t  h  e r  VL  S I  i  m  pl   e m e n t   a  t  i   on of   a   p a r  a l  l   e l  

  pr  e fi x t  r  e  e  : 

 q 0 

 q

i   q

i   +1 

r i   +

1  ,i  

 qn−1 

n−1 

r  0 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  7 

Page 18: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 18/42

1  8 

T h  e   p a 

r  a l  l   e l  -  pr  e fi x C L A a  d  d  e r  (   c  on t   d  . )  

T h  e fi n

 a l  h  a r  d  w a r  e  : 

F A 

F A 

F A 

F A 

 S 

 S 

 S 

 S 

 S 

 C 

 C 

 C 

i n

 C  0 

 C 

 o u t

 C 

Y  0 

 0 

Y 1 

Y 2 

Y 1 4

1 4

Y 1  5

1  5

P  ar  al  l   el  P r  ef  i  x M o d  ul   e

   q

   q

   q

1 4

1 4

   q

1  5

1  5

   q2 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  8 

Page 19: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 19/42

1  9 

 C O

MP  UT E RARI  T HME T I   C

 S  UBT RA C T I   O N

¡

 S  u b 

 t  r  a  c  t  i   onw

I

x

 c  a n b  e  d  on e  u s i  n  g a n a  d  d  e r  , s i  n c  e 

w

I

x

w

I

x

¡

T h i   s m e  a n s  t  h  a  t  

x

 , wh i   c h  w e  a  s  s  um e i   s 

i  n2 ’   s  c  om  pl   e m e n t  n o t   a  t  i   on ,h  a  s 

 t   o b 

 e n e   g a  t   e  d  .A2 ’   s  c  om  pl   e m e n t  n um b  e r i   s n e   g a  t   e  d  b   y c  om

  pl   e m e n t  i  n  gi   t  

 a n d 

 a  d  d i  n  g a 1  ,i   . e  . ,I

x

y

x

!

¡

T h  e 

 a  u  gm e n t   a  t  i   on t   o a 

n a  d  d  e r  t   o  p e r f   or m

 s  u b  t  r  a  c  t  i   oni   s  s h  o

 wn b  e l   o w : 

 C i  n

 C  o u t  

 S  u b  t  r  a c  t   /  A  d  d 

=1  /   0 

F r  om  C  on t  r  ol    U ni   t  

n

n

1  n

n

n− b i   t  A  d  d  er 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

1  9 

Page 20: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 20/42

2  0 

 C O

MP  UT E RARI  T HME T I   C

M UL T I  P L I  E R

 S 

 S  e r i   a l  M ul   t  i    pl  i   c  a  t  i   on

A d  d - a n d - s h i  f   t   (  A & S  )  m ul   t  i    pl  i   c  a  t  i   on : 

M a n u a 

l  E x a m  pl   e  : 

I  f   t  h  e  a 

 d  d i   t  i   on s  a r  e  d  on e  on e  a  t   a  t  i  m e  , w e  o

 b  t   a i  n a  s  e   q u e n c  e  o

f    p a r  t  i   a l    pr  o d -

 u c  t   s 

(

¤

¤

¤

#

Page 21: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 21/42

2 1 

E  a  c h   p

 a r  t  i   a l    pr  o d  u c  t  

£

©

i   s  o b  t   a i  n e  d  a  s 

(

£

©

£

£

¢

£

d

x

T h  u s 

#

#

b

£

(

£

¢

£

d

x

x

d

#

b

£

(

£

¢

£

x

d

w

 wh  e r  e w

i   s  t  h  e m ul   t  i    pl  i   e r 

 a n d x

 t  h  e m ul   t  i    pl  i   c  a n d 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2 1 

Page 22: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 22/42

2 2 

A

 & S m ul   t  i    pl  i   c  a  t  i   on

 (   c  on t   d  . )   : 

T h  e  s  a m e  e f  f   e  c  t   a  s  s h i  f   t  i  n  g t  h  e m ul   t  i    pl  i   c  a n d l   e f   t   (  

£

¢

£

x

 )   c  a 

n b  e  a  c h i   e  v e  d 

 b   yk  e  e   pi  n  g t  h  e m ul   t  i    pl  i   c  a n d fi x e  d  a  t   t  h  e l   e f   t  -m o s  t    p o s i   t  i   on a n

 d  s h i  f   t  i  n  g t  h  e 

  p a r  t  i   a l  

  pr  o d  u c  t  

£ r i    gh  t   .

E x a m  p

l   e  : 

I  n t  h i   s 

 c  a  s  e  , t  h  e   p a r  t  i   a l    pr  o d  u c  t   s  o b  t   a i  n e  d  a r  e  : 

(

¤

£

©

b

£

#

¢

£

x

H o w e  v

 e r  ,

#

i   s  t  h  e  s  a m e  : 

#

#

b

£

(

£

¢

£

x

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2 2 

Page 23: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 23/42

2  3 

A

 & S m ul   t  i    pl  i   c  a  t  i   on

 (   c  on t   d  . )   : 

H a r  d  w a r  e  : 

1  6 − b i   t  A  d  d  er 

A  c  c  um ul   a t   or 

 Q

M

A n d 

 C  o u t  

1  6 

1 1  6 

1  6 

1  6 

M ul   t  i   pl  i   er X 

M ul   t  i   pl  i   c  an d Y 

A  d  d −

 an d − sh i  f   t  m ul   t  i   pl  i   c a t  i   onf   or  un

 si   gn e d n um b  er  s

 C  o u t  

R  e g.

Al    g or i   t  h m : 

I  ni   t  i   a l  i  z  e A C = 0  ;  Q=M ul   t  i    pl  i   e r  ; M=M ul   t  i    pl  i   c  a n d  .

D o t  h  e 

f   ol  l   o wi  n  g s  t   e   p s 

 t  i  m e  s 

I  f  L  S B

 of   Qi   s 1  t  h  e nA C 

=A C +M e l   s  e A C 

=A C  ; 

 S h i  f   t  

B

-A C - Qr  e   gi   s  t   e r  c  om b i  n a  t  i   onr i    gh  t   b   y1  b i   t  

F i  n a l    p

r  o d  u c  t  i   s i  nA C - Q

r  e   gi   s  t   e r 

 N OT E  :  O v e r fl  o w s  a r  e  t   ol   e r  a  t   e  d i  n t  h  e  a  d  d i   t  i   on s —

B

i   s f   e  d  t   o t  h  e M S B of  

A C  wh 

 e nr i    gh  t   s h i  f   t  i  n  g

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  3 

Page 24: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 24/42

2 4 

A & S 

2 ’   s  c  om  pl   e m e n t  m

 ul   t  i    pl  i   c  a  t  i   on

A s  s  um

  p t  i   on : B o t  h 

w

 a n d x

 a r  e i  n t  h  e i  r 2 ’   s  c  om  pl   e m e n t  r  e   pr  e  s  e n t   a  t  i   on

M e  t  h  o d 1  : 

¡

I  f  m

 ul   t  i    pl  i   e r w

i   s - v e 

  g e  t  i   t   s 2 ’   s  c  om  pl   e m e n t   s  o t  h  a  t  i   t   b  e  c  om e  s   p o s i   t  i   v e  ,

i   . e  .w

I

w

¡

I  f  m

 ul   t  i    pl  i   c  a n d x

i   s - v e   g e  t  i   t   s 2 ’   s  c  om  pl   e 

m e n t   s  o t  h  a  t  i   t   b  e  c  om e  s   p o s i   t  i   v e  ,

i   . e  .x

I

x

¡

M ul   t  i    pl    y

w

x

¡

I  f   e x a  c  t  l    y on e  of  

w

 a n d x

 w a  s n e   g a  t  i   v e  ,  g e  t  

’   s 2 ’   s  c  om  pl   e m e n t   s  o t  h  a  t  

i   t   b  e  c  om e  s n e   g a  t  i   v e  ,i   . e  .

I

¡

Di   s  a  d  v a n t   a   g e  : P r  e   pr  o

 c  e  s  s i  n  g a n d   p o s  t    pr  o c  e  s  s i  n  g c  a n t   a k  e 

 u  p t   o4  c l   o c k 

 c   y c l   e  s  (   c  c ’   s  )  

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2 4 

Page 25: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 25/42

2  5 

A & S 2 ’   s  c 

 om  pl   e m e n t  m ul   t  i    p

l  i   c  a  t  i   on (   c  on t   d  . )   : 

M e  t  h  o d 2  : 

¡

 Wh 

 e n t  h  e m ul   t  i    pl  i   e r 

w

i   s + v e   p e r f   or m

w

x

 t   a k i  n  g c  a r  e  t   o d  o t  h  e 

f   ol  l   o wi  n  g wh  e n e  a  c h 

£

i   s  s h i  f   t   e  d r i    gh  t   : 

1  . Wh  e n t  h  e r  e i   s n o o v

 e r fl  o wi  n t  h  e  a  d  d i   t  i   on (  r  e  c  a l  l   t  h  e  c  on d 

i   t  i   onf   or  o v e r -

fl  o wf   or 2 ’   s  c  om  pl   e 

m e n t   a  d  d i   t  i   on )   , a n

 ar  i    t   h   m e t   i    cr  i     g h   t   s  h  

 i     f    t   of  r  e   gi   s  t   e r 

A C  . Qi   s   p e r f   or m e  d 

 wi   t  h  o u t   s h i  f   t  i  n  gi  n

B

i  n t   o t  h  e M S B of  A C 

2  .Ar i   t  h m e  t  i   c r i    gh  t   s h 

i  f   t   : M S Bi   s  s i    gn- e x t   e n d  e  d  ,i   . e  . ,i  f   t  h  e M S B (   s i    gn

 b i   t   )  i   s 1  a 1 i   s  s h i  f   t   e  d i  n t   o t  h  e M S B of  A C  , o t  h  e r  wi   s  e  a  0 

i   s  s h i  f   t   e  d i  n

 3  .I  f   t  h  e r  e i   s  a n o v e r fl  o w , t  h  e n a  s i  n t  h 

 e  un s i    gn e  d  c  a  s  e  , s h i  f   t  

B

i  n t   o

M S B of  A C  wh  e n s h i  f   t  i  n  gA C  . Qr i    gh  t   .

T h i   s  w or k  s  b  e  c  a  u s  e i  n t  h i   s  c  a  s  e  t  h  e 

!

 b i   t   o u t    p u t   of   t  h  e  a  d  d  e r  , wh  e r  e 

B

i   s  t  h  e M S B ,i   s  t  h  e  e x a  c  t  2 ’   s  c  om  pl   e m e n t  r  e   pr  e  s  e n t   a  t  i   on of   t  h  e  s  um .

 C h  e  c k  t  h i   s  b   y s i    gn

 e x t   e n d i  n  g t  h  e i  n  p u

 t   s  t   o

!

 b i   t   s  a n d  c  om  p u t   e  t  h  e 

 s  um— t  h  e  o u t    p u t   w

i  l  l   b  e  t  h  e  s  a m e  a  s 

f   or  t  h  e 

- b i   t  i  n  p u t   s  , b  u t   wi   t  h  o u t  

 o v e r fl  o w o u t   of   t  h  e 

!

 t  h  b i   t  

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  5 

Page 26: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 26/42

2  6 

A & S 2 ’   s  c 

 om  pl   e m e n t  m ul   t  i    p

l  i   c  a  t  i   on (   c  on t   d  . )   : 

M e  t  h  o d 2  (   c  on t   d  . )   : E x a m

  pl   e  : 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  6 

Page 27: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 27/42

2  7 

A & S 2 ’   s  c 

 om  pl   e m e n t  m ul   t  i    p

l  i   c  a  t  i   on (   c  on t   d  . )   : 

M e  t  h  o d 2  (   c  on t   d  . )   : 

¡

I  f   t  h  e m ul   t  i    pl  i   e r 

w

i   s 

n e   g a  t  i   v e  ,  p e r f   or m

 t  h  e fi r  s  t  

I

!

 a  d 

 d i   t  i   on s  a  s  e x-

  pl   a i  n e  d  a  b  o v e  , a n d  t  h  e 

n s  u b  t  r  a  c  t  x

 a  s  t  h  e fi n a l   s  t   e   p

¡

T h i   s  w or k  s  b  e  c  a  u s  e 

 t  h  e  v a l    u e of   a 2 

’   s  c  om  pl   e m e n t  n

 um b  e r w

¢

#

b

¢

(

i   s   gi   v e n b   y

w

I

#

b

¢

#

b

(

£

#

b

"

£

¢

£

T h  u

 s 

w

x

I

#

b

¢

#

b

(

£

#

b

"

£

¢

£

x

 . Wh  e nw

i   s n e   g a  t  i   v e  ,

¢

#

b

i   s 1 

 a n d  t  h  u s 

(

£

#

b

"

£

¢

£

x

I

x

d

#

b

 wh  e r  e  t  h  e fi r  s  t   t   e r mr 

 e   pr  e  s  e n t   s n or m a l  

m ul   t  i    pl  i   c  a  t  i   o

nf   or  t  h  e fi r  s  t  

I

!

 b i   t   s  of  

w

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  7 

Page 28: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 28/42

2  8 

A & S 2 ’   s  c 

 om  pl   e m e n t  m ul   t  i    p

l  i   c  a  t  i   on (   c  on t   d  . )   : 

M e  t  h  o d 2 —E x a m  pl   e  : 

¡

 N o t   e  t  h  a  t  m ul   t  i    pl  i   c 

 a  t  i   on

i   s   p e r f   or m

 e  d  on

 t  h  e  b  a  s 

i   s  : 

w

w

x

¡

T h  e 

m a   gni   t   u d  e  of   a n e   g a  t  i   v e 

w

i   s   gi   v e n b   y

w

#

I

w

#

b

I

(

£

#

b

"

£

¢

£

T h  u

 s 

w

x

I

#

b

I

(

£

#

b

"

£

¢

£

x

I

#

b

¢

#

b

(

£

#

b

"

£

¢

£

x

 ,

 wh i   c h i   s  wh  a  t   w e  a r  e  d  oi  n  g

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  8 

Page 29: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 29/42

2  9 

A & S 2 ’   s  c 

 om  pl   e m e n t  m ul   t  i    p

l  i   c  a  t  i   on (   c  on t   d  . )   : 

M e  t  h  o d 2  (   c  on t   d  . )   : H a r  d  w

 a r  e  : 

1  6 − b i   t  A 

 d  d  er 

A  c  c  um ul   a t   or 

 Q

M

A n d 

 C  o u t  

1  6 

1 1  6 

1  6 

1  6 

M ul   t  i   pl  i   er X 

M ul   t  i   pl  i   c  an d Y 

 Ov f  l  .

 d  e t  .

A  C  [   0  ]  

L  o gi   c 

1 1 

 C 1  5 

A  d  d − an d − sh i  f   t  m ul   t  i   pl  i   c a t  i   onf   o

r 2 ’   s c om pl   em en t  n um b  er  s

A  C  [   0  ]  

L  o gi   c : 

 C  o u t  

I  f   ov f  l   t  h  en

  o u t   p u t  =

 el   s  e

  o u t   p u t  =A  C  [   0  ]  

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

2  9 

Page 30: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 30/42

 3  0 

 S   p e  e  d i  n  g U  p S  e r i   a l  M ul   t  i    pl  i   c  a  t  i   on

B o o t  h ’   s Al    g or i   t  h m

¡

I   d  e  a  :  C  on s i   d  e r  t  h  e f   ol  l   o wi  n  g s  u b  s  t  r i  n  g of  

w

 : 

j

lm

n

o

m

n

o

j

m

n

o

¡

T h  u

 s i  n s  t   e  a  d  of   a  d  d i  n  g

 a n d  s h i  f   t  i  n  g

x

4  t  i  m e  s  (   c  or r  e  s   p on d i  n

  g t   o t  h  e  s  t  r i  n  g

 of  4 

1 ’   s i  n 0 1 1 1 1  0  )   , w e  c  a n s  u b  t  r  a  c  t  

x

 (  I

x

!

 )   wh  e n

 w e  s  e  e  t  h  e 1  s  t  

1  c  omi  n  g a f   t   e r  a  0 i  n

w

 ,i   . e  . , w e  d  e  t   e  c  t  

 t  h  e 2 - b i   t   s  u b  s  t  r i  n  g

1  0 i  n t  h  e l   a  s  t  

2  b i   t   s  of   t  h  e  c  ur r  e n t  

w

 ,  j   u s  t   s h i  f   t  4  t  i  m e 

 s  a n d  t  h  e n a  d  d 

x

 (  

x

!

 )  

 wh  e n w e  s  e  e  t  h  a  t   t  h  e  c 

 ur r  e n t   s  t  r i  n  g of  1 ’   s i  n

w

h  a  v e  e n d  e  d  ,

i   . e  . , w e  d  e  t   e  c  t  

 t  h  e 

2 - b i   t   s  u b  s  t  r i  n  g 0 1 i  n t  h  e l   a  s  t  2  b i   t   s  of  

 t  h  e  c  ur r  e n t  w

 .T h i   s  s  a  v e  s  u s  t   w o

 a  d  d 

 s 

¡

T h  u

 s  wh  e n t  h  e m ul   t  i    p

l  i   e r  c  on t   a i  n s l   on  g (    gr  e  a  t   e r  t  h  a nl   e n  g t  h 2  )   s  t  r i  n  g s  of  

1 ’   s  ,B o o t  h ’   s m ul   t  i    pl  i   c  a  t  i   oni   s f   a  s  t   e r 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  0 

Page 31: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 31/42

 3 1 

B

 o o t  h ’   s Al    g or i   t  h m

 (   c  on t   d  . )  

¡

B o o t  h ’   s m ul   t  i    pl  i   c  a  t  i   on a l   s  o t   a k  e  s  c  a r  e  of   a n e   g a  t  i   v e m ul   t  i    p

l  i   e r  a  u t   om a  t  i  -

 c  a l  l    y . C  on s i   d  e r  t  h  e f   ol  l   o wi  n  gw

 : 

j

j

 S i  n

 c  e  t  h  e m ul   t  i    pl  i   c  a  t  i   on a l    g or i   t  h m c  on t   a i  n s 

 s  t   e   p s  (  

4

i  n t  h  e  a  b  o v e 

 e x a m  pl   e  )   , t  h  e 1  0  0  0  0  0  0 i   s i    gn or  e  d  a n d  w e 

 e n d  u  p s  u b  t  r  a  c  t  i  n  g

!

3

(

 t  i  m e  s  t  h  e m ul   t  i    pl  i   c  a n d 

— e x a  c  t  l    y t  h  e r i    gh  t   a n s  w e r  !  

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3 1 

Page 32: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 32/42

 3 2 

B

 o o t  h ’   s Al    g or i   t  h m

 (   c  on t   d  . )  

B o o t  h ’   s  a l    g or i   t  h mi   s  d  e  c r 

i   b  e  d  b   y t  h  e f   ol  l   o wi  n  g t   a  b l   e f   or i   t   e r  a  t  i   on

' : 

B i    t  

'

B i    t  

'

I

!

E x  pl    an a t  i    on

A c  t  i    on

¢

£

 (   c  ur r  e n t   )   (    pr  e  v . )  

 0 

B e   gi  nni  n  g of  

 a r  un of  

1  s 

I

x

y

!

Mi   d  d l   e  of   a r  un of  1  s  Onl    y s h i  f   t   0 

 0 

E n d  of   a r  un of  1  s 

x

 0 

 0 

Mi   d  d l   e  of   a r  un of   0  s  Onl    y s h i  f   t   0 

 N o t   e  :  (  1  )  F  or  un s i    gn e  d m

 ul   t  i    pl  i   c  a  t  i   on , w e n e  e  d  t   o  p a  d  t  h  e m ul  

 t  i    pl  i   e r w

 wi   t  h 

m  y t  h i   c 

 a l   0  s  on b  o t  h  s i   d  e  s 

 (  r i    gh  t   of  L  S B  p a  d  d i  n  gr  e   q ui  r  e  d  t   o s  t   a r  t   of  f   t  h  e   pr  o-

 c  e  s  s  )  

 (  2  )  F  or 

2 ’   s  c  om  pl   e m e n t  m

 ul   t  i    pl  i   c  a  t  i   on , w e n

 e  e  d  t   o  p a  d  t  h  e m ul   t  i    pl  i   e r 

w

 wi   t  h 

 a m  y t  h 

i   c  a l   0  onl    y t   o t  h  e r i    gh  t   of  i   t   s L  S B .T 

h i   s  w or k  s  b  e  c  a  u s  e 

 (  f   or 2 ’   s  c  om-

  pl   e m e n

 t   , t  h  e l   a  s  t  r  un of  1 ’   s i   s 1 1  . . .1  , wh  e r  e 

 t  h  e l   e f   t  m o s  t  1 i   s  t  h  e  s i    gn b i   t   (   b i   t  

I

!

 )  

 a n d  s  u  p  p o s  e  t  h  e r i    gh  t  m o s  t  1 i   s  t  h  e 

'

’   t  h  b i   t  f  r  oml   e f   t   , t  h  e n t  h  e  v a l   u e 

 of   t  h i   s 

 s  e   q u e n c  e i   s I

#

I

£

g

#

b

g

I

£

 , wh i   c h i   s  e x a  c  t  l    y

 t  h  e  v a l   u e  w e 

 a l  l   o t   e  d 

 t   o t  h i   s  s  e   q u e n c  e  w

h  e n w e  s  u b  t  r  a  c  t   e  d 

x

 a  t   t  h  e 

£’   t  h  b i   t    p o s i   t  i   on a  t   t  h  e 

Page 33: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 33/42

 3  3 

 b  e   gi  nni  n  g of   t  h i   s l   a  s  t  r  un

 of  1 ’   s  .F  ur  t  h  e r  ,i  f  

i   s  t  h  e  v a l   u e  w e 

 a l  l   o t   e  d  t   o t  h  e 

r  e  s  t   of  

 t  h  e m ul   t  i    pl  i   e r  b  e f   or  e  t  h  e l   a  s  t  r  un of  1 ’   s  , t  h  e n t  h  e fi n a l   v a l   u e  w e   gi   v e 

 t   o t  h  e m ul   t  i    pl  i   e r i   s I

£

 , wh i   c h i   s i   t   s  c 

 or r  e  c  t   v a l   u e i  n2 ’   s 

 c  om  pl   e m e n t   : 

I

#

I

£

g

#

b

g

£

 .

 (   3  )  ¢

£

i   s  t  h  e 

' t  h  b i   t   of   t  h  e 

B o o t  h R e  c  o d i  n  g of  

w

 : 

 (  4  )  ¢

£

m e  a n s n o a r i   t  h m e  t  i   c  o  p e r  a  t  i   on ,

!

m e  a n s  a  d  d 

x

 ,

y

!

m e  a n s 

 s  u b  t  r  a  c 

 t  x

H a r  d  w a r  e  : E  x c er  c i    s  e

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  3 

Page 34: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 34/42

 3 4 

B

 o o t  h ’   s Al    g or i   t  h m

 (   c  on t   d  . )  

E x a m  p

l   e  s  : 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3 4 

Page 35: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 35/42

 3  5 

B

 o o t  h ’   s Al    g or i   t  h m

 (   c  on t   d  . )  

¡

P r  o b l   e m :  Wh  e n t  h  e m

 ul   t  i    pl  i   e r  c  on t   a i  n s l   on  g s  t  r i  n  g s  (   s  a   y , of  l   e n  g t  h 

7

 )   of  

 a l   t   e 

r n a  t  i  n  g1  s  a n d  0  s 

 (  !

!

!

!

 )   , t  h  e n

 w e   p e r f   or m

7

6

 a  d  d i   t  i   on s  a n d 

7

6

 s  u b  t  r  a  c  t  i   on s  u s i  n

  gB o o t  h ’   s  a l    g or i   t  h 

m c  om  p a r  e  d  t   o onl    y

7

6

 a  d  d i  -

 t  i   on

 s  u s i  n  gr  e   g ul   a r  a  d  d - a n d - s h i  f   t  

¡

 S  ol   u t  i   on : L  o ok  a  t   3  c  on s  e  c  u t  i   v e  b i   t   s  of   t  h  e m ul   t  i    pl  i   e r i  n s  t   e 

 a  d  of  2  t   o d  e -

 c i   d  e  wh  a  t   t   o d  o .T h i   s i   s  c  a l  l   e  d  t  h  e M o d i  fi 

 e  d B o o t  h ’   s Al    g or i   t  h m (  MBA )  

¡

T h i   s  wi  l  l   e n a  b l   e  u s  t   o

 t  r  e  a  t  i   s  ol   a  t   e  d 1  s  a n d  0  s  d i  f  f   e r  e n t  l    yf  r 

 omr  un s  of  1  s 

 a n d 

 0  s  .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  5 

Page 36: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 36/42

 3  6 

M

 o d i  fi  e  d B o o t  h ’   s A

l    g or i   t  h m

¡

T h  u

 s  wh  e n w e  s  e  e  a 

 w e 

 a  d  d x

 c  or r  e  s   p on d i  n  g t   o t  h  e i   s  ol   a  t   e  d 1  .T h i   s i   s  c  or r  e  c  t   , s i  n c  e i  nBA w e 

 w o ul   d h  a  v e  s  u b  t  r  a  c  t   e  d 

 a x

 on d  e  t   e  c  t  i  n  g1  0  a n d  a  d  d  e  d 

x

 on

 s  u b  s  e   q u e n t  l    y

 d  e  t   e  c  t  i  n  g 0 1  .T h  u s  a  s  s  umi  n  g t  h  e 1 i   s  t  h 

 e ' t  h  b i   t   , w e  w o ul   d h  a  v e  a  d  d  e  d 

£

©

x

I

£

x

£

x

 w e  a r  e  d  oi  n  g t  h  e R

H S i  nMBA

¡

 Wh 

 e n w e  s  e  e  a 

 a n d  t  h i   s i   s  ol   a  t   e  d  0 i   s n o t  f   ol  l   o wi  n  g a n

i   s  ol   a  t   e  d 1  , t  h  e n w

 e  s  u b  t  r  a  c  t  x

 c  or r  e  s   p on d i  n  g t   o t  h  e i   s  ol   a  t   e  d  0  .T h i   s i   s 

 c  or r  e  c  t   , s i  n c  e i  nBA w e  w o ul   d 

h  a  v e  a  d  d  e  d 

x

 on d  e  t   e  c  t  i  n  g 0 1  a n d  t  h  e n s  u b  t  r  a  c  t   e  d 

x

 on

 d  e  t   e  c  t  i  n  g1  0  .

T h i   s i   s  e   q ui   v a l   e n t   t   o a  d  d i  n  gI

£

©

x

£

x

I

£

x

— a   g a i  n , w e  a r  e  d  oi  n  g

 t  h  e 

RH S i  nMBA

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  6 

Page 37: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 37/42

 3  7 

M o d i  fi  e  d B o o t  h ’   s Al    g or i   t  h m (   c  on t   d  . )  

¡

Af   t   e r  d  e  t   e  c  t  i  n  g a ni   s  ol   a  t   e  d 1  (   0 1  0  )   ,i   t   s h  o

 ul   d  b  e n o t   e  d  a  s  s  u c h  s  o t  h  a  t   a f   t   e r 

 s h i  f   t  i  n  gr i    gh  t   , w e  d  on’   t  mi   s i  n t   e r   pr  e  t   t  h  e  b i   t    p a  t   t   e r n a  s  e n d i  n  g a r  un of  1  s  .

F  or 

 e x a m  pl   e  , c  on s i   d  e r  t   w o b i   t    p a  t   t   e r n s  s h  o wi  n  g t  h  e 4  c  on s  e  c  u t  i   v e  b i   t   s  of  

w

!

z

{

!

!

T h 

 e 1  s  t  h  a  s  a ni   s  ol   a  t   e  d 1  a n d  t  h  e 2 n d  a r  un of  1  s  .F  or  t  h 

 e 1  s  t   c  a  s  e  w e 

h  a  v e  a  d  d  e  d 

x

 c  or r  e  s   p

 on d i  n  g t   o t  h  e 1  , a n d i  n t  h  e  s  e  c  on d  c  a  s  e  , w e  d  on o t  

 d  o a n  y t  h i  n  g a  s  w e  a r  e 

i  n t  h  e mi   d  d l   e  of   a 

r  un of  1 ’   s  (   a  s i  nBA )  

Af   t   e r  a r i    gh  t   s h i  f   t   , w e 

h  a  v e  t  h  e   p a  t   t   e r n s 

!

z

{

!

 wh 

i   c h  a r  e i   d  e n t  i   c  a l   .

I  n t  h  e fi r  s  t   c  a  s  e  , w

 e n e  e  d  t   oh  a  v e n o

 t   e  d  t  h  a  t   t  h  e 1 

 c  or r  e  s   p on d  s  t   o a ni   s  ol   a  t   e  d 1  , s  o t  h  a  t   w e  d 

 on o t   d  o a n  y t  h i  n  g .

I  n t  h  e  s  e  c  on d 

 c  a  s  e  , t  h i   s m e  a n s  e n d  o

f   a r  un of  1  s  , a n d  s  o w e n e  e  d  t   o a  d  d 

x

 (   a  s i  nBA )   .

¡

T h  e 

 s  e  c  a  s  e  s  a r  e  d i   s  t  i  n  g ui   s h  e  d  b   y s  e  t   t  i  n  g a l   a  t   c h 

|

 t   o b  e  0  wh 

 e n a ni   s  ol   a  t   e  d 

1 i   s 

 s   p o t   t   e  d  , a n d  t   o1 i  f   a r  un of  1  s i   s  s   p o t   t   e  d 

¡

T h  u

 s  a  c  t   u a l  l    y t  h  e l   e  a  s  t   s i    gni  fi  c  a n t   of   t  h  e 

 3  b i   t   s  t  h  a  t   w e  o b  s  e r  v e  s h  o ul   d  b  e 

|

 a n d n o t   t  h  e   pr  e  vi   o u s  b i   t   of  

w

 .E x c  e   p t  

 wh  e n d i   s  t  i  n  g ui   s h i  n  g b  e  t   w e  e n a n

Page 38: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 38/42

 3  8 

i   s  ol   a  t   e  d 1  (   0  )   a n d  t  h  e 

 e n d  of   a r  un of  1 ’   s  (   0 ’   s  )  

|

 wi  l  l   b  e  t  h 

 e  s  a m e  a  s  t  h  e 

  pr  e  vi   o u s l    y o b  s  e r  v e  d  b i   t   of  

w

 .

¡

T h  u

 s  a f   t   e r  a r i    gh  t   s h i  f   t   , t  h  e  a  b  o v e  3 - b i   t    p a  t   t   e r n s  wi  l  l   b  e 

|

z

{

|

!

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  8 

Page 39: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 39/42

 3  9 

M o d i  fi  e  d B o o t  h ’   s Al    g or i   t  h m (   c  on t   d  . )  

¡

 S i  m

i  l   a r l    y , w e n e  e  d  t   o

 d i   s  t  i  n  g ui   s h  b  e  t   w e  e n a ni   s  ol   a  t   e  d  0  a n d  t  h  e  e n d  of   a 

r  un

 of   0 ’   s  .I  n t  h  e f   or m

 e r  c  a  s  e  ,|

i   s  s  e  t   t   o

1  a n d  t   o 0 i  n t  h  e l   a 

 t   t   e r  c  a  s  e 

¡

A  g a i  n , c  on s i   d  e r  t   w o b 

i   t    p a  t   t   e r n s  s h  o wi  n  g

4  c  on s  e  c  u t  i   v e  b i   t   s  of  

w

!

!

!

z

{

!

!

T h  e 

1  s  t  h  a  s  a ni   s  ol   a  t   e  d  0 i  ni   t   s 2 n d  b i   t  f   or  wh i   c h  w e  s  u b  t  r  a  c 

 t   e  d x

 a n d  t  h  e 

2 n d 

  p a  t   t   e r nh  a  s  a  0 i  n

i   t   s 2 n d  b i   t   t  h  a  t   e n d 

 s  a r  un of   0 ’   s  .

¡

T h  u

 s  a f   t   e r  a r i    gh  t   s h i  f   t   , t  h  e  a  b  o v e  3 - b i   t    p

 a  t   t   e r n s  wi  l  l  n o t   b  e 

i   d  e n t  i   c  a l   , b  u t  

 wi  l  l   b  e 

!

!

|

!

z

{

!

!

|

I  n t  h  e fi r  s  t   c  a  s  e  , w e  c 

 or r  e  c  t  l    y d  on o t  h i  n  g (   w e  a l  r  e  a  d   y s  u b  t  r  a  c  t   e  d x

 c  or -

r  e  s   p on d i  n  g t   o t  h  e i   s  ol   a  t   e  d  0  )   c  or r  e  s   p on d 

i  n  g t   o t  h  e mi   d  d l   e 

 b i   t   a n d i  n t  h  e 

 s  e  c  on d  w e  s  u b  t  r  a  c  t  

x

 , s i  n c  e  t  h  e mi   d  d l   e  b i   t   b  e   gi  n s  a r  un of  

1 ’   s  wh i   c h h  a  s 

n o t  

  y e  t   b  e  e n a  c  c  o un t   e  d f   or  .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

 3  9 

Page 40: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 40/42

4  0 

M o d i  fi  e  d B o o t  h ’   s Al    g or i   t  h m (   c  on t   d  . )  

¡

T h  e 

r i    gh  t  m o s  t   b i   t  i  n t  h  e  3  b i   t   s  t  h  a  t   w e  a r  e l   o ok i  n  g a  t  i   s  a  c  t   u a l  l    y

|

 wh i   c h 

i   s i  ni   t  i   a l  i  z  e  d  t   o 0 

¡

T h  e 

 s  e  c  on d  b i   t  i   s 

¢

£ (  i  n t  h  e 

' t  h i   t   e r  a  t  i   on ,

}

'

}

I

!

 )   , a n

 d  t  h  e l   e f   t  m o s  t  

 b i   t  i   s ¢

£

©

¡

 N o t   e  t  h  a  t   e x c  e   p t  i  n t  h  e i   s  ol   a  t   e  d 1  /   0  c  a  s  e  ,

|

¢

£ b

 (   a  s i  nB

A )   , o t  h  e r  wi   s  e 

|

y

¢

£ b

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

4  0 

Page 41: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 41/42

4 1 

M o d i  fi  e  d B o o t  h ’   s Al    g or i   t  h m (   c  on t   d  . )  

 W e  t  h  u

 s h  a  v e  t  h  e f   ol  l   o wi  n  gM o d i  fi  e  d B o o t  h 

’   s Al    g or i   t  h m d  e  s  c r i   b  e  d f   or i   t   e r  a -

 t  i   on' ,

}

'

}

I

!

 : 

B i    t  

£

©

B i    t  

£

~

E x  pl    an a t  i    on

 N e  w

~

 (  n e x t   )  

 (   c  ur r  e n

 t   )  

 0 

 0 

 0 

Mi   d  d l   e  of   a r  un of  

 0  s 

 0 

 0 

 0 

 0 

I   s  ol   a  t   e  d 1 

 0 

 0 

 0 

I   s  ol   a  t   e  d  0 f   ol  l   o wi  n

  g a ni   s  ol   a  t   e  d 

1  OR

Mi   d  d l   e  of   a r  un of  

 0  s 

 0 

 0 

 0 

B e   gi  n s  a r  un of  1  s 

 0 

 0 

B e   gi  n s  a r  un of   0  s 

 0 

 0 

Mi   d  d l   e  of   a r  un of  

1  s 

 0 

 0 

I   s  ol   a  t   e  d  0 f   ol  l   o wi  n

  g a r  un of  1 ’   s 

Mi   d  d l   e  of   a r  un of  

1  s 

 0 

 N OT E  :  (  1  )  T h  e m ul   t  i    pl  i   e 

r n e  e  d  s  t   o b  e   p a  d  d 

 e  d  b   ym  y t  h i   c  a l   0  s 

 on b  o t  h  s i   d  e  s 

f   or  un s 

i    gn e  d  a n d 2 ’   s  c  om  pl   e m e n t  m ul   t  i    pl  i   c  a 

 t  i   on .

 (  2  )  ¢

£

i   s  t  h  e 

' t  h  b i   t   of   t  h  e 

M o d i  fi  e  d B o o t  h R e  c  o d i  n  g of  

w

 (   3  )  T h i   s  s  i     g n e d  - d   i     g i    t   e n c  o

 d i  n  gh  a  s 

6

5

 0  s  o

n t  h  e  a  v e r  a   g e  , a  s  o  p  p o s  e  d  t   o

6

i  n t  h  e r 

 e   g ul   a r  b i  n a r   y c  o d  e  .T h  u s 

6

4

f   e  w e r  a 

r i   t  h m e  t  i   c  o  p e r  a  t  i   on

 s  a r  e r  e   q ui  r  e  d 

 on t  h  e  a  v e r  a   g e  u s i  n  gMBAf   or m ul   t  i    pl  i   c  a  t  i   on .

 c   

 S h  a n t   a n uD u t   t  

 , UI   C 

4 1 

Page 42: Integer Add and Mult

7/27/2019 Integer Add and Mult

http://slidepdf.com/reader/full/integer-add-and-mult 42/42

M o d i  fi  e  d B o o t  h ’   s Al    g or i   t  h m (   c  on t   d  . )  

E x a m  p

l   e  s  : 

 c   

 S h  a n t   a n uD u t   t  

 , UI   C