Superscalar execution
What Makes a Processor Superscalar?
The Width Parameter
The issue width N determines how many instructions can be dispatched per cycle. Common values:
- 2-way superscalar: 2 instructions/cycle (older Intel Pentium)
- 4-way superscalar: 4 instructions/cycle (Intel Core)
- 6-8 way superscalar: Modern high-performance cores (Intel Skylake, AMD Zen)
How Superscalar Execution Works: The Pipeline Stages
1. Instruction Fetch (Width N)
What happens: Fetch N instructions from the cache in one cycle.
Why it's hard: The instruction stream isn't always aligned nicely. If you need to fetch 4 instructions but they span a cache-line boundary, you might need two cache accesses.
How it's solved:
- Wide instruction cache ports
- Branch predictors that predict multiple branches ahead
- Instruction bufers to queue fetched instructions
2. Decode (Width N)
What happens: Decode N instructions simultaneously into micro-ops.
Why it's hard: x86 instructions have variable length (1-15 bytes). Finding instruction boundaries for multiple instructions in parallel is complex.
How it's solved:
- Pre-decode bits added to cache lines
- Complex decoders for the first few positions
- Simpler decoders for remaining positions
- Micro-op cache (decoded instruction cache) in modern designs
3. Rename and Dispatch
What happens: Rename architectural registers to physical registers to eliminate false dependencies, then dispatch to reservation stations.
The problem this solves:
ADD R1, R2, R3 ; R1 = R2 + R3
MUL R4, R1, R5 ; R4 = R1 * R5 (needs R1, has RAW dependency)
ADD R1, R6, R7 ; R1 = R6 + R7 (WAW hazard with first instruction)
SUB R8, R1, R9 ; R8 = R1 - R9 (which R1? WAR hazard)
Rename solution:
ADD P10, P2, P3 ; Rename R1 → P10
MUL P11, P10, P5 ; Uses P10, can execute when P10 ready
ADD P12, P6, P7 ; Rename R1 → P12 (different physical register!)
SUB P13, P12, P9 ; Uses P12, no confusion
Now instructions1 and 3 don't have a false dependency—they write to different physical registers.
4. Issue (Out-of-Order)
What happens: Instructions wait in reservation stations until their operands are ready, then issue to execution units.
Key insight: Instructions don't issue in program order. They issue when:
- Functional unit available
- All source operands ready
- No structural hazards
This is out-of-order execution.
5. Execute (Multiple Units)
What happens: Multiple functional units execute instructions in parallel.
A typical superscalar might have:
- 4 integer ALUs
- 2 load/store units (AGU + data port)
- 2 floating-point units
- 1 branch unit
Throughput vs Latency:
- Integer ADD: 1 cycle latency, 4/cycle throughput (4 units)
- Integer MUL: 3 cycle latency, 1/cycle throughput (1 unit)
- FP DIV: 20 cycle latency, 1/20 cycle throughput (1 unit, not pipelined)
6. Retire (In-Order, Width N)
What happens: The reorder buffer (ROB) ensures instructions commit their results in program order, maintaining precise exceptions.
Why in-order retirement: If an exception occurs, all instructions before the faulting instruction must complete, and all after must not have visible effects.
Derivation: Maximum IPC
Let's derive the theoretical maximum instructions per cycle (IPC).
Given:
- Issue width:
- Number of functional units: of type
- Instruction mix: fraction requires unit type
- Average instruction latency:
Step 1: Maximum fetch/decode rate = instructions/cycle
Step 2: Maximum issue rate limited by dependencies. With perfect register renaming and infinite ROB, limited by:
Step 3: Functional unit throughput: For unit type with units:
Step 4: Overall throughput considering instruction mix: If fraction of instructions need unit type :
Why this step?: If50% of instructions are loads/stores () and you have 2 load/store units (), then memory operations limit you to IPC maximum.
Step 5: Dependency limit. If average dependency chain length is and latency is :
Final formula:
Critical Structures for Superscalar
Reorder Buffer (ROB)
What: Circular buffer tracking in-flight instructions in program order.
Why: Enables out-of-order execution with in-order retirement (precise exceptions).
How: Each ROB entry contains:
- PC of instruction
- Destination register (logical)
- Result value or pointer to physical register
- Status (pending/complete)
- Exception flags
Size matters:
Larger ROB → more instructions to search for independent work → higher IPC, but more complex hardware.
Register Alias Table (RAT)
What: Maps architectural registers to physical registers.
Size: For architectural registers and physical registers:
- RAT entries: (one per architectural register)
- Each entry: bits
Why: Eliminates WAW and WAR hazards, enabling more paralelism.
Example: x86-64 has 16 integer registers. A modern design might have 180 physical registers.
Reservation Stations
What: Buffers holding instructions waiting for operands.
Why: Decouple instruction issue from execution, allowing instructions to wait without blocking dispatch.
Key property: Instructions wake up when their last operand becomes ready (associative search).
Limitations and Tradeoffs
Recall Explain Superscalar to a 12-Year-Old
Imagine you're doing homework. You have multiple problems to solve: math problems, reading comprehension, and drawing a picture.
Normal computer (scalar): You have one desk. You do one problem at a time. Math problem → reading → drawing → next math problem. You have to finish each before starting the next.
Pipelined computer: You still do one at a time, but as soon as you finish reading the math problem, you can read the next one while solving the first. Like an assembly line.
Superscalar computer: Now you have THREE desks and three copies of you! One can do math, one can read, and one can draw—all at the same time! But there's a catch: if the drawing requires the answer from the math problem, you have to wait. Also, you only have one pencil sharpener, so if all three of you need to sharpen pencils, two have to wait.
That's superscalar: doing multiple things at once, but only when they don't depend on each other and you have enough tools for everyone.
Connections
- Instruction-Level Parallelism: Superscalar is the primary technique for exploiting ILP
- Register Renaming: Essential for eliminating false dependencies
- Out-of-Order Execution: Superscalar processors typically execute OoO
- Branch Prediction: Critical for keeping the pipeline fed with instructions
- Tomasulo's Algorithm: Classic dynamic scheduling algorithm for superscalar
- Reorder Buffer: Maintains precise exceptions in out-of-order superscalar
- VLIW Architecture: Alternative approach where compiler does instruction scheduling
- Cache Hierarchy: Must provide sufficient bandwidth for multiple memory ops/cycle
- Power-Performance Tradeoffs: Wider superscalar means more power consumption
#flashcards/hardware
What is a superscalar processor? :: A processor that can fetch, decode, and execute multiple instructions simultaneously in the same clock cycle using multiple functional units and dynamic scheduling.
What are the three types of data dependencies?
How does register renaming eliminate false dependencies?
What is the purpose of the Reorder Buffer (ROB)?
Why is in-order retirement necessary in superscalar processors?
What limits the IPC of a superscalar processor?
What is the issue width of a superscalar processor?
How do reservation stations enable out-of-order execution? :: They buffer instructions waiting for operands and issue them to functional units as soon as operands become ready and units are available, decoupling dispatch from execution.
What is the difference between throughput and latency for functional units?
Why don't N-way superscalar processors achieve N× speedup?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Superscalar execution ka matlab hai ki processor ek sath multiple instructions ko handle kar sakta hai—same clock cycle mein! Socho jaise highway pek lane ke bajaye 4 lanes hain, toh 4 gadiyan sath mein chal sakti hain. Normal processor (scalar) ek hi instruction process karta hai per cycle, lekin superscalar 4-way processor 4 instructions ko simultaneously fetch, decode, aur execute kar sakta hai. Iska result? Theoretically 4× zyada throughput!
Lekin practical mein itna simple nahi hai. Hardware ko register renaming karni padti hai taki false dependencies (WAW, WAR) hat jayein. Phir out-of-order execution hoti hai—instructions ready hone pe execute ho jati hain, program order mein nahi. Multiple ALUs, FPUs, aur load/store units parallel mein kaam karte hain. Lekin end mein Reorder Buffer (ROB) ensure karta hai ki results program order mein hi commit hon, taki exceptions precise rahein.
Ek badi challenge: real code mein dependencies bohot hoti hain (RAW hazards), branches interrupt karte hain, aur memory bottlenecks aa jate hain. Isliye 4-way superscalar typically sirf 2-3 IPC (instructions per cycle) achieve karta hai real applications pe, 4 nahi. Industry mein balance banana padta hai—kitne functional units, kitna bada ROB, kitna power consumption. Modern Intel aur AMD processors 4 se 8-way superscalar hote hain with hundreds of physical registers for renaming, enabling high performance without crazy high clock speeds.
Samajhne ki key baat: superscalar hardware complexity badha kar instruction-level parallelism (ILP) exploit karta hai jo code mein naturally available hai, lekin actual speedup code ki inherent paralelism pe depend karta hai, sirf hardware width pe nahi.