L14 MipsPipeline Ovw
L14 MipsPipeline Ovw
Assume 30 min. each task – wash, dry, fold, store – and that
separate tasks use separate hardware and so can be overlapped
6 PM 7 8 9 10 11 12 1 2 AM
Time
Task
order
A
Pipelined
B
D
Pipelining Example
• Assume: One instruction format (easy)
• Assume: Each instruction has 3 steps S1..S3
• Assume: Pipeline has 3 segments (one/step)
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5
Seg #1 S1 S2 S3 S1 S2
Seg #2 S1 S2 S3 S1
Seg #3 S1 S2 S3
Time
New Instruction
Pipelined vs. Single-Cycle
Instruction Execution: the Plan
Program
execution 2 4 6 8 10 12 14 16 18
order Time
(in instructions)
Instruction Data Single-cycle
lw $1, 100($0) fetch
Reg ALU
access
Reg
Instruction Data
lw $2, 200($0) 8 ns fetch
Reg ALU
access
Reg
Instruction
lw $3, 300($0) 8 ns fetch
...
8 ns
Instruction Data
Pipelined
lw $2, 200($0) 2 ns Reg ALU Reg
fetch access
Instruction Data
lw $3, 300($0) 2 ns Reg ALU Reg
fetch access
2 ns 2 ns 2 ns 2 ns 2 ns
Pipelining: Keep in Mind
• Pipelining does not reduce latency of a single task,
it increases throughput of entire workload
• Pipeline rate limited by longest stage
– potential speedup = number pipe stages
– unbalanced lengths of pipe stages reduces speedup
• Time to fill pipeline and time to drain it – when
there is slack in the pipeline – reduces speedup
Pipelining MIPS
• What makes it easy with MIPS?
– all instructions are same length
• so fetch and decode stages are similar for all instructions
– just a few instruction formats
• simplifies instruction decode and makes it possible in one stage
– memory operands appear only in load/stores
• so memory access can be deferred to exactly one later stage
– operands are aligned in memory
• one data transfer instruction requires one memory access stage
Pipelining MIPS
• What makes it hard?
– structural hazards: different instructions, at different stages,
in the pipeline want to use the same hardware resource
– control hazards: succeeding instruction, to put into pipeline,
depends on the outcome of a previous branch instruction,
already in pipeline
– data hazards: an instruction in the pipeline requires data to be
computed by a previous instruction still in the pipeline
IF ID EX MEM WB
Conclusions
• Pipelining improves efficiency by:
– Regularizing instruction format => simplicity
– Partitioning each instruction into steps
– Making each step have about the same work
– Keeping the pipeline almost always full (occupied) to
maximize processor throughput
• Pipeline control is complicated
– Forwarding
– Hazard detection and avoidance