take out your “pipelining is hazardous”...

17
Take out your “Pipelining is hazardous” worksheet

Upload: others

Post on 22-Jul-2020

3 views

Category:

Documents


0 download

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Summary• Datahazardsoccurinapipelinewhenaninstructionusesavaluecomputedbyarecentpreviousinstruction• ModifytheMIPSprocessortohandledatahazardsbystalling and/orforwarding

• Next:• Controlhazards(branchconditionnotcalculateduntilEXstage)• Structuralhazards(alreadyseenthesebuthaven’tnamedthem)