CPU Microarchitecture and Memory System: Ten-Topic Review
System DesignModel answerLast updated
Explain ten core architecture topics: OoO pipelines, gshare, register renaming, VLIW, coherence, load/store logic, COW, cache math, VIPT aliasing, and async FIFOs.
Imagine a technical screen for a CPU design or verification role. Explain each of the following topics clearly. Use a small worked example wherever it helps. You do not need a specific ISA.
- Out-of-order core. Name the main structures (reorder buffer, issue queue or reservation stations, load/store queue) and trace an instruction from fetch to retirement.
- gshare predictor. Explain how the table is indexed, what the global history register does, and how the 2-bit counters and history are updated after a branch resolves.
- Register renaming. Given a short sequence of instructions on architectural registers, show how the rename table (RAT) changes and give the final mapping. Assume every destination gets a fresh physical register.
- VLIW. Define it and contrast it with a superscalar out-of-order design, especially the split of complexity between compiler and hardware.
- Cache coherence. State the problem being solved and compare MSI, MESI and MOESI at a high level.
- Load/store subsystem. Describe the store buffer and the load/store queue, explain what "speculative" means for memory operations, and say when cache tags use virtual versus physical addresses.
- Copy-on-write after
fork(). Explain how parent and child can share frames, how a write is detected, which fault occurs, and what the handler does. - Cache index math. From capacity, block size and associativity, derive the number of sets, index bits, offset bits and tag bits for a 32-bit address.
- VIPT caches. Explain why aliasing can occur and how designs avoid it.
- Asynchronous FIFO. Say what problem it solves and outline the Gray-code pointer technique and why it is needed.
Hints
Hint 1
For each topic, lead with the invariant that makes it work (retire in order, SWMR, only one Gray-code bit changes) before naming structures.
Hint 2
For the numeric parts (RAT trace, cache math), read sources before writing the destination mapping, and check that tag + index + offset bits add up to the address width.
Hint 3
For VIPT, compare the number of index plus offset bits against the page-offset bits. For the async FIFO, ask what goes wrong when a multi-bit pointer is sampled by a clock that is not its own.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Lead with a short mental model for each topic, then give one mechanism or example. Interviewers listen for precise invariants more than for vocabulary.
1) Out-of-order core
- Front end: fetch and decode in program order, steered by the branch predictor.
- Rename: the RAT maps architectural to physical registers and a free list supplies new ones. This removes WAR and WAW hazards, leaving only true RAW dependences.
- Dispatch: each instruction gets a ROB entry (program order), an issue-queue entry (waits for operands) and, if it touches memory, a load or store queue entry.
- Issue/execute: wakeup and select logic picks ready instructions regardless of order. Results are broadcast on the bypass network to wake consumers.
- Retire: in order from the ROB head. Retirement commits architectural state, frees the previous physical register of the destination, and lets stores drain toward the cache.
- Recovery: on a mispredict or exception, flush everything younger and restore the RAT from a checkpoint or by walking the ROB.
2) gshare
- Index = low PC bits XOR the global history register (GHR), an n-bit shift register of recent outcomes. The XOR spreads branches that share history across the table and captures correlation.
- Each pattern-history-table entry is a 2-bit saturating counter: 00 strong NT, 01 weak NT, 10 weak T, 11 strong T. Predict taken if the top bit is 1.
- Update: increment on taken and decrement on not-taken, both saturating. Then
GHR = ((GHR << 1) | taken) & mask. - Example: PC bits 1011 XOR GHR 0110 gives index 1101. The counter is 01, so the prediction is NT. The branch is actually taken, so the counter becomes 10 and the GHR becomes 1101.
- In real cores the GHR is updated speculatively at prediction time and repaired on a mispredict. Counter hysteresis keeps one odd outcome, such as a loop exit, from flipping a strong prediction.
3) RAT trace
Start with R1→P1, R2→P2, R3→P3, R4→P4 and free registers P10, P11, and so on. Read the sources first and then install the new destination mapping. Save the old mapping so it can be freed at retire.
| Instruction | Sources read | New mapping | Freed at retire |
|---|---|---|---|
| R1 = R2 + R3 | P2, P3 | R1→P10 | P1 |
| R4 = R1 * R2 | P10, P2 | R4→P11 | P4 |
| R1 = R4 − R3 | P11, P3 | R1→P12 | P10 |
| R2 = R1 + R1 | P12, P12 | R2→P13 | P2 |
Final RAT: R1→P12, R2→P13, R3→P3, R4→P11.
4) VLIW vs superscalar OoO
VLIW relies on the compiler to find independent operations and pack them into fixed-slot bundles. The hardware skips dependence checking, renaming and the ROB, so it is smaller and more power-efficient. That is why it appears in DSPs and in Itanium-style EPIC designs.
The costs are NOP padding (code bloat), poor binary compatibility when widths or latencies change, and fragility when latency is unpredictable, because a cache miss stalls a whole bundle. Compilers respond with software pipelining, predication and trace scheduling.
An OoO superscalar discovers parallelism at run time, adapts to actual latencies and runs old binaries unchanged. It pays in CAM-heavy structures, rename logic and power. The trade-off is compile-time versus run-time scheduling.
5) Cache coherence
Private caches can hold stale copies of one line. Coherence guarantees:
- SWMR: at any moment a line has either one writer or many readers.
- Data-value invariant: a read returns the most recent write to that address.
Protocols:
- MSI: Modified, Shared, Invalid.
- MESI: adds Exclusive (clean, sole copy), so a read followed by a write upgrades silently with no bus traffic.
- MOESI: adds Owned (dirty and shared). The owner services requests and memory stays stale, which avoids a writeback on sharing. MESIF instead adds Forward to pick one responder for clean data.
Snooping (broadcast) suits few cores and directories scale. Coherence concerns one address. Consistency concerns ordering across addresses.
6) Load/store subsystem
- Store buffer: holds retired stores until they write the cache, so retirement is not blocked by store misses. It forwards data to younger loads and is the source of store→load reordering under TSO.
- Load/store queue: tracks in-flight memory operations in program order. It disambiguates addresses, forwards store data to loads, detects violations (a load ran before an older same-address store, so replay or flush) and snoops invalidations to respect the memory model.
- Speculative: memory operations may run past unresolved branches or before older store addresses are known. Loads can run early and be squashed, and a memory-dependence predictor (such as store sets) limits violations. Stores calculate address and data early but write the cache only after retiring.
- Virtual vs physical tags: physical tags are the norm (VIPT L1, physical L2/LLC) because they avoid synonyms and homonyms and match coherence traffic. Virtual tags skip the TLB on hits but need ASID handling or flushes, synonym management and reverse translation for snoops. They survive mainly in small instruction caches and older or embedded designs.
7) Copy-on-write after fork
fork()duplicates the page tables, not the data pages.- Writable private pages are marked read-only in both processes and the frame refcount is incremented. The region descriptor (VMA) still says the page is logically writable.
- A write by either process triggers a protection page fault (on x86, #PF with present + write in the error code).
- The handler consults the VMA:
- Truly read-only region: deliver SIGSEGV.
- COW with refcount > 1: allocate a frame, copy 4 KB, map it writable and drop the old refcount.
- COW with refcount = 1: just make the PTE writable.
- Invalidate the stale TLB entry (shootdown on SMP) and restart the store.
8) Cache index math
- Sets = capacity / (block size × associativity)
- Offset bits = log₂(block size)
- Index bits = log₂(sets)
- Tag bits = 32 − index − offset
Example: 32 KB, 64 B blocks, 4-way. Sets = 32768 / 256 = 128, so index = 7 bits, offset = 6 bits and tag = 32 − 7 − 6 = 19 bits. A fully associative cache has 0 index bits and a direct-mapped cache has associativity 1.
9) VIPT aliasing
A VIPT cache indexes with virtual bits in parallel with the TLB lookup, then compares physical tags. If any index bit lies above the page offset, two virtual addresses that map to one physical page (synonyms) can land in different sets, giving duplicate copies and stale data.
Ways to avoid it:
- Size constraint: keep index + offset bits ≤ page-offset bits (12 for 4 KB pages), so cache size per way ≤ page size. The 4-way 32 KB cache above fails (13 bits), while 8-way 32 KB passes (6 + 6 = 12). That is why L1s grow by adding ways.
- Page coloring: the OS aligns synonyms so the overlapping index bits match.
- Hardware alias handling: detect synonyms on a fill and invalidate or merge the duplicate.
- Way prediction or partial tags to keep associativity high at low latency.
10) Asynchronous FIFO
It moves data safely between two unrelated clock domains. Memory is written in the write clock domain and read in the read clock domain. Only the pointers cross domains.
Problem: a binary pointer such as 0111→1000 changes many bits at once. A synchronizer in the other domain may sample some old and some new bits and read a wildly wrong value.
Fix:
- Convert pointers to Gray code, where only one bit changes per increment. A sampled pointer is then either the old or the new value, never garbage.
- Pass each Gray pointer through a two-flop synchronizer.
- Use an extra MSB on each pointer. Empty is checked in the read domain: read pointer == synchronized write pointer. Full is checked in the write domain: the top two bits differ and the rest match.
- Use a power-of-two depth. The stale synchronized pointer makes full and empty conservative, which is safe, at some cost in throughput.
Common mistakes
- Freeing the new physical register at retire instead of the old one.
- Letting stores write the cache before they retire.
- Confusing coherence with consistency.
- Claiming VIPT is always alias-free without checking the size constraint.
- Synchronizing binary pointers across clock domains.