Lecture 13: OoO 2

Section 1: Out-of-Order Design Variants and the Unified Physical Register File (UPRF)

Let’s step back and look at the entire spectrum of out-of-order microarchitectures. Any Tomasulo-style pipeline must track five distinct activities in hardware tables:

  1. Register rename (mapping architectural registers to internal names).
  2. Post-dispatch, pre-issue operand staging (holding ready/waiting operands before issue).
  3. Post-completion, pre-commit result staging (holding speculative results before commit).
  4. Post-commit result staging (the Architectural Register File, ARF).
  5. Program order for in-flight instructions (needed if we split commit from completion).

Different classic designs arise simply by choosing which tables to fuse and how to distribute them:

Why do all these variants exist? Because bits per entry and number of entries differ sharply across structures. For example, a ROB is usually several times larger than the issue window/reservation stations (because completed instructions sit in the ROB waiting for an older slow instruction to commit, while unissued instructions sit in the issue window). Separating data storage (UPRF) from ordering (ROB) and scheduling allows a smaller-area design and avoids copying data from the ROB into an ARF on commit!

How the Unified Physical Register File (UPRF) Works

In a UPRF machine:

Wait: when can we reuse a physical register? Be very careful here! Consider this sequence renamed from architectural registers (x1, x3, x6...) to physical registers (P1, P2, P3...):

You might think: “We can free P1 as soon as ld P1, (Px) commits!” That is completely wrong! Look at ld P5, (P1) and sd P6, (P1)—those younger instructions are still reading P1 even after ld P1, (Px) commits, and if a trap happens before P1 is overwritten, architectural x1 is P1! Instead, P1 stays live until the next writer of x1 commits! Only when the next instruction that writes x1 commits is it guaranteed that no older or future instruction can ever need the old P1 again.

Worked Example: Physical Register Management Step-by-Step

Let’s trace a complete 5-instruction sequence through a UPRF machine with four structures:

Let’s dispatch all five instructions in order:

  1. ld x1, 0(x3)
    • Source x3 reads P7 from Rename Table. Since P7 is present in Physical Regs, p1 = p, PR1 = P7.
    • Dest x1 reads old mapping LPRd = P8, pops P0 from Free List (PRd = P0), and updates Rename Table x1 -> P0.
    • ROB row 1: use=x, op=ld, p1=p, PR1=P7, Rd=x1, LPRd=P8, PRd=P0.
  2. addi x3, x1, #4
    • Source x1 reads P0 from Rename Table (P0 is not ready yet, so p1 is blank, PR1 = P0).
    • Dest x3: LPRd = P7, pops P1 (PRd = P1), updates Rename Table x3 -> P1.
    • ROB row 2: use=x, op=addi, p1=_, PR1=P0, Rd=x3, LPRd=P7, PRd=P1.
  3. sub x6, x7, x6
    • Sources x7 -> P6 (p1=p, PR1=P6) and x6 -> P5 (p2=p, PR2=P5).
    • Dest x6: LPRd = P5, pops P3 (PRd = P3), updates Rename Table x6 -> P3.
    • ROB row 3: use=x, op=sub, p1=p, PR1=P6, p2=p, PR2=P5, Rd=x6, LPRd=P5, PRd=P3.
  4. add x3, x3, x6
    • Sources x3 -> P1 (not ready) and x6 -> P3 (not ready).
    • Dest x3: LPRd = P1, pops P2 (PRd = P2), updates Rename Table x3 -> P2.
    • ROB row 4: use=x, op=add, p1=_, PR1=P1, p2=_, PR2=P3, Rd=x3, LPRd=P1, PRd=P2.
  5. ld x6, 0(x1)
    • Source x1 -> P0 (not ready).
    • Dest x6: LPRd = P3, pops P4 (PRd = P4), updates Rename Table x6 -> P4.
    • ROB row 5: use=x, op=ld, p1=_, PR1=P0, Rd=x6, LPRd=P3, PRd=P4.

Now watch Execute & Commit of the first two instructions:

Superscalar Register Renaming

Real high-performance processors rename multiple instructions per cycle (for example, Inst 1 and Inst 2 simultaneously). Suppose we naively connect both Inst 1 and Inst 2 to the Rename Table’s read ports and write ports in the same cycle, assigning free tags to Inst 1.PDest and Inst 2.PDest. Does this work?

No! Suppose Inst 1 writes x1 and Inst 2 reads x1 (Src1 or Src2). Because both instructions look up the Rename Table in the same cycle before Inst 1 has updated it, Inst 2 will read the stale physical register for x1 instead of Inst 1’s newly allocated PDest!

To fix this, we add intra-cycle RAW hazard checking in parallel with the rename lookup:

[Editor Note: removed title slide, previous-lecture recap slide, and course-specific homework label.]

✎ Check Your Understanding

  1. In a Unified Physical Register File (UPRF) processor, when an instruction commits, what happens to the physical register PRd that it wrote, and what happens to LPRd (the previous physical register for that architectural destination)? Answer: PRd becomes the new committed architectural register (via the committed mapping table, with no data copying), while LPRd is freed and returned to the Free List.

  2. Why does a 2-wide superscalar renamer need equality comparators (=?) and multiplexers between Inst 1 and Inst 2? Answer: If Inst 2 reads a register written by Inst 1 in the same cycle, reading the Rename Table directly would return Inst 1’s old mapping; the comparators detect the intra-cycle RAW dependency and mux in Inst 1’s newly allocated PDest instead.


Section 2: Load-Store Queue Design and Speculative Memory Disambiguation

We now know how to eliminate register name hazards and track register RAW hazards out of order. After control hazards (branch prediction), data hazards through memory are the next most important bottleneck to superscalar performance. Remember from Lecture 12: unlike register hazards, memory addresses (sd x1, (x2) followed by ld x3, (x4)) are not known at decode—we do not know whether x2 == x4 until execution!

The Speculative Store Buffer

Just like register updates, stores must not modify main memory or the L1 Data Cache until the store instruction commits (otherwise, a mis-speculated or trapping store would permanently corrupt memory). To hold speculative stores safely, we introduce a Speculative Store Buffer:

Now what happens when a younger load executes while older uncommitted stores sit in the Speculative Store Buffer? We perform Load Bypassing (Store-to-Load Forwarding):

When Can a Load Execute Out of Order?

Consider the classic memory-disambiguation dilemma:

sd x1, (x2)
ld x3, (x4)

Suppose x4 is ready long before x2 (for example, x2 depends on an earlier slow computation). When can we execute the load? Modern superscalars choose among three progressively more aggressive strategies:

  1. Conservative Out-of-Order Load Execution (e.g., MIPS R10K, 16-entry address queue):
    • Execute the load ahead of older stores only if all previous store addresses are known and x4 != x2.
    • Each load address is compared against the addresses of all previous uncommitted stores (sometimes using a partial conservative check, e.g., comparing only the bottom 12 bits of the address, to save comparator hardware—if those 12 bits differ, the full addresses definitely differ!).
    • Do not execute the load if any previous store address is not yet known. This is 100% safe (zero memory mis-speculation squashes), but stalls independent loads whenever any older store is slow to compute its address.
  2. Address Speculation:
    • Guess that x4 != x2 and execute the load immediately—even before older store addresses are known!
    • Hardware must buffer all completed-but-uncommitted load and store addresses in program order.
    • When an older store eventually computes its address x2, it searches younger completed loads: if we subsequently find x4 == x2, the load read stale data! Hardware must squash the load and all following instructions and re-execute.
    • Trade-off: Huge speedups when stores and loads rarely alias, but a large penalty for inaccurate address speculation when they do.
  3. Memory Dependence Prediction (e.g., Alpha 21264):
    • Start optimistic: guess x4 != x2 and execute loads before older stores.
    • If a load later turns out to have x4 == x2, squash the load and all following instructions—but learn from the mistake by marking that load instruction’s PC as store-wait in a predictor table.
    • Subsequent executions of that same load instruction will conservatively wait for all previous stores to complete, avoiding repeated expensive squashes!
    • Periodically clear store-wait bits in case program behavior or pointer aliasing changes over time.

Together—virtual memory with hardware TLBs and alias-free VIPT caches at the memory interface, paired with superscalar register renaming, a unified physical register file, an in-order ROB commit point, and speculative load-store disambiguation in the core—these mechanisms form the complete foundation of a modern high-performance processor.

[Editor Note: removed acknowledgements slide.]

✎ Check Your Understanding

  1. If a load’s address matches two entries in the Speculative Store Buffer (one older than the load, one younger, or two older entries) as well as a line in the L1 Data Cache, which data value must the load use? Answer: It must use the data from the Speculative Store Buffer, specifically from the youngest store that is still older than the load.

  2. How does the Alpha 21264’s Memory Dependence Prediction improve upon pure Address Speculation? Answer: Like Address Speculation, it guesses loads don’t alias unknown stores, but whenever a load does collide (x4 == x2) and causes a squash, it marks that load as store-wait so future executions wait for older stores instead of repeatedly mis-speculating (with store-wait bits cleared periodically).