5.4.4 · D3Memory Hierarchy & Caches

Worked examples — Cache line size and tags

2,480 words11 min readBack to topic

This page is the drill hall for the parent note. There we learned the recipe: split every address into [ Tag | Index | Offset ]. Here we push that recipe through every kind of input it can meet — big caches, tiny caches, associativity, 64-bit machines, and the sneaky "degenerate" cases where a field shrinks to zero bits.

Before we start, one sentence of ground-truth so no symbol sneaks in undefined:


The scenario matrix

Every cache-address problem is one of a handful of case classes. Below is the full grid; each worked example afterwards is tagged with the cell it hits, so together they cover every cell.

# Case class What makes it special Example
A Baseline direct-mapped , all three fields non-trivial Ex 1
B Splitting a concrete address turn hex/binary into T, I, O values Ex 2
C Set-associative shrinks index, grows tag Ex 3
D Fully associative (degenerate index) — no index field at all Ex 4
E Line = whole cache (degenerate index, other end) one line only, again Ex 4b (inside Ex 4)
F Offset = 0 (degenerate offset) byte, no offset field Ex 5
G 64-bit / huge address space , giant tag Ex 6
H Real-world word problem array-stride & spatial locality Ex 7
I Exam twist: solve backwards given the fields, find or Ex 8
J Limiting behaviour tag as full memory Ex 9
Figure — Cache line size and tags

Look at the figure: the same 32-bit ruler is chopped differently in each case. As the index field (blue) grows, the tag (yellow) must shrink — they share a fixed total. The offset (pink) is pinned by alone. Keep this "sliding boundary" picture in mind for every example.


The worked examples

Cell A — Baseline direct-mapped

Cell B — Splitting a concrete address

Cell C — Set-associative

Cells D & E — Degenerate index ()

Cell F — Degenerate offset ()

Cell G — 64-bit address space

Cell H — Real-world word problem

Cell I — Exam twist (solve backwards)

Cell J — Limiting behaviour


Recall

Recall Two roads to

— name them Which fields vanish? ::: Index vanishes () in a fully associative cache (many lines, one set) OR in a single-line cache (one line total). Both remove the "which slot" question.

Recall Why does the reassembly check work?

Tag· + Index· + Offset ::: reconstructs the exact original address, because the three fields are just the high, middle, and low bit-groups of that one integer — no information is added or lost.

Recall The three field widths always sum to what?

::: equals , the address width. If they don't, a field was miscounted.


Connections

  • 5.4.02-Direct-mapped-caches — Cells A, B, E, I, J live here.
  • 5.4.03-Set-associative-caches — Cells C, D (associativity ↔ tag/index trade).
  • 5.4.05-Cache-miss-types — Cell H's compulsory misses.
  • 3.1.04-Spatial-locality — why Cell F () is a bad idea and Cell H works.
  • 5.4.01-Cache-fundamentals — the "why cache at all" foundation.
  • 6.2.01-Virtual-memory-pages — same tag/index/offset split, applied to pages.