Professional Documents
Culture Documents
Pipeline: Datahazard, Stall
Pipeline: Datahazard, Stall
Augusto Salazar
Departamento de Ingeniería de Sistemas
Universidad del Norte
augustosalazar@uninorte.edu.co
I: add r1,r2,r3
J: sub r4,r1,r3
4
Three Generic Data Hazards
I: sub r1,r4,r3
J: add r1,r2,r3
K: mul r6,r1,r7
• Called an “output dependence” by compiler writers
This also results from the reuse of name “r1”.
• Can’t happen in MIPS 5 stage pipeline because:
– All instructions take 5 stages, and
– Writes are always in stage 5
• Will see WAR and WAW in more complicated pipes
6
Register Usage Can Cause Data Hazards
7
HW Stalls to Resolve Data Hazard
ALU
F FReg MDm
I add r1,r2,r3 Im Reg
ALU
s
t
sub r4, r1,r3 Im bubble bubble bubble Reg Dm Reg
r.
and r6,r1,r7
ALU
Im Reg Dm
O
r
or r8,r1,r9
ALU
d Im Reg
e
r Im Reg
xor r10,r1,r11
8
How HW really stalls pipeline
• HW doesn’t change PC => keeps fetching same instruction
& sets control signals to benign values (0)
ALU
F FReg MDm
I add r1,r2,r3 Im Reg
n
s
t
stall Im bubble bubble bubble bubble
r.
Im
stall bubble bubble bubble bubble
O
r Im bubble bubble bubble bubble
d stall
e
sub r4,r1,r3
ALU
r Im Reg Dm Reg
and r6,r1,r7
ALU
Im Reg Dm
9
Hazard Conditions
EX Hazard
If (EX/MEM.RegWrite
and (EX/MEM.RegisterRd <> 0)
and (EX/MEM.RegisterRd = ID/EX.RegisterRs
If (EX/MEM.RegWrite
and (EX/MEM.RegisterRd <> 0)
and (EX/MEM.RegisterRd = ID/EX.RegisterRt
Memory Hazard
If (MEM/WB.RegWrite
and (MEM/WB.RegisterRd <> 0)
and (EX/MEM.RegisterRd <> ID/EX.RegisterRs)
and (MEM/WB.RegisterRd = ID/EX.RegisterRs))
If (MEM/WB.RegWrite
and (MEM/WB.RegisterRd <> 0)
and (EX/MEM.RegisterRd <> ID/EX.RegisterRt)
and (MEM/WB.RegisterRd = ID/EX.RegisterRt))
10
Hazard Conditions
add $1
sw $4, 0($1)
add $1
sw $1, 0($4)
11
Logisim implementation
12