take out your “pipelining is hazardous”...
TRANSCRIPT
![Page 1: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/1.jpg)
Takeoutyour“Pipeliningishazardous”worksheet
![Page 2: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/2.jpg)
CS2630ComputerOrganization
Meeting25:AddressinghazardsinpipelinedMIPSSikder Huq
UniversityofIowa
![Page 3: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/3.jpg)
Anotationforstudyinghazards
Thisnotationshowswhatstageisactiveineachcycleforeachinstruction.Noticethatthetheregisterfile(Reg)isinvolvedinbothIDandWBstages.
R
R
W
W
dottedblueline:Weneedtowrite$s0beforeweread$s0solidredline:Pointingfromwherevalueisactuallyproducedtowhereitisactuallyused
add $t0, $t1, $t2
add $t4, $t0, $t3
![Page 4: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/4.jpg)
Avoidingdatahazard
Allowingdependenciesthatgobackwardsintime(likeabove)wouldcauseincorrectresults,sofixitby:a) Makingthedependentinstructionwait(“stall”)b) Makingthedataavailablesooner(“forwarding”)c) Combinationof(a)and(b)
add $t0, $t1, $t2
add $t4, $t0, $t3
![Page 5: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/5.jpg)
Avoidingdatahazardbymethod#1:Stalling
Stall3 cycles
HowdoweStall aninstruction?
add $t0, $t1, $t2
add $t4, $t0, $t3
![Page 6: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/6.jpg)
StallingtheprocessoratstageID
0
Hazarddetect
noop
Tostalltheprocessor,wemust:• DisablePCandIF/IDpipelineregister
frombeingwritten• Insertano-op instruction
![Page 7: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/7.jpg)
HowdoesNo-opstalltheprocessor?No-opmeansaninstructionthathasnoeffect.
Peerinstruction#1:Whatarethecontrolsignalssettoforano-opinstruction?
0
Hazarddetect
noop
![Page 8: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/8.jpg)
Administrivia• BrandonisbackforDebugYourBrain tonight 5-6pm,normaltime• Project2-2assigned• SimilarinfrastructuretoProject2-1• Donow
• Readthedocument• Downloadandrunthetestsimmediately• Designyourprocessoronpaper(2-stageisdifferentfrom5-stageinthebookbutusesthesameprinciples)
![Page 9: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/9.jpg)
Avoidingthedatahazardbymethod#2:forwarding
Forward resulttoALU
Forwardingmeanstogettheneededvaluetotheplacewhereitisusedsooner(i.e.,thedatatakesashortcut!)
Intheabovecase,wecansendtheresultoftheALUbacktotheALUinput.
add $t0, $t1, $t2
add $t4, $t0, $t3
![Page 10: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/10.jpg)
ForwardingALUresults
http://courses.cs.washington.edu/courses/cse378/11wi/lectures/lec12.pdf
AddaMUXforeachALUoperand.EachMUXpicksamong(0)outputoftheregisterfile,(1) theoutputoftheEXstageor(2) theoutputoftheMEMstage
![Page 11: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/11.jpg)
HowdowecalculatesignalForwardA?Peerinstruction#2.
![Page 12: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/12.jpg)
Alongerexample
Patterson&Hennessy
Backwardsdependencesaredatahazards
![Page 13: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/13.jpg)
DependenceswhenMIPSdatapath hasforwarding
Note:let’sassumetheregisterfilecanbewrittenonthefalling edgeoftheclocksothatthenewvaluescanbereadinthesamecycleastheyarewritten
ALUresultforwardedtoALUoperand
ALUresultforwardedtoALUoperand
nohazardb/c$2writteninfirsthalfofclockcycle,readinsecondhalf
nohazard
Patterson&Hennessy
![Page 14: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/14.jpg)
Whataboutload?• Inload,theresultisnotcomputeduntiltheendofMEMstage(1cyclelaterthanarithmeticinstructions)
e.g., lw $s0, 4($t0)sll $s1, $s0, 3
![Page 15: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/15.jpg)
AvoidingtheLOAD-to-readhazardbystalling&forwarding
Stall1cycle
lw $s0, 4($t0)
sll $s1, $s0, 3
Forward resulttoALU
Forwardingmeanstogettheneededvaluetotheplacewhereitisusedsooner.Intheabovecase,wecansendtheresultoftheDMloadbacktotheALUinput.However,westillneedtoalsostallinIDforonecycletomakethearrowgoforwardintime.
![Page 16: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/16.jpg)
Whataboutloadtostorehazard?• Seeworksheet#3
![Page 17: Take out your “Pipelining is hazardous” worksheethomepage.cs.uiowa.edu/~bdmyers/cs2630_fa16/public... · Take out your “Pipelining is hazardous” worksheet. CS 2630 Computer](https://reader033.vdocuments.us/reader033/viewer/2022042710/5f6534fce79d624a401bc43f/html5/thumbnails/17.jpg)
Summary• Datahazardsoccurinapipelinewhenaninstructionusesavaluecomputedbyarecentpreviousinstruction• ModifytheMIPSprocessortohandledatahazardsbystalling and/orforwarding
• Next:• Controlhazards(branchconditionnotcalculateduntilEXstage)• Structuralhazards(alreadyseenthesebuthaven’tnamedthem)