Take out your “Pipelining is hazardous”...

Post on 22-Jul-2020

6 views 0 download

Transcript of Take out your “Pipelining is hazardous”...

Takeoutyour“Pipeliningishazardous”worksheet

CS2630ComputerOrganization

Meeting25:AddressinghazardsinpipelinedMIPSSikder Huq

UniversityofIowa

Anotationforstudyinghazards

Thisnotationshowswhatstageisactiveineachcycleforeachinstruction.Noticethatthetheregisterfile(Reg)isinvolvedinbothIDandWBstages.

R

R

W

W

dottedblueline:Weneedtowrite$s0beforeweread$s0solidredline:Pointingfromwherevalueisactuallyproducedtowhereitisactuallyused

add $t0, $t1, $t2

add $t4, $t0, $t3

Avoidingdatahazard

Allowingdependenciesthatgobackwardsintime(likeabove)wouldcauseincorrectresults,sofixitby:a) Makingthedependentinstructionwait(“stall”)b) Makingthedataavailablesooner(“forwarding”)c) Combinationof(a)and(b)

add $t0, $t1, $t2

add $t4, $t0, $t3

Avoidingdatahazardbymethod#1:Stalling

Stall3 cycles

HowdoweStall aninstruction?

add $t0, $t1, $t2

add $t4, $t0, $t3

StallingtheprocessoratstageID

0

Hazarddetect

noop

Tostalltheprocessor,wemust:• DisablePCandIF/IDpipelineregister

frombeingwritten• Insertano-op instruction

HowdoesNo-opstalltheprocessor?No-opmeansaninstructionthathasnoeffect.

Peerinstruction#1:Whatarethecontrolsignalssettoforano-opinstruction?

0

Hazarddetect

noop

Administrivia• BrandonisbackforDebugYourBrain tonight 5-6pm,normaltime• Project2-2assigned• SimilarinfrastructuretoProject2-1• Donow

• Readthedocument• Downloadandrunthetestsimmediately• Designyourprocessoronpaper(2-stageisdifferentfrom5-stageinthebookbutusesthesameprinciples)

Avoidingthedatahazardbymethod#2:forwarding

Forward resulttoALU

Forwardingmeanstogettheneededvaluetotheplacewhereitisusedsooner(i.e.,thedatatakesashortcut!)

Intheabovecase,wecansendtheresultoftheALUbacktotheALUinput.

add $t0, $t1, $t2

add $t4, $t0, $t3

ForwardingALUresults

http://courses.cs.washington.edu/courses/cse378/11wi/lectures/lec12.pdf

AddaMUXforeachALUoperand.EachMUXpicksamong(0)outputoftheregisterfile,(1) theoutputoftheEXstageor(2) theoutputoftheMEMstage

HowdowecalculatesignalForwardA?Peerinstruction#2.

Alongerexample

Patterson&Hennessy

Backwardsdependencesaredatahazards

DependenceswhenMIPSdatapath hasforwarding

Note:let’sassumetheregisterfilecanbewrittenonthefalling edgeoftheclocksothatthenewvaluescanbereadinthesamecycleastheyarewritten

ALUresultforwardedtoALUoperand

ALUresultforwardedtoALUoperand

nohazardb/c$2writteninfirsthalfofclockcycle,readinsecondhalf

nohazard

Patterson&Hennessy

Whataboutload?• Inload,theresultisnotcomputeduntiltheendofMEMstage(1cyclelaterthanarithmeticinstructions)

e.g., lw $s0, 4($t0)sll $s1, $s0, 3

AvoidingtheLOAD-to-readhazardbystalling&forwarding

Stall1cycle

lw $s0, 4($t0)

sll $s1, $s0, 3

Forward resulttoALU

Forwardingmeanstogettheneededvaluetotheplacewhereitisusedsooner.Intheabovecase,wecansendtheresultoftheDMloadbacktotheALUinput.However,westillneedtoalsostallinIDforonecycletomakethearrowgoforwardintime.

Whataboutloadtostorehazard?• Seeworksheet#3

Summary• Datahazardsoccurinapipelinewhenaninstructionusesavaluecomputedbyarecentpreviousinstruction• ModifytheMIPSprocessortohandledatahazardsbystalling and/orforwarding

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