S4 · Lesson 13 · Superscalar, VLIW and the limits of ILP
Issuing several instructions per cycle, the hardware cost of width, static scheduling and loop unrolling
If one instruction per cycle is good, four should be better. Superscalar cores fetch, rename, issue and commit several instructions per cycle, finding the parallelism in hardware; VLIW machines leave that job to the compiler, which packs independent operations into long instruction words. Both hit the same two walls. Programs have only so much instruction-level parallelism (ILP), limited by true dependences and by how far ahead the machine can see. And the hardware that finds and feeds parallel instructions grows faster than the width: the wake-up logic with width times window, the bypass network with the square of the width. Real cores settled at 4 to 8 wide.
- The cost of an out-of-order issue stage against the issue width w, for a window of W entries.
- Wake-up: every result broadcast is compared with both source tags of every waiting instruction, comparators each cycle (solid, in thousands).
- Bypass: each of w units forwards to both inputs of all w units, at every one of s bypass stages, paths (dashed). Both grow faster than the IPC they could deliver.
Predict
A loop adds the elements of an array into one floating-point sum. The adder is pipelined with a latency of 4 cycles and can start one add per cycle. How fast can the loop run, and how could it run faster?
One add every 4 cycles: each add needs the previous sum, a true dependence no hardware can break, so the pipelined adder sits 3/4 idle and a wider core doesn't help. Unrolling the loop with 4 independent partial sums gives the adder 4 chains to interleave, one add per cycle, and the partial sums are added at the end. (Floating-point addition isn't associative, so compilers only do this when told the reordering is acceptable.)
Name it
How much ILP is there?
For a block of N instructions whose longest chain of dependences is C instructions long (each taking a cycle), no machine can beat IPC = N/C, the dataflow limit. Studies with perfect prediction and unlimited windows found ILP in the hundreds; with realistic predictors, windows and memory latencies, typical integer code sustains 1 to 3.
Superscalar costs
- Fetch must deliver w instructions per cycle across taken branches (trace caches, decoupled fetch).
- Rename reads the map table for 2w sources and w old destinations, and checks dependences among the w instructions renamed together.
- Wake-up compares w result tags against 2W source tags: comparators.
- Bypass: forwarding paths; the wires lengthen with width, slowing the cycle. Wide cores often split into clusters with a cycle of delay between them.
VLIW
The compiler schedules operations into fixed slots of a long instruction, so the hardware needs no dependence checking. Empty slots become NOPs, inflating code by for an average of filled slots; unknown latencies (cache misses) stall the whole word; and a new implementation with different latencies needs recompilation. VLIW thrives in DSPs and accelerators, where code is regular and the compiler knows the hardware exactly.
Exposing ILP in software
Loop unrolling copies the body U times, giving the scheduler independent operations to interleave; a reduction with latency L needs L independent partial results to keep a pipelined unit busy. Each copy needs its own registers, so unrolling is limited by register pressure.
Worked example
A basic block has 24 instructions and its longest dependence chain is 8 long. What's the best IPC on any machine, and on a 4-wide one? What do wake-up and bypass cost for a 4-wide and an 8-wide core with a 128-entry window and 2 bypass stages?
Show the solution
- Dataflow limit. so even the 4-wide core can't exceed an IPC of 3 on this block.
- Wake-up comparators.
- Bypass paths.
- What the width buys. Doubling the width quadruples the bypass network to raise IPC only where the program has more than 3 to give.
Answer the best IPC is 3 on any machine, including the 4-wide one; wake-up needs 1024 comparators at 4-wide and 2048 at 8-wide, and bypass needs 64 paths and 256.
Worked example
A VLIW machine has 6 slots, and the compiler fills 2.4 of them on average. How much bigger is the code than a packed encoding, and what fraction of slots are wasted?
Show the solution
- Code size. times the size of a packed encoding.
- Wasted slots. of the slots hold NOPs.
- The fix. Later VLIW designs (such as EPIC) marked groups of independent instructions with stop bits instead of padding with NOPs, so code density doesn't depend on how full each cycle is.
Answer the code is 2.5 times bigger, and 60% of the slots are wasted.
Worked example
A loop sums an array through a floating-point adder with a 4-cycle latency that accepts one add per cycle. How many independent accumulators keep it busy, and what rate does one accumulator get?
Show the solution
- One accumulator. Each add needs the previous sum, so a new add starts only every 4 cycles:
- Four accumulators. Combined at the end, they interleave four independent chains and fill the pipeline: one add per cycle.
- Why it matters. That's what unrolling a reduction is for, and why compilers need permission to reassociate floating-point sums.
Answer four independent accumulators keep the adder busy; one accumulator gets only 0.25 adds per cycle.
Check
A block of 36 instructions has a longest dependence chain of 5 single-cycle instructions. What's its dataflow-limited IPC?
Check
A 4-wide core has a 64-entry window, each entry with two source tags. How many tag comparators does wake-up need per cycle?
Check
A 4-wide core forwards results from 1 pipeline stages to both inputs of every unit. How many bypass paths does it need?
Check
A reduction loop uses a pipelined unit of latency 4 that can start 2 operation(s) per cycle. How many independent partial results keep it fully busy?
Check
A 6-slot VLIW machine fills 1.5 slots per word on average. How many times larger is its code than a dense encoding of the same operations?
Check
A loop body uses 3 registers per iteration plus 6 shared ones. Unrolled 4 times, how many registers does it need?
Check
A basic block has 24 instructions with a longest dependence chain of 6. An 8-wide core has a 192-entry window and 1 bypass stages.
(a)
What is the best IPC the block can reach on this core?
(b)
How many tag comparators does wake-up need?
(c)
How many bypass paths?
Check
A VLIW machine has w slots per instruction, and the compiler fills k of them on average.
Step 1
By how much is the code inflated against a packed encoding?
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 fraction of slots hold NOPs?
Explain why
Why did superscalar widths stop growing at around 4 to 8, even though transistors kept getting cheaper?
Two limits meet. Ordinary programs have only a few independent instructions ready at a time once real branch prediction, cache misses and finite windows are counted, so the IPC a wider machine could deliver grows slowly. Meanwhile the structures that find and feed those instructions grow faster than the width: wake-up compares every result against every waiting operand, renaming must check dependences among all instructions renamed together, and the bypass network connects every unit to every other one, so it grows with the square of the width and its long wires slow the clock. Past a modest width, the extra hardware costs more in cycle time, power and area than it returns in IPC, and the transistors are better spent on more cores, bigger caches or accelerators.
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.