COA Notes
Contemporary CPU design techniques including out-of-order execution, branch prediction, and multi-core.
Introduction
A modern CPU is perhaps the most complex object ever created by humans — billions of transistors working together to execute billions of operations per second. But the core ideas that make it fast are understandable: do multiple things at once (superscalar), do them in any order that data allows (out-of-order execution), guess what comes next (branch prediction), and keep data close (caches). This page ties together all these techniques to show how a modern processor like Intel Core or AMD Ryzen actually achieves its performance.
The Performance Challenge
A single instruction takes multiple clock cycles if executed sequentially. But users want performance — how do we get more work done per second?
| 1. Increase clock rate | limited by power (P ∝ f³) |
| 2. Reduce CPI | pipelining, superscalar, out-of-order |
| 3. Reduce instruction count | better ISA, compiler optimization |
Modern CPUs focus on reducing effective CPI below 1.0 (executing multiple instructions per cycle).
Superscalar Execution
A superscalar processor issues multiple instructions per clock cycle:
| Single-issue (scalar): 1 instruction per cycle | CPI = 1 |
| 2-wide superscalar: 2 instructions per cycle | CPI = 0.5 (ideal) |
| 4-wide: 4 per cycle | CPI = 0.25 (ideal) |
| 6-wide (Intel Golden Cove): 6 per cycle | CPI = 0.167 (ideal) |
Real CPI is higher than ideal due to dependencies, misses, and stalls. Modern desktop CPUs achieve IPC (instructions per cycle) of 4-6 on favorable code.
Execution Units
A modern core has multiple parallel execution units:
| │ Port 0 | Integer ALU, FP Multiply, Vector, Branch │ |
| │ Port 1 | Integer ALU, FP Add, Vector, LEA │ |
| │ Port 2 | Load AGU (Address Generation) │ |
| │ Port 3 | Load AGU │ |
| │ Port 4 | Store Data │ |
| │ Port 5 | Integer ALU, Vector Shuffle, Branch │ |
| │ Port 6 | Integer ALU, LEA │ |
| │ Port 7 | Store AGU │ |
| │ Port 8 | Store AGU │ |
| │ Port 9 | Store Data │ |
| │ Port 11 | Load AGU │ |
| │ Potential | 6 ALU + 3 Load + 2 Store per cycle! │ |
Out-of-Order Execution
Why In-Order Is Slow
| I1 | LOAD R1, [addr] ← Cache miss! Stalls 200 cycles |
| I2 | ADD R2, R1, R3 ← Depends on I1, must wait |
| I3 | MUL R4, R5, R6 ← INDEPENDENT! But in-order waits for I1 |
| I4 | ADD R7, R4, R8 ← Also waits... |
In-order: Everything stalls behind the cache miss. Wasted cycles.
How Out-of-Order Works
| Step 1 | Fetch and Decode (in order) |
| Step 2 | Rename registers (eliminate false dependencies) |
| Step 3 | Issue to execution units (when operands ready — any order!) |
| Step 4 | Execute (out of order) |
| Step 5 | Retire/Commit (back in program order for correctness) |
The key insight: Instructions with ready operands execute immediately, regardless of program order. Instructions waiting for data sit in the scheduler until their inputs arrive.
Register Renaming
Architectural registers (16 in x86-64) are mapped to many physical registers (200+):
WAW hazard eliminated — both writes go to different physical registers. The second instruction can execute without waiting for the first.
Reorder Buffer (ROB)
The ROB maintains program order for retirement:
| ROB Entry | [Instruction | Destination | Value | Done?] |
| Entry 1 | ADD R1, R2, R3 P47 42 ✓ Done |
| Entry 2 | LOAD R4, [addr] P48 ??? ✗ Waiting (cache miss) |
| Entry 3 | MUL R5, R6, R7 P49 120 ✓ Done |
| Entry 4 | SUB R8, R4, R9 P50 ??? ✗ Waiting for LOAD |
| Retirement | Only Entry 1 can retire (commit). Entry 3 finished but |
This ensures that exceptions and interrupts see a consistent architectural state.
Branch Prediction
Why Prediction Matters
In a 20-stage pipeline, a branch misprediction wastes ~15-20 cycles (flushing all wrong-path instructions). With 15-20% of instructions being branches:
Prediction accuracy is CRITICAL for deep pipelines.
Modern Prediction Techniques
- Branch Target Buffer (BTB): Caches target addresses of recent branches
- Return Address Stack: Predicts function return addresses (near 100% accurate)
- TAGE Predictor: Uses multiple history tables with different history lengths — can learn complex patterns
- Loop Detector: Identifies counted loops and predicts exact iteration count
- Indirect Branch Predictor: For virtual function calls (polymorphism in C++)
Modern predictors achieve 97-99% accuracy on typical code.
Memory Hierarchy Design
Prefetching
Modern CPUs do not just wait for cache misses — they predict future accesses and fetch data proactively:
- Hardware stride prefetcher: Detects sequential/strided access patterns and fetches ahead
- Next-line prefetcher: Always fetches the next cache line (works for sequential code)
- Spatial prefetcher: Detects related accesses across pages
- Software prefetch instructions: Programmer/compiler hints (PREFETCH instruction)
Store Buffer
Stores do not immediately write to cache (would stall the pipeline):
Multi-Core Design
Why Multi-Core?
Power wall: P ∝ V² × f, and voltage must increase with frequency. Doubling frequency more than doubles power. Instead, use two cores at half frequency: same performance, less power.
Cache Coherence (MESI Protocol)
When multiple cores share data, caches must stay synchronized:
| States | Modified, Exclusive, Shared, Invalid |
| Core 1 reads X: Core 1 cache | Exclusive (only copy) |
| Core 2 reads X: Both caches | Shared |
| Core 1 writes X: Core 1 | Modified, Core 2 → Invalid (invalidate message sent) |
| Core 2 reads X: Core 1 writes back | both Shared |
Putting It All Together
A modern instruction flows through:
- Branch Predictor → predicts direction, provides fetch address
- Instruction Cache → fetches 32+ bytes (multiple instructions)
- Decoder → translates to micro-ops (4-6 per cycle)
- Micro-op Cache → bypasses decoder for hot code
- Rename/Allocate → maps to physical registers, allocates ROB entry
- Scheduler → waits for operands, issues to execution units
- Execute → ALU/Load/Store/Branch operations
- Retire → commits results in program order
All happening simultaneously for hundreds of in-flight instructions.
Key Takeaways
- Modern CPUs achieve IPC > 4 through superscalar execution with many parallel units
- Out-of-order execution hides memory latency by executing independent instructions while waiting for cache misses
- Register renaming eliminates false dependencies (WAR/WAW), exposing more parallelism
- Branch prediction with 97%+ accuracy is essential — without it, deep pipelines would stall constantly
- Multi-core design solves the power wall — parallel cores at lower frequency give better performance per watt
- The combination of these techniques means a modern core effectively executes 4-6 instructions per cycle despite having a 20+ stage pipeline
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Modern CPU Design.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, advanced, architecture, modern, cpu
Related Computer Organization & Architecture Topics