EECS151/251A Discussion 12QuincyHuynhApril17,2020
Plan for Today• Adders• Multipliers• HWQuestions
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
Carry Select Adder• Onewaytoreducecriticalpathistocuttheadderinto2parts,severingthecarrychain.
– Problem:TheLSBsideoftheadderwillworkasexpectedbuttheMSBsidestilldependsonthevalueofthecarry!
– Solution:Thereare2possibilitiesforthecarry-intotheMSBadder,0and1.CalculatetheresultofBOTH casesandpickthecorrectone• AllowstheMSBcomputationstooccurinparallelwiththeLSBcalculationwithasmalldelaytoselectthecorrectvalue
– Downside:Replicatedlogic,wastedeffort(energy)onresultthatisnotused
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
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!
Carry Lookahead Adder• Thecarrylogic,aswehavepresentedit,isnotassociative
– WeneedtocomputethebitsinorderfromLSBtoMSB,sinceeachFAneedsthecarry-outofthepreviousstage
• ThisisaproblemasitlimitsustoalinearchainofFAs,preventingusfromdoingworkinparallel
• Solution:Makethecarrylogicassociativethroughre-definingtheFAs
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• 𝑝" = 𝑎"⨁𝑏"
Redefining FAs: Carry Generate and Propagate• Thesumandcarry-outofaFAcannowbedefinedintermsofthesenewsignals– Thesumistrueif:
• Asingleinputistrueandthecarry-inisfalse• Theinputsareboth0orboth1,andthecarry-inistrue• 𝑠" = 𝑝"⨁𝑐",where𝑐" isthecarry-inforthisdigit
– Thecarry-outistrueif:• Carrygenerateistrue• Propagateistrueandthecarry-inistrue• 𝑐")* = 𝑔" + 𝑝" ( 𝑐"
What good did that do?• Notethatthesumandcarry-outbitsineachFAstilldependonthevaluesofthecarry-in.
– Thismeansthatwestillneedthecomputethecarry-invalueforeachbitpositionandhavelogictogeneratethesum
• However,thepandgvaluescanallbecomputedsimultaneously– Thereisnodependence oncarry-inwhencomputingpandg!
• WeleveragethispropertyinthecarrylookaheadadderbygroupingtogetheraddersandcreatingPandGsignalsfortheentiregroup– Prepresentsiftheentiregroupwillpropagateacarrysignal– Grepresentsiftheentiregroupsgeneratesacarrysignal
• ThePandGsignalscanbeprocessedinatreestructure
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
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
Parallel Prefix Adder• Onedisadvantageofthecarrylookaheadadderasdescribedinthelectureslidesisthatthe
carry-outbitstillripplethroughthegroupsinthefirstlayer• Analternativeistocomputethecarrybitsdirectlywithoutanygrouping
– However,wedon’twanttofallbacktoacarryripplesolution.– Trick:unrolltheexpressionforthecarrybit
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)!
Parallel Prefix Trees• Similartoareductiontreeexceptthatyouwanttokeeptheintermediatevalues
– Intermediatevaluesarere-usedwhencomputing• Inourcase,wecould useareductiontreetocomputethelastcarry.
– Thiswouldbeoflimitedusetousbecauseweneedalloftheintermediatecarrybitsthatwouldbecomputedaspartofthereductiontree
• Parallelprefixtreesgiveustheseintermediatevalues!– Workonoperatorsthatareassociative
Different Parallel Prefix Trees• Thereisatradeoffinparallelprefixtreesinhowintermediatevaluesare
computed/reused• Notethatbothofthesegraphsproducethesameoutputs(thepartialresults)
Kogge-Stone(DiagramfromLectureSlides)Requiresmoreresourcesbuthasashortercriticalpath.
Brent-Kung(DiagramfromLectureSlides)Mostreuse(minimallogic)butwithalongercriticalpath
Parallel Prefix Adder• TheParallelPrefixTreeDescribedAboveisforcomputingthecarrybits• Westillneedfulladderstoproducethep&gsignalsandtocalculatethefinalsum
– Modifiedfulladdersfeedtheparallelprefixtreewithpandgvalues– Fulladdersreceivethecarryinfromtheparallelprefixtreetocomputethesumbit
Multipliers• Remember,themechanicsofmultiplicationinbinaryaregenerallythesameasdecimal
multiplication(signedmultiplyrequiresaslighttweak).• 2StepstoMultiplication:
– Generationofpartialproducts– Addingpartialproducts
• Makingfastermultipliersmostlyinvolveschanginghowwedealwithgeneratingandaddingthepartialproducts
Unsigned Multiplication Example4’b0011 (3)
* 4’b0110 (6) 4’b0011 (3)* 4’b0110 (6)-------
000000110011
+ 0000---------00010010 (18)
PartialProducts
• PartialProductscanbegeneratedinparallel
• Let’strytoimprovetheadditionofthepartialproducts
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
Using Carry Save Addition• UsingCarrySaveAdditionAllowsustocreateamulti-inputadderthatis:
– Relativelyfast:CarrySaveAddersdonothaveacarryripple– Relativelysmall:donotneedthelogictohandlethecarrylogictocreateafastadder
• However,stillneedastandardadderattheendtoaddthefinalcarry-outandsum.– ThisisoneofthefastadderssuchastheCarryLookaheadorParallelPrefixAdders– Goodnews!Weonlyneedoneofthem.
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
Piping Feedback• Isitpossibletopipelinefeedbackatall?• Itis,ifyoucanshifttheloopdependencytoapreviouscycle