CS429: Computer Organization and Architecture: Pipeline III
CS429: Computer Organization and Architecture: Pipeline III
Pipeline III
There are two types of hazards that interfere with flow through a
pipeline.
1 Pad the program with NOPs. That could mean two things:
Change the program itself. That violates our Pipeline
Correctness Axiom. Why?
Make the implementation behave as if there were NOPs
inserted.
2 That’s called stalling the pipeline
Data hazards:
Wait for producing instruction to complete
Then proceed with consuming instruction
Control hazards:
Wait until new PC has been determined, then fetch
Make a guess and patch later, if wrong
How is this better than inserting NOPs into the program?
Naive pipeline
Register isn’t written until completion of write-back stage.
Source operands read from register file in decode stage.
Needs to be in register file at start of stage.
Observation: value was available in execute or memory stage.
Trick:
Pass value directly from
generating instruction to
decode stage.
Needs to be available at end of
decode stage.
Decode Stage: W
W_valE
W_valM
m_valM
M_valE
Normally from M
Execute ALU
ALU
Forward
Fetch Instruction
Instruction PC
PC
valM PC f_PC
If we stall the pipeline at one stage and let the instructions ahead
proceed, that creates a gap that has to be filled.
A bubble is a “virtual nop” created by populating the pipeline
registers at that stage with values as if had there been a nop at that
point in the program. The bubble can flow through the pipeline just
like any other instruction.
Condition F D E M W
Load/Use Hazard stall stall bubble normal normal
CS429 Slideset 16: 15 Pipeline III
Control Hazards: Recall Our Prediction Strategy
Condition F D E M W
Mispredicted normal bubble bubble normal normal
Branch
ret
bubble
bubble
bubble
irmovq $5, %rsi # Return
ret
bubble
bubble
bubble
irmovq $5, %rsi # Return
Condition F D E M W
Processing ret stall bubble normal normal normal
Control Hazards
Cancel instructions when detect mispredicted branch; two
cycles wasted
Stall fetch stage while ret pass through pipeline; three cycles
wasted.
Control Combinations
Must analyze carefully
First version had a subtle bug
Only arises with unusual instruction combination
Ci + Cb Cb
CPI = = 1.0 +
Ci Ci
lp + mp + rp
CPI = 1.0 +
Ci