Title: CS 2200 Lecture 09b Hazards
1CS 2200 Lecture 09bHazards
- (Lectures based on the work of Jay Brockman,
Sharon Hu, Randy Katz, Peter Kogge, Bill Leahy,
Ken MacKenzie, Richard Murphy, and Michael
Niemier)
2Control Hazards
3R-Type
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
4Control Hazard on BranchesTwo Stage Stall?
5Example
6Scenario
- We have the following code segment
- lw R6, X(R0)
- beq R1, R2, SKIP
- add R1, R2, R3
- SKIP add R5, R4, R1
- sw R7, X(R0)
- X .word 5
7lw R6,X(R0)
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
8lw R6,X(R0)
beq R1,R2,SKIP
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
9lw R6,X(R0)
beq R1,R2,SKIP
BUBBLE
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
Note Bubble because no branch predict or slot
fill.
WB
EX
MEM
ID
IF
10lw R6,X(R0)
beq R1,R2,SKIP
BUBBLE
BUBBLE
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
Second bubble because were detecting BEQ in 3rd
stage.
WB
EX
MEM
ID
IF
11lw R6,X(R0)
BUBBLE
BUBBLE
add R1,R2,R3
beq R1,R2,SKIP
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
12beq R1,R2,SKIP
BUBBLE
add R1,R2,R3
BUBBLE
add R5,R4,R1
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
13BUBBLE
add R1,R2,R3
BUBBLE
add R5,R4,R1
sw R7,X(R0)
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
Forwarding Unit
WB
EX
MEM
ID
IF
14BUBBLE
sw R7,X(R0)
add R1,R2,R3
add R5,R4,R1
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
15add R1,R2,R3
add R5,R4,R1
sw R7,X(R0)
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
16add R5,R4,R1
sw R7,X(R0)
lw R6,X(R0) beq R1,R2,SKIP add
R1,R2,R3 SKIP add R5,R4,R1 sw R7,X(R0)
M X
1
P C
Instr Mem
DPRF
BEQ
A
Data Mem
M X
M X
D
SE
WB
EX
MEM
ID
IF
17Summary
- Performance
- Execution time or throughput
- Amdahls law
- Multi-bus/multi-unit circuits
- one long clock cycle or N shorter cycles
- Pipelining
- overlap independent tasks
- Pipelining in processors
- hazards limit opportunities for overlap