Documentos de Académico
Documentos de Profesional
Documentos de Cultura
3. Pipeline Hazards
Fetch - Calculate operand address (CO)
operand - Fetch operand (FO)
4. Structural Hazards
5. Data Hazards
Execute - Execute instruction (EI)
instruction - Write back operand (WO)
6. Control Hazards
Datorarkitektur Fö 3 - 3 Datorarkitektur Fö 3 - 4
• Instruction execution is extremely complex and Two stage pipeline: FI: fetch instruction
involves several operations which are executed
successively (see slide 2). This implies a large EI: execute instruction
amount of hardware, but only one part of this Clock cycle → 1 2 3 4 5 6 7 8
hardware works at a given moment.
Instr. i FI EI
Instr. i+1 FI EI
• Pipelining is an implementation technique whereby Instr. i+2 FI EI
multiple instructions are overlapped in execution.
This is solved without additional hardware but only Instr. i+3 FI EI
by letting different parts of the hardware work for Instr. i+4 FI EI
different instructions at the same time. Instr. i+5 FI EI
Instr. i+6 FI EI
• The pipeline organization of a CPU is similar to an
assembly line: the work to be done in an instruction
is broken into smaller steps (pieces), each of which
takes a fraction of the time needed to complete the
entire instruction. Each of these steps is a pipe We consider that each instruction takes execution time Tex.
stage (or a pipe segment).
• Pipe stages are connected to form a pipe: Execution time for the 7 instructions, with pipelining:
(Tex/2)*8= 4*Tex
Stage 1 Stage 2 Stage n
Datorarkitektur Fö 3 - 7 Datorarkitektur Fö 3 - 8
Penalty: 1 cycle
MUX MUX
I1: MUL R2,R3 R2 ← R2 * R3
I2: ADD R1,R2 R1 ← R1 + R2 bypass bypass
path path
ALU
Clock cycle → 1 2 3 4 5 6 7 8 9 10 11 12
Datorarkitektur Fö 3 - 11 Datorarkitektur Fö 3 - 12
Conditional branch
• Control hazards are produced by branch
instructions. ADD R1,R2 R1 ← R1 + R2
BEZ TARGET branch if zero
Unconditional branch
instruction i+1
--------------
-------------
BR TARGET
TARGET -------------
--------------
Branch is taken
TARGET -------------- At this moment, both the
condition (set by ADD) and
the target address are known.
After the FO stage of the
branch instruction the Clock cycle → 1 2 3 4 5 6 7 8 9 10 11 12
address of the target is
known and it can be fetched ADD R1,R2 FI DI COFO EI WO
BEZ TARGET FI DI COFO EI WO
Clock cycle → 1 2 3 4 5 6 7 8 9 10 11 12
target FI stall stall FI DI COFO EI WO
BR TARGET FI DI COFO EI WO Penalty: 3 cycles
target FI stall stall FI DI COFO EI WO
target+1 FI DI COFO EI WO Branch not taken
At this moment the condition is
The instruction following the known and instr+1 can go on.
branch is fetched; before Clock cycle → 1 2 3 4 5 6 7 8 9 10 11 12
the DI is finished it is not
known that a branch is exe- ADD R1,R2 FI DI COFO EI WO
cuted. Later the fetched in-
struction is discarded BEZ TARGET FI DI COFO EI WO
instr i+1 FI stall stall DI COFO EI WO
Penalty: 3 cycles
Penalty: 2 cycles
Summary
Control Hazards (cont’d)
• With conditional branch we have a penalty even if • Instructions are executed by the CPU as a
the branch has not been taken. This is because we sequence of steps. Instruction execution can be
have to wait until the branch condition is available. substantially accelerated by instruction pipelining.