Professional Documents
Culture Documents
An Overview of Pipelining
An Overview of Pipelining
An Overview of Pipelining
Motivating Example
Do Laundry
Wash Dry Fold Put Away
Assumption: we can break up Do Laundry into four steps, all of which take 30 minutes to complete.
Wash
30mins
Dry
30mins
Fold
30mins
Put Away
30mins
Wash
Dry Wash
Fold Dry
Wash
Dry
6 PM
10
11
12
2 AM
6 PM
10
11
12
2 AM
Note: total time is now 3h 30mins. Note: it still takes me 2 hours to complete one load. Note: after the 2nd hour, I finish one load every 30 mins.
The gains with pipelining come from throughput not from reducing the execution time of an individual instruction.
2 2 2 2
1 1 1 1
2 2 2 2
2 2
1 1
8 7 6 5
Question: If we want to build a pipelined CPU for MIPS, how will we deal with the fact that the total execution time varies according to the kind of instruction?
What you could have guessed by now: MIPS was designed for pipelining
All instructions are the same length. Operands are always aligned in memory. Few instruction formats. Few addressing modes (memory operands appear only in load and store instructions).
Add
Add
Add result
PC
Address
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Read data
1 M u x 0
16
Sign extend
32
Pipeline registers: Intermediate storage Question: How does one determine the width of these registers?
Pipeline Hazards
What if the next instruction cannot execute in the following clock cycle?
Structural hazard: Bad hardware support. We cant execute a combo of instructions in the same clock cycle. Example: memory. Solution: stall, design. Data hazard : An instruction depends on the result result of a previous instruction that is still in the pipeline.. Example: add $s0, $t0, $t1
sub $t2, $s0, $t3
Control hazard: The result of one instruction determines what happens to other instructions.. Example: branch. Solutions: stall, reorder, predict.
Program execution Time order (in instructions) add $s0, $t0, $t1 IF
10
ID
EX
MEM
WB
IF
ID
EX
MEM
WB