Lecture 12: OoO 1

Section 1: Complex Pipelines, Hazard Taxonomy, and In-Order Limitations

Now we shift our focus inside the processor core. Simple 5-stage pipelines assume every arithmetic operation completes in 1 cycle and memory takes 1 cycle. Pipelining becomes complex when we want high performance in the presence of:

To talk cleanly about these machines, let’s establish four precise pipeline boundaries across the Frontend (instruction fetch/decode) and Backend (execution, "EXE stage"):

Why Simple In-Order Complex Pipelines Struggle

Suppose we attach multiple functional units (ALU, Mem, FAdd, FMul, FDiv) to an Issue stage with general-purpose (GPRs) and floating-point (FPRs) register files. Four hazards immediately appear:

  1. Structural hazards on iterative functional units (e.g., issuing a second divide while the unpipelined FDiv is busy).
  2. Structural hazards on writeback (two instructions of different latencies finishing on the same cycle and fighting for one WB port).
  3. WAR and WAW data hazards (explained below).
  4. Exception handling (a fast instruction finishing after an older slow instruction that later traps).

In an in-order complex pipeline, we can simplify control by padding shorter pipelines to equalize EXE cycle latency (putting X1, X2, X3 stages on everything) and enforcing an in-order Commit Point right before W. That eliminates WB structural hazards, WAR/WAW hazards, and imprecise exceptions. To prevent the padded writeback latency from slowing down single-cycle integer operations, we add massive bypassing networks—but bypassing becomes extremely expensive with multiple padded functional units.

Can we remove the padding and let functional units run at their natural, unequal latencies without massive bypassing? If we do, we must check four conditions before issuing any instruction from a tracking table:

  1. Is the required functional unit available? (Structural)
  2. Is the input data available? (RAW hazard?)
  3. Is it safe to write the destination? (WAR? WAW hazard?)
  4. Is there a structural conflict at the WB stage?

Review: Data Hazard Taxonomy (Register vs. Memory)

Consider executing a sequence of instructions of the form r_k \leftarrow r_i \text{ op } r_j:

  1. Data-dependence — Read-after-Write (RAW) hazard (a true dependence): r_3 \leftarrow r_1 \text{ op } r_2 r_5 \leftarrow r_3 \text{ op } r_4 The second instruction needs the value produced by the first.
  2. Anti-dependence — Write-after-Read (WAR) hazard (a name dependence): r_3 \leftarrow r_1 \text{ op } r_2 r_1 \leftarrow r_4 \text{ op } r_5 The second instruction overwrites r_1; if it writes before the first reads r_1, the first reads the wrong value.
  3. Output-dependence — Write-after-Write (WAW) hazard (a name dependence): r_3 \leftarrow r_1 \text{ op } r_2 r_3 \leftarrow r_6 \text{ op } r_7 Both write r_3; if the second finishes before the first, r_3 ends up with the older value instead of the newer one.

Notice a crucial difference between register and memory operands: data hazards due to register operands can be determined at the decode stage (just by comparing register numbers), but data hazards due to memory operands (M[r1 + disp1] <- r2 followed by r3 <- M[r4 + disp2]) can be determined only after computing the effective address—specifically, checking whether (r_1 + \text{disp}_1) = (r_4 + \text{disp}_2). (We will tackle memory hazards in Lecture 13.)

Worked Example: Dependency Graph and Out-of-Order Completion

Let’s trace all hazards in the following 6-instruction floating-point sequence:

Let’s map every hazard:

From this dependency graph, valid instruction orderings include in-order (I_1, I_2, I_3, I_4, I_5, I_6), or out-of-order schedules such as I_2, I_1, I_3, I_4, I_5, I_6 (swapping independent I_1, I_2) or I_1, I_2, I_3, I_5, I_4, I_6 (moving I_5 ahead of I_4 because I_5 doesn’t depend on I_4).

Now let’s keep in-order issue (instructions issue one per cycle in program order) and compare in-order completion against out-of-order completion cycle-by-cycle (writing k for the cycle I_k issues, and \underline{k} for the cycle I_k completes):

Where In-Order Issue Still Fails

Out-of-order completion helped above, but look what happens with a slightly different sequence when FLD misses in the cache (latency = long, say 7 cycles):

Under in-order issue: 1 2,1_ . . . . . . 2_ 3 4 4_ 3_ 5 . . . 5_ 6 6_ (20 cycles). Notice that on Cycle 3, instruction 4 (FSUB.D f8, f2, f2) already has its operand f2 ready! Yet the in-order issue restriction prevents instruction 4 from being issued simply because instruction 3 ahead of it is stuck waiting on the long load (2). To hide long-latency operations, we must allow independent younger instructions to issue out of order.

[Editor Note: removed title slide, previous-lecture recap slide, and roadmap slide.]

✎ Check Your Understanding

  1. What are the three types of data hazards, and which one represents a true dependency as opposed to a name dependency? Answer: RAW (Read-after-Write, true data-dependence), WAR (Write-after-Read, anti-dependence), and WAW (Write-after-Write, output-dependence). Only RAW is a true dependency; WAR and WAW are name dependencies.

  2. In the second 6-instruction trace above, why did instruction 4 (FSUB.D f8, f2, f2) sit idle for 8 cycles under in-order issue even though f2 became available on Cycle 2? Answer: Because instruction 3 (FMULT.D) was stalled waiting on the long-latency load (2), and in-order issue forbids issuing instruction 4 before all preceding instructions have issued.


Section 2: Out-of-Order Issue and Why Register Renaming Is Essential

To break the bottleneck of in-order issue, we place an Instruction Pool between Dispatch and Issue:

Let’s apply naive Out-of-Order Issue (without renaming) to our exact 6-instruction example with the long load (2):

Look at that result: Out-of-order execution did not allow any significant improvement! It still took 20 cycles!

And this is not a contrived example—it is typical in loops. Consider:

while (...) {
    A[i] += x;
}

Compiled into assembly:

L1: FLD  f4, 0(x3)
    ADDD f6, f4, f2
    FST  0(x3), f6
    ADD  x3, x3, 8
    j    L1

Every single iteration reuses architectural registers f4 and f6. Even if the first FLD misses in cache, the second iteration cannot start its FLD into f4 because of WAR/WAW hazards on f4 and f6! Thus, the number of registers in an ISA limits the number of instructions that can be in the pipeline, and out-of-order issue by itself does not provide any significant performance improvement!

Register Renaming to the Rescue

Floating-point pipelines often cannot be kept filled with a small number of architectural registers (for instance, the IBM 360 had only 4 floating-point registers). Can a microarchitecture use more registers than specified by the ISA without breaking ISA compatibility?

Yes! Robert Tomasulo of IBM suggested an ingenious solution in 1967 using on-the-fly register renaming. Any anti-dependence (WAR) or output-dependence (WAW) can be eliminated by giving the new write a fresh storage location (name). Look at what happens to our 6-instruction example when hardware renames f4 in instructions 5 and 6 to a fresh internal register f4':

The WAR edge between 3 and 5 disappears! Now watch the execution schedule:

In the pipeline, Decode performs register renaming and adds instructions to the issue-stage Reorder Buffer (ROB) (our instruction pool). Because every write gets a unique renamed destination, renaming makes WAR and WAW hazards impossible. Any instruction in the ROB whose RAW hazards are satisfied can be issued immediately, yielding true out-of-order (dataflow) execution.

✎ Check Your Understanding

  1. Why did naive out-of-order issue fail to speed up the 6-instruction sequence when FLD f4 had a long latency? Answer: Instruction 5 (FDIV.D f4, f2, f8) had a WAR hazard on f4 with the stalled instruction 3 (FMULT.D f6, f4, f2), blocking 5 and 6 from executing ahead of 3.

  2. Which two hazard types are completely eliminated by register renaming, and which one remains? Answer: WAR and WAW hazards are completely eliminated; only RAW hazards (true data dependences) remain.


Section 3: Data-in-ROB Microarchitecture and Separating Completion from Commit

How do we build register renaming and out-of-order execution in hardware? Let’s examine the “Data-in-ROB” design first.

Renaming Structures (Data-in-ROB)

There are two central tables:

  1. Renaming Table & Architectural Register File (Regfile): One entry per architectural register (f1, f2, …), containing a presence bit p and a data / tag field:
    • If p = 1 (present), the architectural register holds the valid, up-to-date data value.
    • If p = 0 (busy), the field holds a tag (t_i) pointing to the ROB slot of the instruction that will produce that register’s value.
  2. Reorder Buffer (ROB): A FIFO queue of instruction templates with slots indexed by tags t_1, t_2, \dots, t_n (Head = oldest, Tail = newest). Each ROB entry tracks:
    • i (issued bit), Opcode (op)
    • Source 1: p1 (presence bit), Tag / Src1 (either the ready value if p1=1, or producer tag t_k if p1=0)
    • Source 2: p2, Tag / Src2
    • Destination: p_dst (whether result is ready), Reg (architectural destination register), Result (holds completed value before commit), and Except? (exception flags).

Let’s trace the four lifecycle events of an instruction in this machine:

  1. Dispatch (at Decode, in program order):
    • Allocate the next ROB slot at Tail (its index t is this instruction’s tag).
    • Read source operands from the architectural regfile/rename table. If an operand is non-busy (p=1), copy its value to Src1/Src2 with p=1. If it is busy (p=0), read <p, result> from the producing ROB slot at that tag index (bypassing if just completed); if still not ready, copy the producer’s tag t_k into Src and set p=0.
    • Write the destination architectural register entry in the rename table with <p=0, Tail, _> so all future readers point to this instruction’s tag.
  2. Issue (out of order):
    • Whenever an entry has i=0 and both p1=1 and p2=1 (and its FU is free), set i=1 and dispatch the operation and values to the Functional Unit.
  3. Completion (out of order):
    • The FU broadcasts <t, result> onto a common bus.
    • The ROB writes Result and Except? into slot t and sets p_dst = 1.
    • Simultaneously, all waiting Src1 and Src2 fields in the ROB are searched associatively for tag t; on a match, the hardware sets p=1 and copies result into Src. (Note: replacing the tag by its value via associative CAM broadcast across every ROB source slot is an expensive hardware operation!)
  4. Commit (in order, at Head):
    • Wait until the oldest instruction at Head has p_dst = 1.
    • Check Except?. If no trap, copy Result into the architectural register file: if the rename table’s tag for Reg still matches Head (no younger writer overwrote the mapping), set <1, _, Result>; otherwise (a younger instruction already renamed Reg), update the committed value while leaving the rename table’s busy tag intact (<0, _, Result>). Then dequeue Head.
    • When can a tag/name be reused? Only whenever an instruction commits (freeing its ROB slot).

Why Separate Completion from Commit?

In early out-of-order machines (like Tomasulo’s original IBM 360/91), completion equaled commit: as soon as an instruction finished executing, it immediately updated architectural registers. That creates two severe problems:

  1. WAW hazards if a younger instruction writes before an older one if not carefully gated.
  2. Imprecise traps/exceptions: If instruction I_4 finishes and overwrites f8 before older instruction I_1 finishes and discovers a divide-by-zero or page fault, the architectural state is already corrupted when the trap fires! Imprecise traps make debugging and OS virtual-memory restarts nearly impossible.

By separating completion from commit, the ROB holds completed values temporarily (out-of-order completion) and updates architectural state strictly in program order (in-order commit). Look at how a snapshot of the ROB moves from Cycle t to Cycle t + 1:

When a Trap is detected at the Commit point:

What if we need to flush only part of the ROB without taking a full trap—such as on a branch misprediction? Repairing the rename table on a partial squash is non-trivial because every enqueued instruction after the branch modified the rename table. Two solutions exist:

Historical Perspective: Why OoO Faded Until the 1990s

Tomasulo’s 1967 IBM 360/91 FPU pioneered distributed reservation stations (3 entries for the Adder, 2 for the Multiplier, 6 load buffers, 3 store buffers) connected by a Common Data Bus (<tag, result>) that broadcast results to all waiting entries simultaneously. Yet despite being built commercially in the 1960s, out-of-order execution largely disappeared until the 1990s for two architectural and two economic reasons:

[Editor Note: removed blank transition slide and acknowledgements slide.]

✎ Check Your Understanding

  1. In a Data-in-ROB machine, when are source tags replaced by actual data values, and when can an instruction’s ROB tag/slot be reused? Answer: Source tags are replaced by data whenever a functional unit produces data (via associative broadcast on completion). A ROB tag/slot can only be reused whenever that instruction commits in order at the ROB head.

  2. Why did separating completion from commit solve the problem of imprecise traps? Answer: Out-of-order completion writes results and exception flags only into temporary ROB buffers; architectural state is updated strictly in program order at commit, so if an older instruction traps, all younger instructions can be cleanly killed before they alter architectural state.