S4 · Lesson 6 · Pipelining limits and optimal depth
Latch overhead, hazard penalties that grow with depth, the optimal pipeline and power-aware depth
In the early 2000s one processor family stretched its pipeline past 30 stages to chase clock rate, and its successor went back to about 14. The reason is that a deeper pipeline wins clock rate but loses in two ways. Every stage adds latch overhead that no amount of splitting removes, and every hazard that empties the pipeline (a mispredicted branch, above all) costs more cycles the deeper the pipeline is. Somewhere between too shallow and too deep is an optimum, and once power is counted, the optimum moves shallower still. This lesson finds it.
- Time per instruction, in FO4 delays, against pipeline depth k: , with t FO4 of logic per instruction, o FO4 of overhead per stage, and b stall cycles per instruction per stage of depth.
- The marker is the depth that minimizes TPI, . The curve is flat near it, so a few stages either way cost little.
- Dashed: the power-aware metric BIPS³/W (performance cubed over power, with each stage's latches adding power), scaled to its own peak. Its optimum is shallower.
Predict
A core has 100 FO4 of logic per instruction, 4 FO4 of overhead per stage, and loses 0.05 cycles per instruction per stage to hazards. Which depth gives the shortest time per instruction?
= 22.4 stages, about 8.5 FO4 per stage and a CPI of 2.1, for 17.9 FO4 per instruction. Five stages give 30 FO4 and 40 stages 19.5. But latches cost power: with each stage adding 5% to the core's power, the depth that maximizes BIPS³/W is about 16, and for plain BIPS/W about 11. Product lines that weigh power heavily build shallower pipelines.
Name it
Why a pipeline can't be split forever
- Overhead per stage: latch delay, setup, clock skew and jitter, together o, about 2 to 5 FO4. The period is , never below o.
- Imbalance: stages can't be cut at arbitrary points; the slowest one sets the clock.
- Hazards that grow with depth: a branch resolved at the end of a deep front end flushes more instructions, and load-use distances grow in cycles. A simple model charges stall cycles per instruction per stage, so CPI = 1 + bk.
The optimum
At the optimum the overhead's share and the hazards' share balance. Studies of real workloads found the performance optimum near 6 to 8 FO4 of logic per stage.
Counting power
Each stage's latches and clocking add power, roughly . Metrics that weigh energy, such as BIPS/W or BIPS³/W (whose ranking doesn't change when voltage scaling trades speed for power), have shallower optima than raw performance.
The FO4 yardstick
Expressing delays in FO4 (S3.18) makes these results independent of the process: a 100 FO4 instruction path in 22 stages runs at about 8.5 FO4 per cycle in any technology.
Worked example
With t = 100 FO4, o = 4 FO4 and b = 0.05, compare 5, 10, 22 and 40 stages.
Show the solution
- 5 stages.
- 10 stages.
- 22.4 stages, the optimum.
- 40 stages.
- What the extra depth bought. The last 18 stages beyond the optimum bought a clock 1.3 times faster and lost it all to the CPI.
Answer 30, 21, 17.9 and 19.5 FO4 per instruction for 5, 10, 22 and 40 stages, so about 22 stages is best.
Worked example
A mispredicted branch in a 14-stage pipeline resolves at stage 11. With 20% branches and a 5% misprediction rate, what CPI do mispredictions add? What if a 31-stage pipeline resolves at stage 25?
Show the solution
- 14 stages, resolving at stage 11. The penalty is 10 cycles:
- 31 stages, resolving at stage 25. The penalty is 24 cycles:
- What the deeper pipeline must overcome. Its faster clock has to outrun 0.14 more CPI from branches alone, before counting longer load-use and cache-hit latencies in cycles.
Answer mispredictions add 0.10 CPI to the 14-stage pipeline and 0.24 CPI to the 31-stage one.
Worked example
An instruction's path is 120 FO4 of logic, each stage adds 3 FO4 of overhead, and hazards cost 0.1 cycles per instruction per stage. What depth is best, and how much logic does each stage hold there?
Show the solution
- Best depth. each with 120/20 = 6 FO4 of logic.
- Time per instruction. which also equals .
- Compare with real designs. That 6 FO4 per stage agrees with the 6 to 8 FO4 that studies of real workloads found.
Answer 20 stages is best, each holding 6 FO4 of logic.
Check
A core has 120 FO4 of logic per instruction, 3 FO4 of overhead per stage and loses 0.08 cycles per instruction per stage of depth. What depth minimizes time per instruction?
Check
With 80 FO4 of logic, 3 FO4 of overhead and 0.1 stalls per instruction per stage, what's the time per instruction at 30 stages, in FO4?
Check
A pipeline of 20 stages splits 100 FO4 of logic evenly, with 3 FO4 of overhead per stage. What fraction of each cycle is overhead?
Check
Branches are 0.15 of instructions, 0.03 of them mispredicted, and they resolve at stage 25. How much CPI do mispredictions add?
Check
How many FO4 is each cycle when 100 FO4 of logic is split over 25 stages with 3 FO4 of overhead?
Check
At the optimal depth, what's the time per instruction for t = 100 FO4, o = 3 FO4 and b = 0.08?
Check
An instruction's path is 120 FO4; each stage adds 2 FO4 of overhead, and hazards cost 0.08 cycles per instruction per stage.
(a)
What is the time per instruction with 20 stages?
(b)
What depth minimizes it?
Check
A pipeline's time per instruction is .
Step 1
What depth k minimizes it?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the least time per instruction?
Step 3
How much logic does each stage hold at the optimum?
Check
Write best_depth(t, o, b, p=None): search depths k = 1 to 100 and return (best k, its time per instruction ). With p = None, minimize the time; with a number p, maximize , , for power that grows as .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does counting power push the best pipeline depth shallower than the depth that maximizes performance?
Near the performance optimum, the time per instruction is almost flat: adding or removing a few stages changes performance only slightly. Each extra stage, though, adds a full row of latches, more clock load and more speculative work thrown away on every misprediction, so power keeps rising steadily with depth. A metric that weighs power, such as performance per watt or BIPS³/W, therefore gains more from removing stages than it loses in speed, until the speed loss becomes steep. That moves its optimum to a shallower depth than raw performance alone would choose, which is why power-conscious designs settled on moderate pipelines.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.