---
title: "Problem set 2: pipelines, prediction and out-of-order execution"
heading: "Problem set 2: pipeline depth, branch prediction, dynamic scheduling and speculation"
eyebrow: S4 · Problem set 2
type: problems
---

::: hook
These problems cover lessons 6 to 10: optimal pipeline depth and latch overhead, misprediction costs and predictor tables, fetch rates and micro-op caches, Little's law for windows and reservation stations, renaming, and how much of a speculative window is useful.
:::

::: pool
pick: 12

::: check
kind: parts
given: t = 90 | 150; o = 3 | 5; b = 0.04 | 0.09

## A core with {t} FO4 of logic per instruction, {o} FO4 of overhead per stage and {b} stall cycles per instruction per stage.

::: part
answer: sqrt(t/(o*b))
tolerance: 1%

### Optimal depth?

::: misses
- [any] $\sqrt{t/(ob)}$.
:::
:::

::: part
answer: (sqrt(o) + sqrt(t*b))^2
tolerance: 1%

### Time per instruction there, in FO4?

::: misses
- [any] $(\sqrt o + \sqrt{tb})^2$.
:::
:::

::: part
answer: t/sqrt(t/(o*b)) + o
tolerance: 1%

### FO4 per cycle there?

::: misses
- [any] $t/k^* + o$.
:::
:::
:::

::: check
kind: parts
given: t = 120 | 160; o = 3.5 | 4.5; k = 10 | 28; b = 0.05 | 0.07

## The same model at a fixed depth of {k} stages: {t} FO4 of logic, {o} FO4 overhead, {b} stalls per instruction per stage.

::: part
answer: 100*o/(t/k + o)
unit: %
tolerance: 0.5%

### Overhead share of each cycle?

::: misses
- [any] $o/(t/k + o)$.
:::
:::

::: part
answer: (t/k + o)*(1 + b*k)
tolerance: 0.5%

### Time per instruction, in FO4?

::: misses
- [any] Cycle × CPI.
:::
:::
:::

::: check
kind: parts
given: f = 0.16 | 0.22; m = 0.03 | 0.07; s = 12 | 20; c = 0.5 | 0.9

## A core with base CPI {c}: {f} of instructions are branches, {m} mispredicted, resolved at stage {s}.

::: part
answer: f*m*(s - 1)
tolerance: 0.5%

### Misprediction CPI?

::: misses
- [any] $f_bm(s - 1)$.
:::
:::

::: part
answer: (c + f*m*(s - 1))/(c + f*m/2*(s - 1))
tolerance: 0.5%

### Speedup if a better predictor halves the misprediction rate?

::: misses
- [any] Compare total CPI.
:::
:::
:::

::: check
kind: parts
given: N = 6 | 12 | 40

## A loop of {N} iterations runs over and over.

::: part
answer: 100*2/N
unit: %
tolerance: 0.5%

### 1-bit predictor misprediction rate?

::: misses
- [any] Two per run.
:::
:::

::: part
answer: 100/N
unit: %
tolerance: 0.5%

### 2-bit counter?

::: misses
- [any] One per run.
:::
:::
:::

::: check
kind: parts
given: n = 10 | 14; B = 400 | 4000

## A predictor table of $2^{\given{n}}$ two-bit counters, with {B} active branches.

::: part
answer: 2^(n + 1)
tolerance: 0

### Table size, in bits?

::: misses
- [any] Two bits per entry.
:::
:::

::: part
answer: 1 - (1 - 2^(-n))^(B - 1)
tolerance: 0.5%

### Chance a given branch shares its entry?

::: misses
- [any] $1 - (1 - 2^{-n})^{B-1}$.
:::
:::
:::

::: check
kind: parts
given: f = 0.15 | 0.2; t = 0.55 | 0.75; h = 0.8 | 0.95; c = 2 | 4; a = 0.94 | 0.97; P = 15

## Branches are {f} of instructions, {t} of them taken; the BTB holds {h} of taken targets (miss cost {c} cycles), and direction accuracy is {a} (penalty {P}).

::: part
answer: f*t*(1 - h)*c
tolerance: 0.5%

### CPI from BTB misses?

::: misses
- [any] Taken × BTB miss × cost.
:::
:::

::: part
answer: f*(1 - a)*P
tolerance: 0.5%

### CPI from direction mispredictions?

::: misses
- [any] $f(1 - a)P$.
:::
:::
:::

::: check
kind: parts
given: w = 4 | 8; L = 25 | 50; W = 96 | 256

## A {w}-wide out-of-order core averaging {L} cycles per instruction in flight, with a {W}-entry window.

::: part
answer: w*L
tolerance: 0.5%

### Window for full width?

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

::: part
answer: (w + W/L - abs(w - W/L))/2
tolerance: 0.5%

### Sustainable IPC with {W} entries?

::: misses
- [any] min(w, W/L).
:::
:::
:::

::: check
kind: parts
given: A = 32 | 64; W = 160 | 320; f = 0.7 | 0.8; c = 2 | 3; g = 0.75 | 0.85

## A core renames {A} architectural registers for {W} in-flight instructions ({f} write a register); it has {c} result buses, and {g} of instructions produce results.

::: part
answer: A + W*f
tolerance: 0.5%

### Physical registers?

::: misses
- [any] $A + Wf$.
:::
:::

::: part
answer: c/g
tolerance: 0.5%

### IPC limit from the result buses?

::: misses
- [any] $c/f_w$.
:::
:::
:::

::: check
kind: parts
given: r = 0.6 | 1.2; l = 4 | 8; q = 3 | 6; n = 4 | 7

## A floating-point multiplier gets {r} instructions per cycle, each waiting {q} cycles for operands and executing for {l}; elsewhere, a chain of {n} dependent multiplies runs alone.

::: part
answer: r*(l + q)
tolerance: 0.5%

### Reservation stations needed on average?

::: misses
- [any] Little's law.
:::
:::

::: part
answer: n*(l + 1)
tolerance: 0

### Cycles for the chain, with 1 cycle of CDB broadcast per link?

::: misses
- [any] $n(l + 1)$.
:::
:::
:::

::: check
kind: parts
given: a = 0.94 | 0.98; f = 0.17 | 0.23; W = 100 | 300

## A {W}-entry window, a branch every 1/{f} instructions, accuracy {a}.

::: part
answer: a^(f*W)
tolerance: 0.5%

### Chance the youngest instruction is on the correct path?

::: misses
- [any] $a^{fW}$.
:::
:::

::: part
answer: (1 - a^(f*W))/(f*(1 - a))
tolerance: 0.5%

### Expected useful instructions?

::: misses
- [any] $\frac{1}{f}\frac{1 - a^{fW}}{1 - a}$.
:::
:::
:::

::: check
kind: parts
given: c = 3 | 4; w = 6 | 8; u = 0.55 | 0.75; l = 0.25 | 0.3; r = 0.01 | 0.04; p = 15 | 25

## A core fetches {w} per cycle with {u} useful and commits at most {c}; {l} of instructions are loads, {r} of them replayed at {p} cycles each.

::: part
answer: ((c + w*u) - abs(c - w*u))/2
tolerance: 0.5%

### Best IPC?

::: misses
- [any] min(c, wu).
:::
:::

::: part
answer: l*r*p
tolerance: 0.5%

### CPI added by replays?

::: misses
- [any] $f_\text{load}rp$.
:::
:::
:::

::: check
kind: parts
given: S = 18 | 25; s = 6 | 9; f = 0.2; m = 0.05 | 0.08; t = 1.3 | 1.5

## A deep pipeline resolves branches at stage {S}; a shallow one resolves them at stage {s} but its clock period is {t}× longer. Branches are {f} of instructions, {m} mispredicted; ignore other stalls.

::: part
answer: 1 + f*m*(S - 1)
tolerance: 0.5%

### CPI of the deep design?

::: misses
- [any] $1 + f_bm(s - 1)$.
:::
:::

::: part
answer: (1 + f*m*(s - 1))*t/(1 + f*m*(S - 1))
tolerance: 0.5%

### Shallow design's time per instruction relative to the deep one's?

::: misses
- [any] Its CPI × clock ratio over the deep CPI.
:::
:::
:::

::: check
kind: parts
given: w = 4 | 8; t = 6 | 10 | 16; b = 1 | 2

## A {w}-wide fetch meets a taken branch every {t} instructions and loses {b} cycle(s) on each redirection.

::: part
answer: t/(ceil(t/w - 1e-9) + b)
tolerance: 0.5%

### What fetch rate does it reach?

::: misses
- [any] $t/(\lceil t/w\rceil + b)$.
:::
:::
:::

::: check
kind: parts
given: h = 0.75 | 0.9; u = 6 | 8; d = 3 | 4

## A µop cache delivers {u} µops a cycle on hits ({h} of µops) and the decoders {d}.

::: part
answer: 1/(h/u + (1 - h)/d)
tolerance: 0.5%

### What average rate results?

::: misses
- [any] $1/(h/u + (1 - h)/d)$.
:::
:::
:::

::: check
kind: parts
given: f = 0.15 | 0.25; a = 0.95 | 0.98; P = 14 | 20; m = 3 | 8; p = 20 | 40

## Branches are {f} of instructions, predicted {a} right with a {P}-cycle penalty; the instruction cache misses {m} times per thousand instructions at {p} cycles.

::: part
answer: f*(1 - a)*P + m/1000*p
tolerance: 0.5%

### What CPI does the front end lose?

::: misses
- [any] Mispredictions plus instruction-cache stalls.
:::
:::
:::
:::
