Computer Architecture: Pipelining Khiyam Iftikhar
Computer Architecture: Pipelining Khiyam Iftikhar
Pipelining
Khiyam Iftikhar
Why not Single-Cycle
• All instruction take same time
– Clock cycle is equal to worst case delay
– No benefit of making common case fast
Pipelining: Laundry analogy
Performance
• Conlusion: Pipelined is ‘n’ times faster where
‘n’ is number of stages.
MIPS Single Cycle Vs Pipelined
Cycle Time Period
• Cycle time for single cycle is equal to
combined delay of all the sources for the
longest instruction (that requires max time
• Cycle time for pipelined is equal to delay of
the slowest stage.
MIPS Single Cycle Vs Pipelined
Cycle Time Period
Designing instruction set for Pipelining
MIPS was designed for pipelining
• All instructions are of same length.
– So 1 fetch stage.
• All instruction have source registers at the same place
– So 1 decode stage.
– So instruction is decoded at the same time when the operands are fetched
from registers.
• Memory is accessed only in lw and sw
– If it was allowed to operate on memory, execute stage should be split to three
stages, address calculation, memory access, execute.
• Operands must be aligned in memory.
– So a single data transfer requires one memory access; otherwise two
accesses are required.
Pipeline Hazards: Structural
• Hardware doesn’t support combination of
instructions that are executed in a clock cycle
• Example:
– Single Data and instruction memory
– Lw is WriteBack Stage
Data Hazard
• Operands of an instruction depend upon
result of previous instruction
1 cycle delay
Example:Pipelined Datapath cycle by cycle
detail
Solution
• No of stalls without forwarding is 2
• Reordered code is
Pipelined Datapath R-type,lw/sw,branch
Datapath with Forwarding Unit
Resolving Data Hazards:
Data Forwarding Type 1
Resolving Data Hazards:
Data Forwarding Type 2
Example :Dependency detection
Cases Where even Data Forwarding creates a Stall (Bubble)
It changes state from ‘Predict Not Taken’ to ‘Predict Taken’ after 2 consecutive Taken
Delayed Execution
• Place an instruction which is not effected by
result of branch, after branch instruction