---
title: Superscalar, VLIW and the limits of ILP
heading: Issuing several instructions per cycle, the hardware cost of width, static scheduling and loop unrolling
eyebrow: S4 · Lesson 13 · Superscalar, VLIW and the limits of ILP
xp: 50
---

::: hook
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.
:::

::: play
- 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, $2wW$ 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, $2sw^2$ paths (dashed). Both grow faster than the IPC they could deliver.
:::
:::

```sim plot
view: graph
x: w = 1..16 step 1
y: n = 0..10
slider: W = 32..512 = 128 log
slider: s = 1..3 step 1 = 2
plot: 2*w*W/1000 | samples: 400 | label: wake-up comparators, thousands
plot: 2*s*w^2/100 | samples: 400 | dashed | color: ch2 | label: bypass paths, hundreds
```

::: 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 per cycle, already
- [x] One add every 4 cycles, until the sum is split into 4 partial sums
- [ ] One add per cycle with a wider core
- [ ] One add every 2 cycles

::: reveal
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.)
:::
:::

::: nameit
## 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: $2wW$ comparators.
- Bypass: $2sw^2$ 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 $w/\bar k$ for an average of $\bar k$ 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.
:::

::: 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?

::: solution
1. **Dataflow limit.**
   $$24/8 = 3$$
   so even the 4-wide core can't exceed an IPC of 3 on this block.
2. **Wake-up comparators.**
   $$\begin{aligned} \text{4-wide: } 2 \times 4 \times 128 &= 1024 \\ \text{8-wide: } 2 \times 8 \times 128 &= 2048 \end{aligned}$$
3. **Bypass paths.**
   $$\begin{aligned} \text{4-wide: } 2 \times 2 \times 16 &= 64 \\ \text{8-wide: } 2 \times 2 \times 64 &= 256 \end{aligned}$$
4. **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.
:::
:::

::: 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?

::: solution
1. **Code size.**
   $$6/2.4 = 2.5$$
   times the size of a packed encoding.
2. **Wasted slots.**
   $$1 - 2.4/6 = 60\%$$
   of the slots hold NOPs.
3. **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.
:::
:::

::: 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?

::: solution
1. **One accumulator.** Each add needs the previous sum, so a new add starts only every 4 cycles:
   $$1/4 = 0.25\ \text{adds per cycle}$$
2. **Four accumulators.** Combined at the end, they interleave four independent chains and fill the pipeline: one add per cycle.
3. **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
given: N = 20 | 36 | 60; C = 5 | 9 | 12
answer: N/C
tolerance: 0.5%

## A block of {N} instructions has a longest dependence chain of {C} single-cycle instructions. What's its dataflow-limited IPC?

::: right
Right. N/C = {answer}.
:::

::: misses
- [C/N] IPC is instructions per cycle: the chain sets the cycles.
- [any] Not yet. N instructions in at least C cycles.
:::
:::

::: check
given: w = 2 | 4 | 6 | 8; W = 64 | 192
answer: 2*w*W
tolerance: 0.5%

## A {w}-wide core has a {W}-entry window, each entry with two source tags. How many tag comparators does wake-up need per cycle?

::: right
Right. $2wW$ = {answer}.
:::

::: misses
- [w*W] Each entry has two source tags.
- [any] Not yet. Every result tag against every source tag.
:::
:::

::: check
given: w = 2 | 4 | 6 | 8; s = 1 | 2 | 3
answer: 2*s*w^2
tolerance: 0.5%

## A {w}-wide core forwards results from {s} pipeline stages to both inputs of every unit. How many bypass paths does it need?

::: right
Right. $2sw^2$ = {answer}.
:::

::: misses
- [2*s*w] Every unit's result goes to every unit, not only its own.
- [any] Not yet. Sources × destinations × stages.
:::
:::

::: check
given: L = 3 | 4 | 6; r = 2 | 3
answer: L*r
tolerance: 0

## A reduction loop uses a pipelined unit of latency {L} that can start {r} operation(s) per cycle. How many independent partial results keep it fully busy?

::: right
Right. Latency × issue rate: {answer}.
:::

::: misses
- [L] Each cycle the unit can start r operations, each needing its own chain.
- [any] Not yet. Little's law: operations in flight = rate × latency.
:::
:::

::: check
given: w = 4 | 6 | 8; k = 1.5 | 2.4 | 3.2
answer: w/k
tolerance: 0.5%

## A {w}-slot VLIW machine fills {k} slots per word on average. How many times larger is its code than a dense encoding of the same operations?

::: right
Right. $w/\bar k$ = {answer}.
:::

::: misses
- [k/w] Empty slots add size.
- [any] Not yet. Slots per word over useful operations per word.
:::
:::

::: check
given: U = 2 | 4 | 8; r = 3 | 5; b = 4 | 6
answer: U*r + b
tolerance: 0

## A loop body uses {r} registers per iteration plus {b} shared ones. Unrolled {U} times, how many registers does it need?

::: right
Right. $Ur + b$ = {answer}.
:::

::: misses
- [U*(r + b)] The shared registers aren't copied.
- [any] Not yet. Each copy needs its own working registers.
:::
:::

::: check
kind: parts
given: N = 24 | 48; C = 6 | 12; w = 4 | 8; W = 64 | 192; s = 1 | 2

## A basic block has {N} instructions with a longest dependence chain of {C}. A {w}-wide core has a {W}-entry window and {s} bypass stages.

::: part
answer: N/C - (N/C - w)*step(N/C - w)
tolerance: 0.5%

### What is the best IPC the block can reach on this core?

::: misses
- [any] The smaller of the dataflow limit N/C and the width.
:::
:::

::: part
answer: 2*w*W
tolerance: 0
unit: comparators

### How many tag comparators does wake-up need?

::: misses
- [any] $2wW$.
:::
:::

::: part
answer: 2*s*w^2
tolerance: 0
unit: paths

### How many bypass paths?

::: misses
- [any] $2sw^2$.
:::
:::
:::

::: check
kind: derivation
vars: w = 2..16, k = 1..8

## A VLIW machine has w slots per instruction, and the compiler fills k of them on average.

::: step
answer: w/k

### By how much is the code inflated against a packed encoding?
:::

::: step
answer: 1 - k/w

### What fraction of slots hold NOPs?
:::

::: right
Right. That's why later VLIW designs (EPIC) added stop bits and compressed encodings.
:::
:::

::: explain
## Why did superscalar widths stop growing at around 4 to 8, even though transistors kept getting cheaper?

::: model
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

::: check
given: N = 30 | 48; C = 6 | 10
answer: N/C
tolerance: 0.5%

## Dataflow IPC: {N} instructions, chain {C}?

::: misses
- [any] N/C.
:::
:::

::: check
given: w = 3 | 6; W = 96 | 256
answer: 2*w*W
tolerance: 0.5%

## Wake-up comparators: {w}-wide, {W} entries?

::: misses
- [any] $2wW$.
:::
:::

::: check
given: L = 5 | 8; r = 1 | 2
answer: L*r
tolerance: 0

## Partial sums for latency {L}, {r} per cycle?

::: misses
- [any] $Lr$.
:::
:::
:::
