4.1.9 · D1Computer Architecture (Deep)

Foundations — Cache organization — direct-mapped, n-way set associative, fully associative

2,166 words10 min readBack to topic

Before you can read the parent note, you must own eleven small ideas. We build them one at a time — each one earns the next. Nothing is assumed.


1. A "bit" and why we count in powers of two

Why does hardware love powers of two? Because with switches side by side you can make exactly different patterns — and every pattern is used, none wasted.

Figure — Cache organization — direct-mapped, n-way set associative, fully associative

This is the single arithmetic move the whole topic runs on:


2. The symbol — the tool that "un-doubles"

Why do we need a new symbol instead of ordinary multiplication? Because doubling and un-doubling are the exact question the address split asks: "I have boxes — how many switches address them?" Multiplication gives you the count forward (); runs it backward.


3. A memory address and its width

If , there are distinct addresses, i.e. bytes of addressable memory. The parent note's " bytes" is literally "" spoken out loud.


4. A block (line) and its size

Memory is not copied one byte at a time — that would waste the trip. It moves in fixed chunks.

Why chunks? Because programs tend to use neighbours soon after each other (this is spatial locality) — grabbing the whole neighbourhood at once pays off.

Figure — Cache organization — direct-mapped, n-way set associative, fully associative

5. Block number vs. block offset — splitting the address once

Take any byte address and ask the two questions above.


6. The floor and mod — two symbols we just used

Why these two? Because "which block" and "which byte inside" are exactly integer division and remainder.


7. The cache's shape: sets , ways , total blocks

Figure — Cache organization — direct-mapped, n-way set associative, fully associative

8. Tag , index , offset — the three field widths

Now we name the widths (bit counts) of the three fields. Each is a small .


9. The valid bit — "is this slot even filled?"

When the machine powers on, every slot holds garbage. We need one switch per slot to say "ignore me until I've been loaded."

Without it, a random leftover tag could accidentally "match" and hand you wrong data. It is the AND-guard on every lookup.


10. Hit, miss, and the comparator

This is why fully associative () is expensive: comparators screaming on every access. It leads straight into average access time reasoning and the 3 C's miss model you'll meet later.


11. The mod placement rule — where a block is allowed to live

Putting it together: a block with number is sent to set

Once , two blocks sharing a set can both stay — but then you must choose whom to evict on a later miss, which is the job of replacement policies. Direct-mapped () never chooses: one legal slot, no policy needed.


How the pieces feed the topic

bit and powers of two

log base 2 counting

address width m

block and size B

block number and offset

floor and mod

sets S ways E total N

field widths t s b

tag index offset split

valid bit and comparator

hit or miss lookup

placement k mod S

Cache organization the topic


Equipment checklist

You are ready for the parent note when you can answer each without peeking.

  • How many distinct patterns do bits make? ::: .
  • What does ask? ::: " to what power equals ?" — the number of doublings.
  • What is and why? ::: , because .
  • What does stand for and what is ? ::: address width in bits; = number of addressable bytes.
  • Why is memory moved in blocks of bytes, not single bytes? ::: to exploit spatial locality — neighbours get used soon.
  • Given a byte address, how do you get its block number? ::: (chop off the low bits).
  • What does compute and why is it perfect for choosing a set? ::: the remainder; it always lands in , one bin per set.
  • Define , , and their relationship. ::: sets, ways (blocks per set), total slots; .
  • Give the three field widths. ::: , , , with .
  • Why does fully associative have the largest tag? ::: , so ; the tag must hold the whole block number.
  • What two conditions make a hit? ::: valid bit AND stored tag equals address tag.
  • How many comparators does an -way cache need? ::: exactly .
  • Which set does block map to, and which bits does that use? ::: , using the lowest bits of the block number.