CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture
Lecture 12 - Out-of-Order Execution I
Chris Fletcher
UC Berkeley, Spring 2026
Complex Pipelining: Motivation
- Pipelining gets complex when we want performance with:
- Long-latency or partially pipelined FPUs (unpipelined FDiv, multi-cycle FAdd/FMul)
- Variable memory access time (hits vs. misses)
- Multiple arithmetic and memory units in parallel
| Event | Meaning |
| Dispatch | Leave decode, enter the instruction pool |
| Issue | Leave the pool for a functional unit |
| Complete | Finish execution, produce result/exception flags at writeback |
| Commit | Update permanent architectural state (separated from completion later) |
Issues in Complex Pipeline Control
- ALU, Mem, FAdd, FMul, FDiv behind an issue stage with GPRs and FPRs:
- Structural hazards on iterative units (second divide while FDiv busy)
- Structural hazards on writeback (different latencies finish together)
- WAR and WAW hazards
- Exceptions (fast op finishes after an older slow op traps)
- In-order fix: pad all units to equal latency (X1–X3) + commit point before W
- Removes WB conflicts, WAR/WAW, imprecise exceptions
- But bypassing gets very expensive with many padded units
- Without padding, check before issue: unit free? inputs ready (RAW)? safe to write (WAR/WAW)? WB conflict?
Data Hazards: Register vs. Memory
| Hazard | Example | Kind |
| RAW | $r_3 \leftarrow r_1\,op\,r_2$; $r_5 \leftarrow r_3\,op\,r_4$ | True dependence |
| WAR | $r_3 \leftarrow r_1\,op\,r_2$; $r_1 \leftarrow r_4\,op\,r_5$ | Name (anti) dependence |
| WAW | $r_3 \leftarrow r_1\,op\,r_2$; $r_3 \leftarrow r_6\,op\,r_7$ | Name (output) dependence |
- Register hazards: found at decode by comparing register numbers
- Memory hazards (
M[r1+disp1] ← r2; r3 ← M[r4+disp2]): only after computing addresses
- Is $r_1 + \text{disp}_1 = r_4 + \text{disp}_2$? (Lecture 13)
Data Hazards: An Example
| Instruction | Latency |
| I1 | FDIV.D f6, f6, f4 | 4 |
| I2 | FLD f2, 45(x3) | 1 |
| I3 | FMUL.D f0, f2, f4 | 3 |
| I4 | FDIV.D f8, f6, f2 | 4 |
| I5 | FSUB.D f10, f0, f6 | 1 |
| I6 | FADD.D f6, f8, f2 | 1 |
- RAW: 1→4, 1→5 (f6); 2→3, 2→4, 2→6 (f2); 3→5 (f0); 4→6 (f8)
- WAR: 4→6, 5→6 (f6)
- WAW: 1→6 (f6)
- Valid orders: in order; I2, I1, I3…; I1, I2, I3, I5, I4, I6
In-Order Issue: In- vs. Out-of-Order Completion
k = Ik issues, k = Ik completes
In-order completion: 15 cycles
| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 1 | 2 | · | · | 1 | 2 | 3 | 4 | · | 3 | 5 | 4 | 6 | 5 | 6 |
Out-of-order completion: 12 cycles
| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 1 | 2 | 2 | 3 | 1 | 4 | 3 | 5 | 5 | 4 | 6 | 6 |
- I2 completes right away; I5 finishes ahead of I4
In-Order Issue Limitations
| Instruction | Latency | Depends on |
| 1 | FLD f2, 34(x2) | 1 | |
| 2 | FLD f4, 45(x3) | long | |
| 3 | FMULT.D f6, f4, f2 | 3 | 1, 2 |
| 4 | FSUB.D f8, f2, f2 | 1 | 1 |
| 5 | FDIV.D f4, f2, f8 | 4 | 1, 4; WAR on 3 (f4) |
| 6 | FADD.D f10, f6, f4 | 1 | 3, 5 |
In-order issue (20 cycles): 1 2,1 · · · · · · 2 3 4 4 3 5 · · · 5 6 6
- Instruction 4 has
f2 by cycle 3 but can't issue: 3 is stuck behind the long load
Check Your Understanding
1. Name the three data hazards. Which is a true dependence?
RAW (true), WAR (anti), WAW (output). Only RAW is true; WAR and WAW are name dependences.
2. In the long-load trace, why did instruction 4 sit idle for 8 cycles though
f2 was ready early?
Instruction 3 was stalled on the long load, and in-order issue forbids issuing 4 before 3.
Out-of-Order Issue
- Instruction pool between dispatch and issue
- Dispatch: add the next instruction in order if there's space and no WAR/WAW hazard
- WAR is possible again: a younger op could issue and overwrite a register an older waiting op hasn't read
- Issue: any pool instruction whose RAW hazards are satisfied (≤1 per cycle for now)
- Writeback enables waiting instructions
Long-load example, OoO issue without renaming:
| c | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 18 | 19 | 20 |
| 1 | 2,1 | 4 | 4 | · | · | · | · | 2 | 3 | 3 | 5 | 5 | 6 | 6 |
5 can't go: WAR on f4 with stalled 3. Still 20 cycles.
This Is a Typical Problem in Loops
while (...) {
A[i] += x;
}
L1: FLD f4, 0(x3)
ADDD f6, f4, f2
FST 0(x3), f6
ADD x3, x3, 8
j L1
- Every iteration reuses
f4 and f6
- If the first
FLD misses, iteration 2's FLD into f4 is blocked by WAR/WAW
- The number of ISA registers limits how many instructions can be in flight
- OoO issue alone gives no significant speedup
Register Renaming
- Small ISA register sets can't keep FP pipelines full (IBM 360: 4 FP registers)
- Tomasulo (IBM, 1967): rename on the fly
- Give each new write a fresh storage location → WAR and WAW disappear
3: FMULT.D f6, f4, f2
5: FDIV.D f4', f2, f8 # f4 renamed
6: FADD.D f10, f6, f4'
| c | 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 |
| 1 | 2,1 | 4 | 4 | 5 | 2 | 3,5 | 3 | 6 | 6 |
The divide overlaps the long load: 20 → ~13 cycles
Renaming in the Pipeline
- Decode renames registers and adds instructions to the reorder buffer (ROB), the instruction pool
- Every write gets a unique destination: WAR and WAW become impossible
- Any ROB entry whose RAW hazards are satisfied can issue: true dataflow execution
Check Your Understanding
1. Why did naive OoO issue not speed up the long-load sequence?
Instruction 5 had a WAR hazard on f4 with stalled instruction 3, blocking 5 and 6.
2. Which hazards does renaming eliminate, and which remain?
WAR and WAW are eliminated; RAW (true dependences) remains.
Renaming Structures (Data-in-ROB)
Rename table & regfile
| reg | p | data / tag |
| f1 | 1 | value |
| f2 | 0 | t₃ |
| … | | |
p = 1: value valid
p = 0: tag of the producing ROB slot
Reorder buffer (FIFO, tags t₁…tₙ, head = oldest)
| i | op | p1 | src1 | p2 | src2 | pd | reg | result | exc? |
| | | | | | | | | |
| | | | | | | | | |
src = value if p = 1, producer tag if p = 0
Instruction Lifecycle (Data-in-ROB)
- Dispatch (in order): allocate the tail slot (its tag); read sources (value, or result from the producer's ROB slot, or its tag with p = 0); set the destination's rename entry to
<0, tail>
- Issue (out of order): entry with i = 0, p1 = p2 = 1, free unit → i = 1, send to the unit
- Complete (out of order): broadcast
<t, result>; write result and exc into slot t; associatively search every source field for t and fill in values (expensive CAM)
- Commit (in order, at head): wait for pd = 1; if no exception, write the regfile (set p = 1 only if the rename tag still points here); dequeue
A tag can be reused only when its instruction commits.
Separating Completion from Commit
- Tomasulo's IBM 360/91: completion = commit
- WAW risk if not carefully gated
- Imprecise traps: I4 overwrites
f8 before older I1 faults
- ROB holds completed values (out-of-order completion), updates state in program order (in-order commit)
- Dependents can bypass completed values from the ROB before commit
- Trap at commit: kill younger instructions in ROB/decode/fetch, reset rename table (all p = 1), inject handler PC: precise
- Partial squash (branch mispredict): repair the rename table by
- Unwinding from the ROB tail back to the branch, or
- Snapshots per branch, restored in one cycle
Historical Perspective: IBM 360/91 FPU
- Tomasulo, 1967: distributed reservation stations
- 3 adder entries, 2 multiplier entries, 6 load buffers, 3 store buffers
- Common data bus broadcasts
<tag, result> to all waiting entries
- Out-of-order then faded until the 1990s:
- Missing precise traps (no ROB)
- Missing branch prediction: control hazards starved the window
- Simple in-order chips in new technology beat multi-board OoO in old technology
- Single-chip CPUs + caches gave ~1%/week scaling before OoO was needed again
Check Your Understanding
1. In Data-in-ROB, when are source tags replaced by values, and when can a ROB tag be reused?
Tags are replaced when a unit produces data (associative broadcast). A tag is reused only when its instruction commits at the head.
2. Why does separating completion from commit fix imprecise traps?
Results and exception flags wait in the ROB; state changes only in program order, so younger instructions can be killed before touching state when an older one traps.