---
title: Problem set 8
heading: "Problem set 8: datapaths, pipelines and prediction"
eyebrow: C8 · Problem set 8
type: problems
---

::: hook
These problems use lessons 35 to 42: the single-cycle processor, caches and pipelines, pipelining and hazards, branch prediction with superscalar and multicore processors, and SIMD and vector instructions. Addresses are 32 bits, 1 KiB is 1024 bytes, and a pipeline's branch penalty is paid only on mispredictions.
:::

::: pool
pick: 12

::: check
kind: parts
given: cq = 30 | 45; m = 160 | 240; r = 90 | 130; l = 110 | 170; x = 25 | 40; s = 45 | 70

## A single-cycle processor's units take: register clock-to-Q {cq}, each memory {m}, register-file read {r}, ALU {l}, result mux {x}, register-file setup {s} (all ps).

::: part
answer: cq + 2*m + r + l + x + s
unit: ps
tolerance: 0.5%

### What is the clock period?

::: misses
- [cq + m + r + l + x + s] A load reads two memories.
- [any] Not yet. The load's path from PC to register file.
:::
:::

::: part
answer: (cq + 2*m + r + l + x + s - m)/(cq + 2*m + r + l + x + s)*100
unit: %
tolerance: 0.5%

### What percentage of the cycle does an R-type instruction, which skips the data memory, actually need?

::: misses
- [any] The period minus the data memory, over the period.
:::
:::
:::

::: check
kind: parts
given: Tc = 700 | 900; l = 120 | 150; u = 280 | 400; F = 0.02 | 0.1

## A slow unit of {u} ps is added in parallel with the {l} ps ALU of a {Tc} ps single-cycle processor, on the critical path. A fraction {F} of instructions use it.

::: part
answer: Tc + u - l
unit: ps
tolerance: 0.5%

### What is the new clock period?

::: misses
- [Tc + u] The new unit replaces the ALU's delay on the path; it doesn't add to it.
- [any] Not yet. Grows by the difference.
:::
:::

::: part
answer: (Tc + u - l)/Tc
tolerance: 0.5%

### By what factor does every program slow down, however few instructions use the unit?

::: misses
- [1 + F*(u - l)/Tc] In a single-cycle design every instruction gets the longer cycle.
- [any] Not yet. New period over old.
:::
:::
:::

::: check
kind: parts
given: h = 1 | 2; m = 0.02 | 0.05 | 0.1; P = 40 | 100; m2 = 0.01 | 0.015

## A cache hits in {h} cycles and misses {m} of the time, with a {P}-cycle miss penalty.

::: part
answer: h + m*P
unit: cycles
tolerance: 0.5%

### What is the average memory access time?

::: misses
- [m*P] Every access pays the hit time.
- [h + P] Only the misses pay the penalty.
- [any] Not yet. $t_\text{hit} + m \cdot t_\text{penalty}$.
:::
:::

::: part
answer: (h + m*P)/(h + m2*P)
tolerance: 0.5%

### A larger cache with the same hit time misses only {m2} of the time. By what factor does the AMAT improve?

::: misses
- [any] Old AMAT over new.
:::
:::
:::

::: check
kind: parts
given: C = 4 | 16 | 64; L = 16 | 32 | 64; let lines = C*1024/L

## A direct-mapped cache holds {C} KiB in {L}-byte lines, for 32-bit addresses.

::: part
answer: log(L)/log(2)
tolerance: 0.5%

### How many offset bits?

::: misses
- [any] $\log_2$ of the line size.
:::
:::

::: part
answer: 32 - log(lines)/log(2) - log(L)/log(2)
tolerance: 0.5%

### How many tag bits?

::: misses
- [32 - log(lines)/log(2)] Take off the offset bits too.
- [any] Not yet. 32 − index − offset, with $\log_2$ of the line count for the index.
:::
:::
:::

::: check
kind: parts
given: k = 5 | 6 | 8; N = 50 | 200 | 5000; T = 800 | 1000; r = 40

## A single-cycle design with {T} ps of logic and a {r} ps register is pipelined into {k} equal stages, each adding a {r} ps register. It runs {N} instructions with no stalls.

::: part
answer: k + N - 1
unit: cycles
tolerance: 0

### How many cycles does the pipeline take?

::: misses
- [N] The first instruction takes {k} cycles to fill the pipeline.
- [any] Not yet. k + N − 1.
:::
:::

::: part
answer: N*(T + r)/((k + N - 1)*(T/k + r))
tolerance: 0.5%

### How many times faster than the single-cycle design is it on these instructions?

::: misses
- [k] The register overhead and the pipeline fill keep it below {k}.
- [any] Not yet. Single-cycle time over pipelined time.
:::
:::
:::

::: check
kind: parts
given: a = 170 | 230; b = 200 | 260; c = 90 | 150; o = 35 | 55

## A five-stage pipeline's stages take {a}, {b}, {c}, {b} and {c} ps, and each pipeline register adds {o} ps.

::: part
answer: (a + b + abs(a - b))/2 + o
unit: ps
tolerance: 0.5%

### What is the clock period?

::: misses
- [a + 2*b + 2*c + o] The period is set by the slowest stage, not the sum.
- [any] Not yet. Slowest stage + overhead.
:::
:::

::: part
answer: 1e6/((a + b + abs(a - b))/2 + o)
unit: MHz
tolerance: 0.5%

### What is the clock frequency?

::: misses
- [any] One over the period.
:::
:::
:::

::: check
kind: parts
given: L = 0.2 | 0.3; u = 0.25 | 0.5; B = 0.12 | 0.18; t = 0.4 | 0.7; p = 2 | 3

## {L} of instructions are loads, {u} of which are used by the very next instruction; {B} are branches, {t} of them taken, predicted not taken at a {p}-cycle penalty. Forwarding is complete.

::: part
answer: 1 + L*u + B*t*p
tolerance: 0.5%

### What is the CPI?

::: misses
- [1 + L*u + B*p] Only the taken branches are mispredicted.
- [1 + B*t*p] Load-use pairs still stall a cycle with forwarding.
- [any] Not yet. 1 + L·u + B·t·p.
:::
:::

::: part
answer: L*u/(L*u + B*t*p)*100
unit: %
tolerance: 0.5%

### What percentage of the stall cycles come from load-use hazards?

::: misses
- [any] Load-use stalls over all stalls.
:::
:::
:::

::: check
kind: parts
given: n = 3 | 6 | 12; m = 50 | 500

## An inner loop of {n} iterations runs {m} times; ignore the first run.

::: part
answer: (n - 2)/n*100
unit: %
tolerance: 0.5%

### What accuracy does a 1-bit predictor reach on the loop's closing branch?

::: misses
- [(n - 1)/n*100] That's the 2-bit predictor. A 1-bit one also misses the first iteration.
- [any] Not yet. Two misses per {n}.
:::
:::

::: part
answer: m - 1
tolerance: 0

### How many mispredictions does a 2-bit predictor make in the counted runs?

::: misses
- [2*(m - 1)] Two wrong guesses in a row are needed to flip a 2-bit counter, so only the exit is missed.
- [any] Not yet. One per run.
:::
:::
:::

::: check
kind: parts
given: B = 0.2; a = 0.9 | 0.97; T1 = 400 | 450; T2 = 200 | 250; p1 = 2; p2 = 10 | 14

## Design X has a short pipeline: {T1} ps cycle, {p1}-cycle misprediction penalty. Design Y is deeper: {T2} ps cycle, {p2}-cycle penalty. Branches are {B} of instructions, predicted with accuracy {a}; the base CPI is 1.

::: part
answer: T1*(1 + B*(1 - a)*p1)
unit: ps
tolerance: 0.5%

### What is X's time per instruction?

::: misses
- [any] Cycle time × (1 + B(1 − a)p).
:::
:::

::: part
answer: T1*(1 + B*(1 - a)*p1)/(T2*(1 + B*(1 - a)*p2))
tolerance: 0.5%

### How many times faster is Y than X?

::: misses
- [T1/T2] The deeper pipeline pays more per misprediction.
- [any] Not yet. X's time per instruction over Y's.
:::
:::
:::

::: check
kind: parts
given: w = 2 | 3 | 4; s = 0.05 | 0.2 | 0.4

## A {w}-wide superscalar processor loses {s} cycles per instruction to stalls.

::: part
answer: 1/w + s
tolerance: 0.5%

### What is its CPI?

::: misses
- [any] 1/w + stalls.
:::
:::

::: part
answer: (1/w + s)/(1 + s)
tolerance: 0.5%

### What fraction of the CPI of a 1-wide design with the same stalls is that?

::: misses
- [1/w] The stalls don't shrink with width.
- [any] Not yet. (1/w + s)/(1 + s).
:::
:::
:::

::: check
kind: parts
given: p = 0.7 | 0.85 | 0.97; n = 2 | 8 | 32

## A fraction {p} of a job runs in parallel on {n} cores.

::: part
answer: 1/((1 - p) + p/n)
tolerance: 0.5%

### What is the speedup over one core?

::: misses
- [n] The serial part doesn't speed up.
- [any] Amdahl's law.
:::
:::

::: part
answer: 1/(1 - p)
tolerance: 0.5%

### What is the most any number of cores could give?

::: misses
- [any] Let n grow without limit.
:::
:::
:::

::: check
kind: parts
given: k = 2 | 4 | 8; s = 0.5 | 0.7; v = 0.75 | 0.85

## A chip uses {k} cores at {s} of the original clock and {v} of the voltage, in place of one fast core.

::: part
answer: k*v^2*s
tolerance: 0.5%

### What is its dynamic power relative to the single core?

::: misses
- [k*s] Lower voltage also cuts power, as its square.
- [any] Not yet. k·v²·s.
:::
:::

::: part
answer: k*s/(k*v^2*s)
tolerance: 0.5%

### How many times the single core's work per joule does it do on parallel work?

::: misses
- [any] Throughput over power.
:::
:::
:::

::: check
kind: parts
given: d = 20 | 30 | 40; l = 20 | 25; u = 30 | 50

## Without forwarding, {d}% of instructions stall 2 cycles for the one before. With forwarding, only loads ({l}%) used at once ({u}% of them) stall 1 cycle.

::: part
answer: 1 + 2*d/100
tolerance: 0.5%

### What is the CPI without forwarding?

::: misses
- [any] $1 + 2d$.
:::
:::

::: part
answer: (1 + 2*d/100)/(1 + l/100*u/100)
tolerance: 0.5%

### How many times faster does forwarding make it?

::: misses
- [any] The ratio of CPIs.
:::
:::
:::

::: check
kind: parts
given: T = 800 | 1000; k = 5 | 8 | 12; o = 20 | 40

## {T} ps of logic is split into {k} equal stages, each with {o} ps of register overhead.

::: part
answer: T/k + o
unit: ps
tolerance: 0.5%

### What is the clock period?

::: misses
- [T/k] Add the register overhead.
- [any] $T/k + o$.
:::
:::

::: part
answer: T/(T/k + o)
tolerance: 0.5%

### What is the speedup at a CPI of 1?

::: misses
- [k] The overhead keeps it below {k}.
- [any] $T/(T/k + o)$.
:::
:::
:::

::: check
kind: parts
given: b = 15 | 20; a = 85 | 92 | 97; p = 2 | 3 | 10

## {b}% of instructions are branches, predicted with {a}% accuracy; a misprediction costs {p} cycles.

::: part
answer: 1 + b/100*(1 - a/100)*p
tolerance: 0.5%

### What is the CPI, with no other stalls?

::: misses
- [any] $1 + b(1 - a)p$.
:::
:::

::: part
answer: b/100*(1 - a/100)*p/(1 + b/100*(1 - a/100)*p)*100
unit: %
tolerance: 0.5%

### What share of cycles are lost to mispredictions?

::: misses
- [any] Stall cycles ÷ total.
:::
:::
:::

::: check
kind: parts
given: f = 0.7 | 0.85 | 0.95; L = 4 | 8 | 16; n = 50 | 1000

## A fraction {f} of a program vectorizes onto {L} lanes, and its hot loop handles {n} elements.

::: part
answer: 1/((1 - f) + f/L)
tolerance: 0.5%

### What's the overall speedup?

::: misses
- [L] Only the vectorized part speeds up.
- [any] Not yet. Amdahl: $1/((1 - f) + f/L)$.
:::
:::

::: part
answer: 1/(1 - f)
tolerance: 0.5%

### What's the most any vector width could give?

::: misses
- [L] With infinitely many lanes, only the serial part remains.
- [any] Not yet. Let $L \to \infty$.
:::
:::

::: right
Right. The serial fraction caps the speedup however wide the vectors get.
:::
:::
:::
