+ All Categories
Home > Documents > EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are...

EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are...

Date post: 26-Nov-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
23
EECS151/251A Discussion 12 Quincy Huynh April 17, 2020
Transcript
Page 1: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

EECS151/251A Discussion 12QuincyHuynhApril17,2020

Page 2: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Plan for Today• Adders• Multipliers• HWQuestions

Page 3: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Adders• Earlierintheterm,wediscussedtheCarryRippleAdder

– Replicateshowweaddbyhand• Computesum[i]andcarry_out[i]basedonA[i],B[i],andcarry_in[i]• carry_in[i]=carry_out[i-1],carry_in[0]=0ifunsigned.

• PrimaryDownside:LongCriticalPath– ThecarryrippleresultsinacriticalpaththatgoesthrougheachFA– Growslinearlywiththenumberofbitsadded

• Howdowemakeaddersfaster?– Cutthecriticalpath!– How?

• Changehowweworkwithcarries! FAa b ci

co sFA

a b ci

co sFA

a b ci

co sFA

a b ci

co s

a[3]b[3]

a[2]b[2]

a[1]b[1]

a[0]b[0]

s[3] s[2] s[1] s[0]co

c0

CriticalPath

Page 4: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Carry Select Adder• Onewaytoreducecriticalpathistocuttheadderinto2parts,severingthecarrychain.

– Problem:TheLSBsideoftheadderwillworkasexpectedbuttheMSBsidestilldependsonthevalueofthecarry!

– Solution:Thereare2possibilitiesforthecarry-intotheMSBadder,0and1.CalculatetheresultofBOTH casesandpickthecorrectone• AllowstheMSBcomputationstooccurinparallelwiththeLSBcalculationwithasmalldelaytoselectthecorrectvalue

– Downside:Replicatedlogic,wastedeffort(energy)onresultthatisnotused

Page 5: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Carry Select Example:

Assu

min

g co

[1] =

= 0

Assu

min

g co

[1] =

= 1

FAa b ci

co sFA

a b ci

co sFA

a b ci

co sFA

a b ci

co s

a[3]b[3]

a[2]b[2]

a[1]b[1]

a[0]b[0]

s[1] s[0]

c0

FAa b ci

co sFA

a b ci

co s

a[3]b[3]

a[2]b[2]

s[3] s[2]co

0

1

Example:4’b0111 (7)

+ 4’b0101 (5)-----------

5’b01100 (12)

11

1

0

10

0

1

11

11

00

00

0

1

10

1

1

10

0 1 1

0

Page 6: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Quick Aside: Associativity• Anoperator,#,isassociativeifthefollowingistrue:(a#b)#c=a#(b#c)• Addition*,multiplication,AND,OR,XOR,areassociative• Thisallowsustocomputetheminatreestructure

– Ex.Compute:a+b+c+d+e+f+g+h

See:Weisstein,EricW. "Associative."FromMathWorld--AWolframWebResource. http://mathworld.wolfram.com/Associative.html*Additionoffloatingpointnumbersisgenerallynotconsideredassociative

((((((a+b)+c)+d)+e)+f)+g)+h

((a+b)+(c+d))+((e+f)+(g+h))

Delay:7AdditionsHWRequirements:7Adders

Delay:3AdditionsHWRequirements:7Adders

+a

b

+c

+d

+e

+f

+g

+h

+ba

+dc

+fe

+hg

+ +

+

Addersinsamelayercanbecomputedinparallel!

Page 7: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Carry Lookahead Adder• Thecarrylogic,aswehavepresentedit,isnotassociative

– WeneedtocomputethebitsinorderfromLSBtoMSB,sinceeachFAneedsthecarry-outofthepreviousstage

• ThisisaproblemasitlimitsustoalinearchainofFAs,preventingusfromdoingworkinparallel

• Solution:Makethecarrylogicassociativethroughre-definingtheFAs

Page 8: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Redefining FAs: Carry Generate and Propagate• EachFANowGenerates2NewSignals– g(Generate):Trueiftheadderisguaranteedtogenerateacarry,regardlessofthevalueofthecarry-in• Ifbothoperandshavea1inthisposition,itisguaranteedthatacarrywillbegenerated

• 𝑔" = 𝑎" % 𝑏"– p(Propagate):Trueifthecarry-outofthisstagewillequalthecarry-in(propagatecarry-in)• Ifexactlyoneoftheinputsistrue,thecarry-outwillequalthecarry-in• 𝑝" = 𝑎"⨁𝑏"

Page 9: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Redefining FAs: Carry Generate and Propagate• Thesumandcarry-outofaFAcannowbedefinedintermsofthesenewsignals– Thesumistrueif:

• Asingleinputistrueandthecarry-inisfalse• Theinputsareboth0orboth1,andthecarry-inistrue• 𝑠" = 𝑝"⨁𝑐",where𝑐" isthecarry-inforthisdigit

– Thecarry-outistrueif:• Carrygenerateistrue• Propagateistrueandthecarry-inistrue• 𝑐")* = 𝑔" + 𝑝" ( 𝑐"

Page 10: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

What good did that do?• Notethatthesumandcarry-outbitsineachFAstilldependonthevaluesofthecarry-in.

– Thismeansthatwestillneedthecomputethecarry-invalueforeachbitpositionandhavelogictogeneratethesum

• However,thepandgvaluescanallbecomputedsimultaneously– Thereisnodependence oncarry-inwhencomputingpandg!

• WeleveragethispropertyinthecarrylookaheadadderbygroupingtogetheraddersandcreatingPandGsignalsfortheentiregroup– Prepresentsiftheentiregroupwillpropagateacarrysignal– Grepresentsiftheentiregroupsgeneratesacarrysignal

• ThePandGsignalscanbeprocessedinatreestructure

Page 11: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Carry Look-ahead Adder• Thesmallerblocksaremodifiedfulladders.

– Cancalculategandpimmediately– Mustwaitforcarry-intocomputesumbit– SomeFAsarerequiredtocreateacarry-out– 𝑔" = 𝑎" % 𝑏"– 𝑝" = 𝑎"⨁𝑏"– 𝑠" = 𝑝"⨁𝑐"– 𝑐")* = 𝑔" + 𝑝" % 𝑐"

a[0]b[0]

s[0]

a[1]b[1]

s[1]

a[2]b[2]

s[2]

a[3]b[3]

s[3]

a[4]b[4]

s[4]

a[5]b[5]

s[5]

a[6]b[6]

s[6]

a[7]b[7]

s[7]

c[0] c[0]

c[0]

c[0]

c[1]

c[2]

c[3]

c[4]

c[5]

c[6]

c[7]

c[8]

NoDependenceoncarry-in

Dependoncarry-in

a[i]b[i]

s[i] {p[i], q[i]}

2

c[i]

c[i+1]

{PA, QA}

{PB, QB}

2

2

2

{P, Q}

c_in

c_out

Page 12: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

a[0]b[0]

s[0]

a[1]b[1]

s[1]

a[2]b[2]

s[2]

a[3]b[3]

s[3]

a[4]b[4]

s[4]

a[5]b[5]

s[5]

a[6]b[6]

s[6]

a[7]b[7]

s[7]

c[0] c[0]

c[0]

c[0]

c[1]

c[2]

c[3]

c[4]

c[5]

c[6]

c[7]

c[8]

Carry Look-ahead Adder• ThelargerblockscomputeP&Gforhigherlevelsof

thehierarchy.– P&Gcanbecomputedwithoutcarry-in– Carry-inisrequiredtogeneratecarry-out– 𝑃 = 𝑃/𝑃0– 𝐺 = 𝐺0 + 𝐺/𝑃0– 𝐶345 = 𝐺 + 𝐶"6𝑃

NoDependenceoncarry-in

Dependoncarry-in

a[i]b[i]

s[i] {p[i], q[i]}

2

c[i]

c[i+1]

{PA, QA}

{PB, QB}

2

2

2

{P, Q}

c_in

c_out

Page 13: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Parallel Prefix Adder• Onedisadvantageofthecarrylookaheadadderasdescribedinthelectureslidesisthatthe

carry-outbitstillripplethroughthegroupsinthefirstlayer• Analternativeistocomputethecarrybitsdirectlywithoutanygrouping

– However,wedon’twanttofallbacktoacarryripplesolution.– Trick:unrolltheexpressionforthecarrybit

Page 14: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Unrolling the Carry-in• Recall:𝑐")* = 𝑔" + 𝑝" % 𝑐"• Let’scomputethecariesusingunrolling

– 𝑐7 = 0 (unsigned)– 𝑐* = 𝑔7 + 𝑝7 % 𝑐7 = 𝑔7– 𝑐9 = 𝑔* + 𝑝* % 𝑐* = 𝑔* + 𝑝* 𝑔7 = 𝑔* + 𝑝*𝑔7– 𝑐: = 𝑔9 + 𝑝9 % 𝑐9 = 𝑔9 + 𝑝9 𝑔* + 𝑝*𝑔7 = 𝑔9 + 𝑝9𝑔* + 𝑝9𝑝*𝑔7– 𝑐; = 𝑔: + 𝑝: % 𝑐: = 𝑔: + 𝑝: 𝑔9 + 𝑝9𝑔* + 𝑝9𝑝*𝑔7 = 𝑔: + 𝑝:𝑔9 + 𝑝:𝑝9𝑔* + 𝑝:𝑝9𝑝*𝑔7

• ComputingthecariesinvolvesANDsandORsofindividualpandgsignals– Thesepandgsignalscanallbecomputedinparallelsincetheydonotdependoncarry-ins

• Theseoperationsareassociative!– Wecanchangetheorderinwhichtheyareevaluated– Allowsustocomputetheminatree(parallelcomputation)!

Page 15: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Parallel Prefix Trees• Similartoareductiontreeexceptthatyouwanttokeeptheintermediatevalues

– Intermediatevaluesarere-usedwhencomputing• Inourcase,wecould useareductiontreetocomputethelastcarry.

– Thiswouldbeoflimitedusetousbecauseweneedalloftheintermediatecarrybitsthatwouldbecomputedaspartofthereductiontree

• Parallelprefixtreesgiveustheseintermediatevalues!– Workonoperatorsthatareassociative

Page 16: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Different Parallel Prefix Trees• Thereisatradeoffinparallelprefixtreesinhowintermediatevaluesare

computed/reused• Notethatbothofthesegraphsproducethesameoutputs(thepartialresults)

Kogge-Stone(DiagramfromLectureSlides)Requiresmoreresourcesbuthasashortercriticalpath.

Brent-Kung(DiagramfromLectureSlides)Mostreuse(minimallogic)butwithalongercriticalpath

Page 17: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Parallel Prefix Adder• TheParallelPrefixTreeDescribedAboveisforcomputingthecarrybits• Westillneedfulladderstoproducethep&gsignalsandtocalculatethefinalsum

– Modifiedfulladdersfeedtheparallelprefixtreewithpandgvalues– Fulladdersreceivethecarryinfromtheparallelprefixtreetocomputethesumbit

Page 18: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Multipliers• Remember,themechanicsofmultiplicationinbinaryaregenerallythesameasdecimal

multiplication(signedmultiplyrequiresaslighttweak).• 2StepstoMultiplication:

– Generationofpartialproducts– Addingpartialproducts

• Makingfastermultipliersmostlyinvolveschanginghowwedealwithgeneratingandaddingthepartialproducts

Page 19: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Unsigned Multiplication Example4’b0011 (3)

* 4’b0110 (6) 4’b0011 (3)* 4’b0110 (6)-------

000000110011

+ 0000---------00010010 (18)

PartialProducts

• PartialProductscanbegeneratedinparallel

• Let’strytoimprovetheadditionofthepartialproducts

Page 20: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Carry Save Addition• Whenwegenerateacarryinagivencolumnof

anaddition,weaddittothe2valuesinthenextcolumn.– Thisadditionmayinturngenerateitsowncarry

• Ifaddingcarriesisjustlikeanotheraddition,canwedelayaddingthecarrybitsuntillater?– Yes,solongaswerememberwhatthecarrybits

needtobeadded• Thisisthebasisofthecarrysaveadder:

– Takesina,b,andcarry_in (multi-bit)– Producesasumandcarry_out (multi-bit)

FAa b ci

co sFA

a b ci

co sFA

a b ci

co sFA

a b ci

co s

a[3]b[3]

a[2]b[2]

a[1]b[1]

a[0]b[0]

s[3] s[2] s[1] s[0]co[4]

ci[0]ci[1]ci[2]ci[3]

co[3] co[2] co[1] co[0]

0

CSAa b ci

cos

n n n

n+1n

Page 21: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Using Carry Save Addition• UsingCarrySaveAdditionAllowsustocreateamulti-inputadderthatis:

– Relativelyfast:CarrySaveAddersdonothaveacarryripple– Relativelysmall:donotneedthelogictohandlethecarrylogictocreateafastadder

• However,stillneedastandardadderattheendtoaddthefinalcarry-outandsum.– ThisisoneofthefastadderssuchastheCarryLookaheadorParallelPrefixAdders– Goodnews!Weonlyneedoneofthem.

Page 22: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Using Carry Save Addition

• Becauseadditionisassociative,itactuallydoesnotmatterwhatorderthecarrybitsareaddedbackintothesum– Canuseatreestructure

CSAa b ci

cos

ab

c

CSAa b ci

cos

d

CSAa b ci

cos

e

CSAa b ci

cos

f

ADDa b

s

CSAa b ci

cos

ab

c

CSAa b ci

cos

de

f

CSAa b ci

cos

CSAa b ci

cos

ADDa b

s

Page 23: EECS151/251A Discussion 12eecs151/sp20/files/...Carry Look-ahead Adder • The smaller blocks are modified full adders. – Can calculate g and p immediately – Must wait for carry-in

Piping Feedback• Isitpossibletopipelinefeedbackatall?• Itis,ifyoucanshifttheloopdependencytoapreviouscycle


Recommended