Download pot - Data Hazards and Stalls

Transcript

No Slide Title

Data Hazards and Stalls
Data hazards and forwarding Data Hazards and Stalls

\course\cpeg323-05F\Topic6c-323.ppt

An Example
Assuming that register R2 = 10 initially. And the sub instruction will result in R2 = -20.

\course\cpeg323-05F\Topic6c-323.ppt

Sheet1

sub$2, $1, $3# Register $2 written by sub

and$12, $2, $5# 1st operand ($2) depends on sub

or$13, $6, $2# 2nd operand ($2) depend on sub

add$14, $2, $2# 1st ($2) & 2nd ($2) depend on sub

sw$15, 100($2)# Index ($2) depends on sub

Sheet2

Sheet3

Pipelined dependencies in a five instruction sequence using simplified datapaths to show the dependencies.
Note: only add and sw get the right value R2 = - 20

\course\cpeg323-05F\Topic6c-323.ppt

An Example (contd)
Hazard condition (between sub and and at the indicated stages):

EX/MEM.RegisterRd = ID/EX.RegisterRs = $2

General
1a.EX/MEM.RegisterRd = ID/EX.RegisterRs1b.EX/MEM.RegisterRd = ID/EX.RegisterRt2a.MEM/WB.RegisterRd = ID/EX.RegisterRs2b.MEM/WB.RegisterRd = ID/EX.RegisterRt
Question: can you identify which of the 4 conditionsHere captures the hazards condition between sub and or ?

\course\cpeg323-05F\Topic6c-323.ppt

Sheet1

sub$2, $1, $3# Register $2 written by sub

and$12, $2, $5# 1st operand ($2) depends on sub

or$13, $6, $2# 2nd operand ($2) depend on sub

add$14, $2, $2# 1st ($2) & 2nd ($2) depend on sub

sw$15, 100($2)# Index ($2) depends on sub

Sheet2

Sheet3

Forwarding/Bypassing
ALUinputs can also from pipeline registers

Extra multiplexors

Hazard detection units

\course\cpeg323-05F\Topic6c-323.ppt

The dependencies between the pipeline registers move forward in time, so it is possible to supply the inputs to the ALU needed by the and instruction and or instruction by forwarding the results found in the pipeline registers rather than stall.

\course\cpeg323-05F\Topic6c-323.ppt

the ALU and pipeline registerbefore adding forwarding.
a. No forwarding

\course\cpeg323-05F\Topic6c-323.ppt

Forwarding control and the multiplexors are added
b. With forwarding

\course\cpeg323-05F\Topic6c-323.ppt

The control values for the forwarding multiplexors.

\course\cpeg323-05F\Topic6c-323.ppt

Forwarding Conditions
1. EX hazard:

if(EX/MEM.RegWriteand (EX/MEM.RegisterRd =/= 0)and (EX/MEM.RegisterRd = ID/EX.RegisterRs)) ForwardA = 10

if (EX/MEM.RegWriteand (EX/MEM.RegisterRd =/= 0)and (EX/MEM.RegisterRd = ID/EX.RegisterRt)) ForwardB = 10


\course\cpeg323-05F\Topic6c-323.ppt

2. MEM hazard:

if(MEM/WB.RegWriteand (MEM/WB.RegisterRd =/= 0)and (MEM/WB.RegisterRd = ID/EX.RegisterRs)) ForwardA = 01

if(MEM/WB.RegWriteand (MEM/WB.RegisterRd =/= 0)and (MEM/WB.RegisterRd = ID/EX.RegisterRt)) ForwardB = 01
Cond

\course\cpeg323-05F\Topic6c-323.ppt

Note:here both EX and MEM stages may have the exact hazard conditions. What should we do ?
Add $1, $1, $2Add $1, $1, $3Add $1, $1, $4.
Priority in Forwarding

\course\cpeg323-05F\Topic6c-323.ppt

Note:When both EX and MEM stages may have the exact hazard conditions.
If (MEM/WB.RegWriteand (MEM/WB.RegisterRd =/= 0)and (EX/MEM.RegisterRd =/= ID/EX.RegisterRs)and (MEM/WB.RegisterRd = ID/EX.RegisterRs)) Forward A = 01

if (MEM/WB.RegWriteand (MEM/WB.RegisterRd =/= 0)and (EX/MEM.RegisterRd =/= ID/EX.RegisterRt)and (MEM/WB.RegisterRd = ID/EX.RegisterRt)) ForwardB = 01
Priority in Forwarding

\course\cpeg323-05F\Topic6c-323.ppt

The datapath modified to resolve hazards via forwarding.

\course\cpeg323-05F\Topic6c-323.ppt

The Snapshots of Our Example Through Forwarding

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 3 of the instruction sequence.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 4 of the instruction sequence.
add $9, $4, $2 or $4, $4, $2 and $4, $2, $5 sub $2 before

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 5 of the instruction sequence.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 6 of the instruction sequence.
after after add $9, $4, $2 or $4 and $4...

\course\cpeg323-05F\Topic6c-323.ppt

Hazards and Stalls

\course\cpeg323-05F\Topic6c-323.ppt

A pipelined sequence of instructions.

\course\cpeg323-05F\Topic6c-323.ppt

The way stalls are really inserted into the pipeline.

\course\cpeg323-05F\Topic6c-323.ppt

Forwarding with Load and Stores
The problem

The solution

\course\cpeg323-05F\Topic6c-323.ppt

A Hazard Detection Unit
In the ID stage, the following should be checked by the hazard detection unit, so it can insert the stall between a load and its use.if (ID/EX.MemRead and ((ID/EX.RegisterRt = IF/ID.RegisterRs) or (ID/EX.RegisterRt = IF/ID.RegisterRt)) stall the pipeline

\course\cpeg323-05F\Topic6c-323.ppt

Pipelined control overview, showing the two multiplexors for forwarding, the hazard detection unit, and the forwarding unit.

\course\cpeg323-05F\Topic6c-323.ppt

Snapshots of the running example through the pipeline

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 2 of the instruction sequence in the example.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 3 of the instruction sequence in the example.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 4 the instruction sequence in the example.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 5 of the instruction sequence in the example.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 6 of the instruction sequence in the example.

\course\cpeg323-05F\Topic6c-323.ppt

Clock cycles 7 of the instruction sequence in the example. (note the forwarding of r4)

\course\cpeg323-05F\Topic6c-323.ppt

Branch Hazards and Handling
Branch hazardsBranch hazard handling methodsStaticDynamic

\course\cpeg323-05F\Topic6c-323.ppt


Recommended