Professional Documents
Culture Documents
02 - Pipelining Part 1 PDF
02 - Pipelining Part 1 PDF
F 3 - 1
Datorarkitektur
F 3 - 2
FI
Decode
DI
4. Structural Hazards
5. Data Hazards
Execute
instruction
6. Control Hazards
Datorarkitektur
F 3 - 3
Datorarkitektur
F 3 - 4
Instruction Pipelining
Acceleration by Pipelining
Stage 2
1 2 3 4 5 6 7 8
Instr. i
FI EI
FI EI
Instr. i+2
Instr. i+3
Instr. i+4
Instr. i+5
Instr. i+6
FI EI
FI EI
FI EI
FI EI
FI EI
Stage n
Clock cycle
Instr. i+1
Datorarkitektur
F 3 - 5
Datorarkitektur
F 3 - 6
1 2 3 4 5 6 7 8 9 10 11 12
Instr. i
FI DI COFO EI WO
Instr. i+1
Instr. i+2
Instr. i+3
FI DI COFO EI WO
FI DI COFO EI WO
FI DI COFO EI WO
Instr. i+4
FI DI COFO EI WO
Instr. i+5
FI DI COFO EI WO
Instr. i+6
FI DI COFO EI WO
PowerPC:
Datorarkitektur
F 3 - 7
Datorarkitektur
Pipeline Hazards
Structural Hazards
Types of hazards:
1. Structural hazards
2. Data hazards
3. Control hazards
F 3 - 8
1 2 3 4 5 6 7 8 9 10 11 12
ADD R4,X
FI DI COFO EI WO
Instr. i+1
Instr. i+2
Instr. i+3
Instr. i+4
FI DI COFO EI WO
FI DI COFO EI WO
stall
FI DI COFO EI WO
FI DI COFO EI WO
Penalty: 1 cycle
Datorarkitektur
F 3 - 9
Datorarkitektur
F 3 - 10
Data Hazards
I1:
I2:
MUL
ADD
MUX
R2 R2 * R3
R1 R1 + R2
R2,R3
R1,R2
MUX
bypass
path
bypass
path
ALU
Clock cycle
1 2 3 4 5 6 7 8 9 10 11 12
MUL R2,R3
FI DI COFO EI WO
ADD R1,R2
to register or memory
FI DI CO stall stall FO EI WO
Instr. i+2
FI DI
COFO EI WO
Clock cycle
1 2 3 4 5 6 7 8 9 10 11 12
MUL R2,R3
FI DI COFO EI WO
ADD R1,R2
FI DI CO stall FO EI WO
After the EI stage of the MUL instruction the result is available by forwarding. The penalty is reduced to one cycle.
Datorarkitektur
F 3 - 11
Datorarkitektur
Control Hazards
F 3 - 12
Unconditional branch
-------------BR
TARGET
-------------TARGET
-------------After the FO stage of the
branch instruction the
address of the target is
known and it can be fetched
1 2 3 4 5 6 7 8 9 10 11 12
BR TARGET
FI DI COFO EI WO
FI
target+1
stall stall
Clock cycle
1 2 3 4 5 6 7 8 9 10 11 12
ADD R1,R2
FI DI COFO EI WO
target
FI
stall stall
FI DI COFO EI WO
Penalty: 3 cycles
Branch not taken
At this moment the condition is
known and instr+1 can go on.
Clock cycle
1 2 3 4 5 6 7 8 9 10 11 12
ADD R1,R2
FI DI COFO EI WO
BEZ TARGET
instr i+1
Penalty: 2 cycles
FI DI COFO EI WO
FI DI COFO EI WO
FI DI COFO EI WO
Penalty: 3 cycles
R1 R1 + R2
branch if zero
BEZ TARGET
Clock cycle
target
TARGET
Branch is taken
ADD
R1,R2
BEZ
TARGET
instruction i+1
-------------------------
FI DI COFO EI WO
FI
stall stall
DI COFO EI WO
Datorarkitektur
F 3 - 13
Datorarkitektur
F 3 - 14
Summary
Control Hazards (contd)