wire / wire-format / cache-structure
A CPU cache is organized into sets, each containing ways (lines). Address decomposition: tag (high bits) | set index (middle bits) | block offset (low bits). On access: compute set index, check all ways in that set for a tag match. Hit: return data. Miss: fetch from next level. Replacement policies: LRU, pseudo-LRU, random, FIFO. Write policies: write-through (write to cache and memory) or write-back (write to cache only, dirty bit marks modified lines).
aka: CPU cache structure (set-associative)
spec: CPU cache design
A CPU cache is organized into sets, each containing ways (lines). Address decomposition: tag (high bits) | set index (middle bits) | block offset (low bits). On access: compute set index, check all ways in that set for a tag match. Hit: return data. Miss: fetch from next level. Replacement policies: LRU, pseudo-LRU, random, FIFO. Write policies: write-through (write to cache and memory) or write-back (write to cache only, dirty bit marks modified lines).
| field | size | meaning |
|---|---|---|
| Block offset | log2(line size) bits | Low bits: offset within the cache line. E.g., 6 bits for 64-byte lines. |
| Set index | log2(num sets) bits | Middle bits: which set. E.g., 6 bits for 64 sets. |
| Tag | remaining bits | High bits: identifies which memory block is in this line. |
| Cache line | line size (32/64/128 bytes) | The unit of transfer between cache levels and memory. |
| Associativity | ways per set | 1 = direct-mapped, 2/4/8 = set-associative, N = fully associative. |
| MESI protocol | 4 states | Modified (dirty, exclusive), Exclusive (clean, exclusive), Shared (clean, may be in other caches), Invalid (not valid). Used for cache coherence in multi-core systems. |
| Write-back | policy | Write to cache only; mark line dirty. Write to memory only on eviction. Faster but requires dirty bit. |
| Write-through | policy | Write to cache and memory simultaneously. Simpler but slower. |
| Inclusive vs exclusive | policy | Inclusive: L2 contains all L1 data. Exclusive: L2 and L1 are disjoint (more total capacity). |
example:
00 00 00 00
Cache structure (placeholder)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/cache-structure
or /wire-format/cache-structure.json