Course: Computer Architectures · Lecture: Lecture 11 - Hardware Speculation
1. The missing piece after dynamic scheduling
Branch Prediction Fundamentals chooses a likely path. Tomasulo Dynamic Scheduling chooses pending operations whose inputs and execution resources are ready. Hardware speculation permits execution before knowing whether the predicted path is correct, while deferring permanent changes.
The key distinction is between a result being available to consumers and being committed into architectural state. Architectural state means the registers and memory values the program is entitled to observe. Internal provisional results can differ from it.
An added example starts with committed f8=10. A branch predicts path A; instructions on that path compute f8=3+4 and then f10=f8×2. The processor can produce provisional 7 and 14 before the branch resolves. If the prediction was wrong, discard both. Committed f8 stays 10. If correct, each instruction still waits for its turn and all required safety conditions before commit.
2. What the ROB holds
A Reorder Buffer (ROB) retains issued instructions until commitment. Entries are allocated in program order even when calculations finish out of order. In the lecture’s model every issued instruction, including loads, stores and branches, has an entry; it is not only for instructions after a branch.
| Main field | Purpose |
|---|---|
| Instruction type | Distinguish branch, store or register-producing operation |
| Destination | Architectural register or store address |
| Value | Computed result or store data when available |
| Ready | Whether the required result has been produced |
Later mechanisms need additional information, such as recorded exceptions and a pending store-data producer. The four-field table is an introductory description, not a complete universal implementation specification.
The ROB has a head (oldest uncommitted instruction) and an allocation end for new entries. Circular-buffer organization reuses freed slots; indices wrap around, but instruction age and program order remain tracked.
Example: a completed result can wait
ROB1: f0 = f2 / f4 slow division
ROB2: f8 = 3 + 4 result 7 ready
ROB3: f10 = f8 * 2 result 14 readyROB2 can supply 7 to ROB3’s consumer before committing. But neither younger instruction may commit ahead of ROB1. Once ROB1 finishes safely and commits, commitment can advance through ready entries according to the machine’s commit capacity.
Fetch is not the commit condition. These instructions were already fetched before issue and execution. Fetch may be far ahead. Commitment waits for the oldest uncommitted instruction to be ready and safe, not for IF to reach a code line.
3. Four steps and four hardware roles
Issue → Execute → Write result → Commit| Structure | Role |
|---|---|
| Reservation station | Hold an operation and track its input values or missing producers |
| Functional unit | Perform the operation |
| Common Data Bus (CDB) | Broadcast a result with its producer tag |
| ROB | Track order and retain the instruction/result until commit |
Issue
Both a suitable reservation station and a ROB slot must be available. Otherwise issue stalls. Read available operands from committed registers or ready ROB results. For a missing operand, retain the producer tag. The instruction’s ROB entry number becomes its output identifier and is carried in the station’s destination field.
This changes the tag source from basic Tomasulo’s station identifier to a ROB identifier. A station’s Qj/Qk still name missing input producers, but now those tags refer to ROB entries. A register mapping records the latest pending ROB producer for that register; existing consumers keep their own selected input tags.
Execute
Calculate when operands and resources permit. Ready operands do not remove functional-unit contention, memory-order constraints or CDB bandwidth limits. RAW correctness still requires using the intended producer’s value.
Write result
For the addition above, the unit broadcasts (ROB2, 7) on the CDB. Stations waiting for ROB2 capture 7, and ROB2 stores 7 and becomes ready. This does not update the committed f8 yet. The completed operation’s reservation station can be released while its ROB entry remains occupied.
If a dependent instruction issues after the broadcast but before commit, it can obtain the ready value from ROB2; it has not missed its only chance to receive it. If the producer has committed, the value is in the committed register file in this design.
Commit
Only eligible entries at the head can commit in program order. A normal register-producing instruction writes its architectural destination and frees its ROB slot. If younger writers exist, the pending-register mapping must continue to identify the appropriate newer producer rather than being blindly cleared by an older commit. Branches and faulting instructions require the special actions below; a ready result alone is insufficient.
Different processors can implement renaming and commitment with physical registers and mapping tables instead of literally copying every result from a ROB to a register file. This note follows the architecture drawn in the slides. Simpler processors may use no ROB at all.
4. Wrong prediction: discard the incorrect future
Assume committed f8=10:
| Entry | Operation | State |
|---|---|---|
| ROB1 | Older division | Still executing |
| ROB2 | Branch predicted A | Actual path is not A |
| ROB3 | Path A: f8=3+4 | 7 ready |
| ROB4 | Path A: f10=f8×2 | 14 ready |
The younger results cannot commit past ROB2. In the lecture’s simplified scheme, when the mispredicted branch reaches the head, discard wrong-path younger entries and restart fetch at the correct successor. Restore/remove the discarded instructions’ pending mappings and other speculative bookkeeping as necessary. ROB1’s valid committed effect stays; f8’s committed value remains 10. Even a consumer of a provisional wrong-path result is discarded if it belongs to that wrong path.
The deck describes recovery at the ROB head; many implementations can redirect sooner. Earlier correct work must not be discarded as if the whole program were undone.
5. Stores and loads: the lecture’s conservative rule
A store prepares its address and data but changes memory only at commit in this model. If memory[A]=5 and a speculative instruction wants to store 9, retain A and 9 provisionally. A wrong-path store can then be discarded while memory stays 5.
A store needs both its address and data by commitment. Page 22 notes extra tracking for the producer of missing store data. Address calculation may happen before the data arrives; a store has a memory destination rather than an output register.
Now place a load of A after that store. It must receive 9, not the old 5. Page 16’s conservative model orders address computation relative to earlier stores and delays the load’s memory-read step when a relevant pending older store has a matching destination. The load may already have a ROB entry and a calculated address while it waits.
Older store to A: pending → commit and update A
Younger load of A: waits → read the updated valueA correctly predicted branch removes a control-path concern; it does not automatically commit the store or eliminate its dependency. A load of a known non-overlapping location has no such same-location dependency. Address uncertainty still needs safe handling. See Memory Disambiguation in Dynamic Scheduling.
Store-to-load forwarding is an additional option in other designs: supply the pending older store’s value directly to the younger load before store commit, while keeping the load speculative. It is not the waiting scheme used in these slides. Register-result forwarding through the CDB must not be confused with this memory-data mechanism.
6. Fault detection versus taking an exception
A speculative instruction may detect a fault, such as an invalid-address load. Record the fault with its ROB entry rather than immediately invoking the handler.
- If the instruction is squashed after a wrong prediction, ignore its recorded fault.
- If it remains on the correct path and reaches the head, take its exception instead of committing a normal result, then discard younger work.
At this boundary older instructions have committed and younger ones have not. This supports Precise Exceptions. A faulting instruction does not commit a bad result merely because it reached the head. “Commit stage” names the point at which fault handling can occur, not permission to publish the faulting operation’s normal effects.
7. Architectural recovery does not erase every internal effect
Speculation can initiate expensive requests, including cache fills or address-translation work. A Translation Lookaside Buffer (TLB) caches translations; a miss may require further work. Starting early hides delay if the path is correct, but can waste resources if wrong. Page 24 says some processors defer selected expensive speculative events, while starting cheaper ones sooner. These are design choices, not universal policies.
Squashing an instruction prevents its architectural result from committing; it need not undo a cache fill or every other microarchitectural effect. “Permanent” in this lesson refers to architectural effects, not to erasing all traces of internal work.
8. Recall and worked answers
- ROB1 is slow; ROB2 has 7 ready. Can ROB3 use 7? Can ROB2 commit first?
- An addition freed its reservation station. Why can its ROB entry still be busy?
- A branch resolves correctly, but an older instruction remains unfinished. Can a following store immediately commit?
- A load from the wrong path detects an exception. Why not handle it immediately?
- A load follows a pending store to the same address. Under the lecture model, what step waits? How could another design differ?
Answers: 1. Yes, a dependent consumer can receive it; no, commitment follows order. 2. Calculation/publication finished but commitment has not. 3. No: readiness, program order and safety still apply. 4. The instruction may be squashed and should never architecturally occur. 5. The memory read waits for the older store; a different design may forward store data while keeping the load provisional.
Multiple issue connection
The next lecture compares the same two-issue loop with and without speculation: later iterations issue early in both cases, but speculation lets their loads execute before earlier branches resolve. Lecture 12 - Multiple Issue