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:
- Register rename (mapping architectural registers to internal names).
- Post-dispatch, pre-issue operand staging (holding ready/waiting operands before issue).
- Post-completion, pre-commit result staging (holding speculative results before commit).
- Post-commit result staging (the Architectural Register File,
ARF). - 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:
- Tomasulo’s Original Design: Tracks (1) in a rename table, (2) in distributed per-FU reservation stations, has no (3) and no (5) because there is no separate commit, and stores (4) in the ARF.
- Data-in-ROB Design: Tracks (1) in a rename table, (4) in the ARF, and fuses (2), (3), and (5) inside a centralized ROB.
- Unified Physical Register File (UPRF) Design (used in MIPS R10K, Alpha 21264, Intel Pentium 4, and Sandy/Ivy Bridge): Tracks (1) using a Decode Stage Register Mapping plus a Committed Register Mapping, tracks (5) in a separate ROB (which holds no data!), and fuses (2), (3), and (4) inside one centralized Unified Physical Register File (
UPRF).
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:
- During decode, all architectural registers are renamed into indices of a single large Physical Register File (
P0..Pn) that holds both committed and speculative values—no register values are read at decode. - Functional units read operands from the UPRF at issue and write results to the UPRF at completion.
- Commit only updates the Committed Register Mapping (pointing each architectural register to its committed physical register)—zero data movement occurs at commit!
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...):
ld x1, (x3)\told P1, (Px)addi x3, x1, #4\toaddi P2, P1, #4sub x6, x7, x9\tosub P3, Py, Pzadd x3, x3, x6\toadd P4, P2, P3ld x6, (x1)\told P5, (P1)add x6, x6, x3\toadd P6, P5, P4sd x6, (x1)\tosd P6, (P1)ld x6, (x11)\told P7, (Pw)
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:
- Rename Table (
x0..x7): initiallyx1 -> P8,x3 -> P7,x6 -> P5,x7 -> P6. - Physical Regs (
P0..Pn): initiallyP5: <x6>, p,P6: <x7>, p,P7: <x3>, p,P8: <x1>, p(p= data present). - Free List: initially
[P0, P1, P3, P2, P4]. - ROB: columns
use | ex | op | p1 | PR1 | p2 | PR2 | Rd | LPRd | PRd. NoticeLPRd(Last Physical Register for destination) records the previous physical register mapped toRdbefore this instruction overwrote it! (ReadingLPRdrequires a third read port on the Rename Table for each instruction.)
Let’s dispatch all five instructions in order:
ld x1, 0(x3)- Source
x3readsP7from Rename Table. SinceP7is present in Physical Regs,p1 = p,PR1 = P7. - Dest
x1reads old mappingLPRd = P8, popsP0from Free List (PRd = P0), and updates Rename Tablex1 -> P0. - ROB row 1:
use=x, op=ld, p1=p, PR1=P7, Rd=x1, LPRd=P8, PRd=P0.
- Source
addi x3, x1, #4- Source
x1readsP0from Rename Table (P0is not ready yet, sop1is blank,PR1 = P0). - Dest
x3:LPRd = P7, popsP1(PRd = P1), updates Rename Tablex3 -> P1. - ROB row 2:
use=x, op=addi, p1=_, PR1=P0, Rd=x3, LPRd=P7, PRd=P1.
- Source
sub x6, x7, x6- Sources
x7 -> P6(p1=p, PR1=P6) andx6 -> P5(p2=p, PR2=P5). - Dest
x6:LPRd = P5, popsP3(PRd = P3), updates Rename Tablex6 -> P3. - ROB row 3:
use=x, op=sub, p1=p, PR1=P6, p2=p, PR2=P5, Rd=x6, LPRd=P5, PRd=P3.
- Sources
add x3, x3, x6- Sources
x3 -> P1(not ready) andx6 -> P3(not ready). - Dest
x3:LPRd = P1, popsP2(PRd = P2), updates Rename Tablex3 -> P2. - ROB row 4:
use=x, op=add, p1=_, PR1=P1, p2=_, PR2=P3, Rd=x3, LPRd=P1, PRd=P2.
- Sources
ld x6, 0(x1)- Source
x1 -> P0(not ready). - Dest
x6:LPRd = P3, popsP4(PRd = P4), updates Rename Tablex6 -> P4. - ROB row 5:
use=x, op=ld, p1=_, PR1=P0, Rd=x6, LPRd=P3, PRd=P4.
- Source
Now watch Execute & Commit of the first two instructions:
- Execute & Commit
ld x1, 0(x3)(ROB row 1):- Marks
ex = x, writes<x1>intoP0and setspinP0. - Broadcasts tag
P0to the ROB: bothaddi(row 2) andld(row 5) matchPR1 == P0and set theirp1 = p! - On commit of row 1: hardware reads
LPRd = P8, clears/invalidatesP8, and pushesP8onto the Free List! (Becauseld x1just committedP0, nobody can ever needP8again.)
- Marks
- Execute & Commit
addi x3, x1, #4(ROB row 2):- Marks
ex = x, writes<x3>intoP1and setspinP1. - Broadcasts
P1to the ROB:add(row 4) matchesPR1 == P1and setsp1 = p! - On commit of row 2: hardware reads
LPRd = P7, invalidatesP7, and pushesP7onto the Free List!
- Marks
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:
- Comparators (
=?) check whetherInst 1.Dest == Inst 2.Src1andInst 1.Dest == Inst 2.Src2. - Multiplexers at
Inst 2’sPSrc1andPSrc2outputs selectInst 1’s newPDest(fromFree Tags) whenever a match occurs, otherwise passing through theRename Tableread data. (Similarly, if both write the sameDest,Inst 2’s mapping must win when updating the table.) With this parallel bypass network, processors like the MIPS R10K rename 4 serially-RAW-dependent instructions per cycle.
[Editor Note: removed title slide, previous-lecture recap slide, and course-specific homework label.]
✎ Check Your Understanding
In a Unified Physical Register File (UPRF) processor, when an instruction commits, what happens to the physical register
PRdthat it wrote, and what happens toLPRd(the previous physical register for that architectural destination)? Answer:PRdbecomes the new committed architectural register (via the committed mapping table, with no data copying), whileLPRdis freed and returned to the Free List.Why does a 2-wide superscalar renamer need equality comparators (
=?) and multiplexers betweenInst 1andInst 2? Answer: IfInst 2reads a register written byInst 1in the same cycle, reading the Rename Table directly would returnInst 1’s old mapping; the comparators detect the intra-cycle RAW dependency and mux inInst 1’s newly allocatedPDestinstead.
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:
- At decode: A store buffer slot is allocated in program order, with fields
V(Valid),S(Speculative),Tag(the store’s physical memory address), andData. - Splitting stores: Stores split into two micro-operations: “store address” execution (which computes the address and writes
Tag) and “store data” execution (which writesDataonce the value register is ready). - On store commit: When a store becomes the oldest instruction in the ROB and both its address and data are available, it commits by clearing its speculative bit (
S = 0) and eventually draining its data along the Store Commit Path into theL1 Data Cache(Tags | Data). - On store abort (trap or branch misprediction): Simply clear the valid bit (
V = 0).
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):
- The
Load Addresssearches both theSpeculative Store Bufferand theL1 Data Cachein parallel. - If the address hits in both the store buffer and the cache, which should we use? The Speculative Store Buffer, because it holds the newer, uncommitted value not yet written to the cache.
- If the same address appears in the store buffer twice, which should we use? The youngest store older than the load (the most recent write in program order prior to the load).
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:
- 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.
- Execute the load ahead of older stores only if all previous store addresses are known and
- Address Speculation:
- Guess that
x4 != x2and 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 findx4 == 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.
- Guess that
- Memory Dependence Prediction (e.g., Alpha 21264):
- Start optimistic: guess
x4 != x2and 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 asstore-waitin 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-waitbits in case program behavior or pointer aliasing changes over time.
- Start optimistic: guess
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
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.
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 asstore-waitso future executions wait for older stores instead of repeatedly mis-speculating (withstore-waitbits cleared periodically).