4.1.10 · D1Computer Architecture (Deep)

Foundations — Cache lines, tags, index, offset

1,712 words8 min readBack to topic

Before you can read the parent note Cache lines, tags, index, offset, you must be fluent in a handful of tiny ideas. This page builds each one from nothing — no symbol is used before it is drawn.


0 — What is a "bit" and why memory is counted in powers of two

Picture a row of light switches. Each switch is one bit.

Figure — Cache lines, tags, index, offset

This single fact — " bits name things" — is the engine of the whole topic. Read it backwards and it becomes the tool we actually use: if I need to name different things, how many switches do I need? That backwards question is what the next symbol answers.


1 — The symbol (exponent / power of two)

Recall Fill the table (self-test)

, , , , , , , , .

Why the topic needs it
Line sizes and set counts are always powers of two (, ), because they are counted by whole bit-fields.

2 — The symbol (the "how many bits?" question)

Now the backwards question from Section 0.

Figure — Cache lines, tags, index, offset
Why the topic needs it
Every field width — offset , index — is a .

3 — Binary, hexadecimal, and the symbol 0x

Addresses are long strings of bits. Writing ones and zeros is painful, so we group them.

So 0xF 1111 , and 0x2F 0010 1111.

Figure — Cache lines, tags, index, offset
Why the topic needs it
Addresses like 0xDEADBEEF are hex; you must expand them to bits to slice fields correctly.

4 — What a memory address is (the symbol and )

Picture a very long street where every byte is one house, numbered .

Why the topic needs it
The address is the raw material we chop into tag/index/offset. is the total width we must account for: .

5 — Integer division and the block number

The parent uses without warning. Here is the picture.

Figure — Cache lines, tags, index, offset
Why the topic needs it
The low bits of the block number become the index; the leftover high bits become the tag. See Spatial and temporal locality for why grouping bytes into blocks pays off.

6 — The cache's own quantities: , , ,

Now the four cache dimensions, in build order.

Why the topic needs it
These four numbers, plugged into , produce every field width on the parent page.

7 — Putting the symbols together (the split, symbol-checked)

You now own every piece. The parent's headline formula reads, symbol by symbol:

Read it as three "how many bits?" questions answered by , on an -bit house number from §4.


Prerequisite map

bits = yes or no switches

k switches name two-to-the-k things

exponent two-to-the-k

log base 2 = how many bits

group bits into nibbles = hex 0x

address A is n bits wide

divide by B = drop low bits = block number

offset = log2 B

index = log2 S

tag = leftover bits

ADDRESS SPLIT tag index offset


Equipment checklist

Convert to a plain number
.
Convert to a plain number
(because ).
Why must and be powers of two?
So each field is a whole number of bits ( is an integer only for powers of two).
Expand the hex digit 0xF to bits
1111.
What does the prefix 0x announce?
The number that follows is written in hexadecimal.
What does mean, and how many bytes can it name?
Address width in bits; it names bytes.
What does compute, in words?
The block number — how many whole -byte lines fit below address .
In binary, dividing by is the same as…
Deleting the low bits.
Relate , ,
(sets equal total lines divided by ways).
How many index bits when (fully associative)?
Zero, since .
Offset width formula and what it depends on
; depends only on line size, not total cache size.
Tag width formula
(the leftover bits).