220 practiceproblems 8 multicycledp sol

34
CS220 Spring 2015 Practice Problems #8 Solutions Problem 1: Assuming the following timings for the components of the datapath. All other components have no delay. Data/Instruction Memory Read: 200ps Data Memory Write: 100ps Register File Read: 100ps Register File Write: 50ps Adders: 80ps ALUs: 200ps Logical Shifter/Sign Extension: 30ps Multiplexors and other gates: 10ps a. Calculate the delay for each clock cycle of the multi‐cycle datapath finite state machine (each stage of each instruction, i.e. each bubble). See attached pages b. What is the minimum clock cycle period at which the multi‐cycle datapath can operate properly? 270ps What is the length of each instruction type in ps (R‐type, lw, sw, beq, j)? lw 270*5 = 1350ps sw/r‐type 270*4 = 1080 ps beq/j 270*3 = 810 ps Problem 2: MIPS Execution Examine the following MIPS program P. add $t0, $s4, $s3 and $t2, $t0, $s1 add $t1, $t1, $t1 add $t2, $t2, $t2 lw $t3, OPTION beq $s0, $t3, PARSE_WRITE_SP_LE and $t0, $t1, 0xff and $t1, $t1, 0xff00 or $t1, $t1, $t0 and $t0, $t2, 0xff and $t2, $t2, 0xff00 or $t2, $t2, $t0 PARSE_WRITE_SP_LE: sw $t1, 0($a1) lw $v0, WRITE_FILE sw $t2, 0($a1) a. In the multicycle datapath, in which clock cycle is the lw $t3, OPTION instruction fetched? 17 th cycle b. In the multicycle datapath, how many cycles does it take Program P to execute, assuming the branch is not taken? 61 clock cycles c. Which values (eg. MEM[$s0], branch address, Instruction[15:0], etc) are stored in the A, B, ALUOut, and MDR registers during the execution cycle of the following instruction: sw $t1, 0($a1) A: Reg[rs] = Reg[$a1] B: Reg[rt] = Reg[$t1] ALUOut: Reg[rs] + Instr[15:0] = Reg[$a1] + 0 MDR: Value read from memory (since Mem Rd = 0, it is the value last time read from the memory), which is the sw instruction itself.

Upload: kkfr888

Post on 29-Jan-2016

233 views

Category:

Documents


0 download

DESCRIPTION

MIPS Multi Cycle Datapath

TRANSCRIPT

Page 1: 220 PracticeProblems 8 MultiCycleDP Sol

CS220Spring2015PracticeProblems#8Solutions

Problem1:Assumingthefollowingtimingsforthecomponentsofthedatapath.Allothercomponentshavenodelay.

Data/InstructionMemoryRead:200ps DataMemoryWrite:100ps RegisterFileRead:100ps RegisterFileWrite:50ps

Adders:80ps ALUs:200ps LogicalShifter/SignExtension:30ps Multiplexorsandothergates:10ps

a. Calculatethedelayforeachclockcycleofthemulti‐cycledatapathfinitestatemachine(eachstageofeachinstruction,i.e.eachbubble).Seeattachedpages

b. Whatistheminimumclockcycleperiodatwhichthemulti‐cycledatapathcanoperateproperly?270psWhatisthelengthofeachinstructiontypeinps(R‐type,lw,sw,beq,j)?

lw270*5=1350ps sw/r‐type270*4=1080ps beq/j270*3=810ps

Problem2:MIPSExecutionExaminethefollowingMIPSprogramP.

add $t0, $s4, $s3 and $t2, $t0, $s1 add $t1, $t1, $t1 add $t2, $t2, $t2 lw $t3, OPTION beq $s0, $t3, PARSE_WRITE_SP_LE and $t0, $t1, 0xff and $t1, $t1, 0xff00 or $t1, $t1, $t0 and $t0, $t2, 0xff and $t2, $t2, 0xff00 or $t2, $t2, $t0 PARSE_WRITE_SP_LE: sw $t1, 0($a1) lw $v0, WRITE_FILE sw $t2, 0($a1)

a. Inthemulticycledatapath,inwhichclockcycleisthelw $t3, OPTION instructionfetched?17thcycleb. Inthemulticycledatapath,howmanycyclesdoesittakeProgramPtoexecute,assumingthebranchisnot

taken?61clockcyclesc. Whichvalues(eg.MEM[$s0],branchaddress,Instruction[15:0],etc)arestoredintheA,B,ALUOut,andMDR

registersduringtheexecutioncycleofthefollowinginstruction:sw $t1, 0($a1)A: Reg[rs] = Reg[$a1] B: Reg[rt] = Reg[$t1] ALUOut:Reg[rs]+Instr[15:0]=Reg[$a1]+0MDR:Valuereadfrommemory(sinceMemRd=0,itisthevaluelasttimereadfromthememory),whichistheswinstructionitself.

Page 2: 220 PracticeProblems 8 MultiCycleDP Sol
Page 3: 220 PracticeProblems 8 MultiCycleDP Sol
Page 4: 220 PracticeProblems 8 MultiCycleDP Sol
Page 5: 220 PracticeProblems 8 MultiCycleDP Sol
Page 6: 220 PracticeProblems 8 MultiCycleDP Sol
Page 7: 220 PracticeProblems 8 MultiCycleDP Sol
Page 8: 220 PracticeProblems 8 MultiCycleDP Sol
Page 9: 220 PracticeProblems 8 MultiCycleDP Sol
Page 10: 220 PracticeProblems 8 MultiCycleDP Sol
Page 11: 220 PracticeProblems 8 MultiCycleDP Sol
Page 12: 220 PracticeProblems 8 MultiCycleDP Sol

Problem3:Multi‐cycledatapathInclasswecoveredtheMIPSmulti‐cycleimplementationalsowhichoperatesforthesamebasicsubsetofMIPSinstructionsasinthesingle‐cyclebasicimplementation.InthisproblemyouwillintroducefunctionalityforadditionalMIPSinstructions.UsetheMulti‐cyclehandoutpostedonPIAZZAtospecifyyourchanges.Inallcases,trytofindasolutionthatminimizesthenumberofclockcyclesrequiredforthenewinstruction.Additionalfunctionalunitscanbeadded(adder,ALU,SignExtension,Registers,etc),butonlywhenabsolutelynecessary.Explicitlystatehowmanycyclesittakestoexecutethenewinstructioninyourmodifiedfinitestatemachine.ModifythedatapathandthefinitestatemachinetoimplementthefollowinginstructionsINDEPENDANTLY:

a. Implement'addi'instruction Reg[rt]←Reg[rs]+immed[15:0];

#registerrsisaddedtoimmediatevalueintheinstructionandstoredinrt

b. Implement'jal'instruction.Reg[31]←PC+4#$raregisterstoresthereturnaddressPC←PC+4[31:28],(Instruction[25:0]<<2)

#PCisthetop4bitsofthePC+4valueconcatenatedwiththelowest26bitsofthejumpaddress#shiftedtheleftby2bits

c. Implementanew'wai'instruction.Theinstruction,wai rt,standsfor"whereami"andputstheinstructionaddressintoaregisterspecifiedbythertfield.(Immediateformat)

Reg[rt]←PC#$raregisterstoresthereturnaddress

d. Implement‘bne’if(Reg[rs]!=Reg[rt])PC←PC+4+Instruction[15:0]<<2

e. Implement‘beqi’(Assumethersfieldisa5‐bit2’scomplementvalue)

if(Reg[rt]==2’scomplementvalueinrsfield)PC←PC+4+Instruction[15:0]<<2

f. Implement‘bgtz’(Assumethertregisterissetto$0)

if(Reg[rs]>=0)PC←PC+4+Instruction[15:0]<<2

g. Implementanew'incbeq'instruction.Theinstruction,incbeq rs, rt, label,standsfor"incrementandbranchonequal".Incrementalwaysoccurs!

if(Reg[rs]==Reg[rt])PC←PC+4+Instruction[15:0]<<2Reg[rs]←Reg[rs]+4#theincrementalwaysoccurs

h. Implementanew'sneg'instruction.Theinstruction,sneg rs,standsfor"setonnegative”.(Immediate

format)if(Reg[rs]<0)Reg[rt]=1,elseReg[rt]←0

i. Implementanew‘lwdec’instructon.Theinstructionlwdec rs, offset(rt),loadsavalueand

decrementsthersvaluebyonememoryword.Reg[rt]←Mem[Reg[rs]+sign‐extendedoffset]Reg[rs]←Reg[rs]–4

j. Implementanew‘swr’instruction.Theinstructionswr rd, rt(rs),usesaregistervaluefortheoffsetwhencalculatingthememoryaddresstostoredatato.

Mem[Reg[rs]+Reg[rt]]=Reg[rd]

k. Implementanew‘slti’instruction.Theinstructionsetsslti rs, rt, immediatesetsthersregistertotheimmediatevalueifthevalueinregisterrsislessthanregisterrt.

if(Reg[rs]<Reg[rt])Reg[rs]←2’scomplementimmediatevalue

Page 13: 220 PracticeProblems 8 MultiCycleDP Sol
Page 14: 220 PracticeProblems 8 MultiCycleDP Sol
Page 15: 220 PracticeProblems 8 MultiCycleDP Sol
Page 16: 220 PracticeProblems 8 MultiCycleDP Sol
Page 17: 220 PracticeProblems 8 MultiCycleDP Sol
Page 18: 220 PracticeProblems 8 MultiCycleDP Sol
Page 19: 220 PracticeProblems 8 MultiCycleDP Sol
Page 20: 220 PracticeProblems 8 MultiCycleDP Sol
Page 21: 220 PracticeProblems 8 MultiCycleDP Sol
Page 22: 220 PracticeProblems 8 MultiCycleDP Sol
Page 23: 220 PracticeProblems 8 MultiCycleDP Sol
Page 24: 220 PracticeProblems 8 MultiCycleDP Sol
Page 25: 220 PracticeProblems 8 MultiCycleDP Sol
Page 26: 220 PracticeProblems 8 MultiCycleDP Sol
Page 27: 220 PracticeProblems 8 MultiCycleDP Sol
Page 28: 220 PracticeProblems 8 MultiCycleDP Sol
Page 29: 220 PracticeProblems 8 MultiCycleDP Sol
Page 30: 220 PracticeProblems 8 MultiCycleDP Sol
Page 31: 220 PracticeProblems 8 MultiCycleDP Sol
Page 32: 220 PracticeProblems 8 MultiCycleDP Sol
Page 33: 220 PracticeProblems 8 MultiCycleDP Sol

Problem4:Showhowthejumpregisterinstruction'jr'canbeimplementedtothemulti‐cycledatapathbysimplymakingchangestothefinitestatemachine.(Hint:$0=$zero=0)rt field of the instruction should be register $0, which always holds the value 0.

Problem5:CalculatethedelayinthedatapathaftertheadditionofALLinstructionsinProblem3.Assumethesamedelays.Whatistheminimumclockcycleperiodatwhichthisdesigncanoperateproperly?Theanswerwilldependonhowyouimplementedeachinstruction

Problem6:Considerchangestotheoriginalmulti‐cycledatapaththatalterstheregisterfilesothatithasonlyonereadport.Describeanychangesthatwillneedtobemadetothedatapathinordertosupportthismodification.Usethedatapathdiagramtoillustratethechanges.Modifythefinitestatemachinetoindicatehowtheinstructionswillworkgivenyournewdatapath.YouwillneedtoaddcontrollinestoWriteregistersAandBandamultiplexer(withacontrolline)toselectbetweentheRsandRtfieldsoftheinstruction.

State1ismodifiedwithselectRsandWriteAasserted.Anewstatehastobeaddedbeforestates6and8toselectRtandWriteB.Afterthenewstatecontrolbranchestoeitherstate6orstate8basedupontheop‐code.OtherstatesarenotaffectedasonR‐Formatandbranchinstructionuseinputfromtworegisters.Additionally,State2mustbemodifiedtoadditionallyreadtheRtregisterandstorethecontentsinB.While,lwdoesnotrequiretoreadRt,thestoreworddoes.BymakingthemodificationtoState2,wheretheRegisterfileisnotbeingused,wedonot

Page 34: 220 PracticeProblems 8 MultiCycleDP Sol

increasethenumberofclockcyclesrequiredforaswinstruction.ControlsignalstoselectRtandWriteBmustbespecified.

Problem7:Considereliminatingthetwoshiftleftby2unitsinthemulticycledatapath.Insteadoftheseunits,theALUwillbeusedforshiftingthevaluesinstead.Whatimpactdoesthishaveontheoriginal5instructions(lw,sw,R‐type,beq,j)?Iftheshiftleftby2iseliminated,thenanytimethishappenswillrequirethattheALUisused.First,sincetheDecodestageaddstheimmediatevalueshiftedleftby2tocalculatethebranchaddress,nowastageinbetweentheFetchandDecodestageswouldneedtobeaddedtodotheshiftingofthesignextendedvalue.ThevaluewouldbeinALUOutandtheinput3ofALUSrcBwouldneedtomodifiedtobethevaluedfromtheALUOutregister.ThesecondShiftleftunitisusedinstage9fortheJumpinstruction.Ifthiswasremoved,thedatapathwouldneedtogothroughtheALUandthePCSourcemuxcouldeliminateinput2,andusethevalueoutoftheALUinstead.Problem8:Inthesinglecycledatapathcontrolunitfortheoriginal5instructions(lw,sw,R‐type,beq,j),theMemtoRegcontrolsignalcanbeeliminatedandtheMemReadorALUSrccontrolsignalscanbeusedtocontrolthemultiplexorinstead.Thisreducesthenumberofcontrolsignalsrequired(lesslogicgatestoimplement).

a. Whichothersignalsinthesinglecycledatapathcanbeeliminatedandreplacedbyanotherexistingcontrolsignal,ortheinverse(NOT)ofthesignal.

RegDstandALUOp1RegDst&MemRead’Branch&AluOp0

b. Arethereanysignalsinthemulti‐cycledatapath(basic5instructionsonly)whichcanbeeliminatedand

replaced?

Yes,MemtoRegisonlyusedinStage4&7.ItcanbereplacedwithRegDst’(whichisalsoonlyusedinStage4&7)