Cache Design for a 2-Set-Associative Cache: Address Interpretation
We will design a set-associative cache given:
- Block size: 4 words, each word is 16 bits (so block size in bits is )
- Set size (associativity): 2 ways
- Total cache capacity: 4096 words (not bytes)
- Main memory: 64K words, each word is 32 bits (so main memory size in bits is )
Key cache terms we’ll use:
block
set
tag
index
Cache Address Breakdown (Tag, Index, Block Offset) — How Set-Associative Caches Split Addresses
1) Convert all sizes into consistent units
Given cache block size
- 4 words/block
- 16 bits/word
So block size in bits:
Cache total words
- 4096 words total
- each word = 16 bits
So cache total capacity in bits:
Main memory
- 64K 32-bit words
So memory words: and memory is:
2) Determine number of sets (and number of lines)
For a set-associative cache:
way
Each set has 2 ways, so each set contains:
- 2 lines
- each line holds 1 block
Let:
- = number of sets
- = block size in words = 4 words
- total cache words = 4096
Total words in cache: 4096 = (\text{#sets}) \times (\text{ways per set}) \times (\text{words per block}) So:
Answer:
- Number of sets
- Total number of cache lines (ways) =
Also, total cache “lines” check:
- each line holds 4 words
- 1024 lines 4 words/line = 4096 words ✅
Design-to-Address Interpretation Roadmap
Fix units
Step AConvert word sizes and block size into bits/words."
Compute sets
Step BUse total cache words = sets × ways × words/block."
Compute address fields
Step CSplit main-memory addresses into tag, set index, block offset."
Lay out structures
Step DTag store per line, valid bits, data store per line."
3) Cache structure (what each set/line contains)
We will describe the structure at the level needed to “design the cache structure and show address interpretation.”
Each cache line (one way within a set) stores:
- Data block: 4 words (each 16-bit) 64-bit data per line
- Tag bits: identify which main-memory block is cached
- Valid bit (and typically optionally Dirty/Replacement metadata)
Keywords:
tag store
valid bit
replacement policy
Minimal required arrays
- Data array:
Data[sets][ways][blockWords] - Tag array:
Tag[sets][ways] - Valid array:
Valid[sets][ways]
A compact diagram of the organization:
Mapping rule on lookup
- Use processor address to compute:
- block offset (within the 4-word block)
- set index (select set)
- tag (compare with both ways in that set)
- If either way’s valid&tag match => hit; return the word indicated by block offset.
Compute address field widths (block offset, set index, tag)
- 1Step 1
Main memory is 64K 32-bit words, so there are 65536 distinct word addresses. Processor/CPU addresses are assumed to be word addresses; thus total word-address bits = log2(65536)=16.
- 2Step 2
Block has 4 words → need log2(4)=2 bits to select which word within the block.
- 3Step 3
Number of sets is 512 → need log2(512)=9 bits for set index.
- 4Step 4
Tag bits = total address bits − (set index bits + block offset bits) = 16 − (9 + 2) = 5 bits.
- 5Step 5
Processor word address splits as: [tag:5][set index:9][block offset:2].
4) Address interpretation for processor lookups
From the step-by-step:
- Main memory word address bits:
- Block offset bits:
- Set index bits:
- Tag bits:
So the processor’s word address is interpreted as:
Keywords:
block offset
set index
word address
Important consistency check
If you instead interpret addresses as byte addresses, block offset and total address bits change. Here the problem states main memory is given as 64K 32-bit words, so using word addresses yields clean integer splits.
Word-size mismatch (16-bit cache words vs 32-bit memory words)
Cache stores 16-bit words but main memory is 32-bit words. A common assumption is that the cache fetches the needed 16-bit granularity from the 32-bit memory word (e.g., two cache words per memory word). If your course assumes a different transfer granularity, recompute offsets accordingly.
5) Derive the formulas used in hardware/software
Let:
- = processor word address
- Define:
- = block offset bits = 2
- = set index bits = 9
- = tag bits = 5
Then:
- Block offset (word within the block):
- Set index:
- Tag:
Look-up procedure
- Access set:
set = index - Compare both ways’ tags with
tag - If match and valid: return
Data[set][way][offset]
6) Example address breakdown (illustrative)
Let an example processor word address be:
Compute:
- offset =
- index =
- tag =
This yields an address split consistent with:
- 2-bit offset (0..3)
- 9-bit index (0..511)
- 5-bit tag (0..31)
(You can plug any you’re given in homework; the formulas above are the core.)
Cache Geometry Summary
Key structural counts and address field sizes
Common variations and how to adapt
Cache Address Interpretation Quick Checks
Knowledge Check
Given block size = 4 words and set size = 2 ways, total cache capacity = 4096 words, the number of sets is: