Course: Computer Architectures
Lecture: Lecture 06 - Exceptions and Interrupts
Definition
A precise exception presents architectural state consistent with stopping at a defined instruction boundary in program order. For the retryable synchronous faults used here:
| Instruction relative to the fault | Required state when the handler takes control |
|---|---|
| Older | All required effects completed |
| Faulting | No committed partial effects; can be retried |
| Younger | No committed effects; can be restarted or discarded |
Architectural state means the programmer-visible registers, memory, status, and restart PC. Internal execution can overlap; correctness depends on which effects become visible.
Slide 16 explicitly requires completion of preceding instructions and restartability of following instructions. The no-partial-effects rule above explains the retryable-fault case; exact exception semantics vary by ISA.
Execution, completion, and commit
- Execution: The functional unit performs the operation.
- Completion: The result is ready, or a fault has been detected.
- Commit: The result is accepted into architectural state in a way consistent with the required ordering.
Slide 24 calls an instruction committed when it is guaranteed to complete. The distinction here adds study guidance: a younger result may be computed and buffered before it is safe to make it architecturally visible.
Multicycle Operations allow an older divide to remain active while younger additions finish. This can happen with in-order issue; out-of-order completion does not itself establish out-of-order issue.
Worked examples from slides 18 and 21-23
Example 1: A younger FP operation faults before an older divide finishes (slide 18)
The lecture uses MIPS-style FP notation:
DIV.D F0, F2, F4
ADD.D F10, F10, F8
SUB.D F12, F12, F14Assume the divide has a longer execution time and independent younger operations can overlap it. The following timeline is explanatory; the slide gives no exact cycle latencies.
| Event | DIV.D (oldest) | ADD.D | SUB.D (youngest) |
|---|---|---|---|
| 1 | Starts | Waiting to start | Waiting to start |
| 2 | Still executing | Starts | Waiting to start |
| 3 | Still executing | Executing | Starts |
| 4 | Still executing | Completes | Executing |
| 5 | Still executing | Result ready | Detects an exception |
At event 5, taking the handler immediately would leave an older instruction unfinished. A state with a new F10 but an unfinished older divide does not describe a complete program-order prefix.
To handle the SUB.D fault precisely:
- Record its exception and prevent its
F12write and any younger effects. - Let the older divide finish. If it also faults, its exception takes priority because it is older.
- If the divide succeeds, make its result and the older add’s result visible in the required order.
- Enter the handler at the
SUB.Dboundary, with the correct olderF0andF10, and no faultingF12update.
Why buffering helps: The add can compute its result early while keeping it pending until the older divide is known to succeed. Without buffering or another recovery mechanism, a later divide fault could leave the younger add already visible.
The slide labels the uncontrolled case imprecise. Different completion times create the problem; they do not force imprecision if commit and recovery are controlled.
Example 2: Two faults are detected in the same cycle (slide 21)
LD is older than DADD. This table reconstructs the slide’s five-stage alignment; trailing stages show the nominal schedule, not execution after taking a fault.
| Instruction | C1 | C2 | C3 | C4 | C5 | C6 |
|---|---|---|---|---|---|---|
| LD | IF | ID | EX | MEM: data page fault | WB | |
| DADD | IF | ID | EX: arithmetic fault | MEM | WB |
Both faults are detected at C4. The processor must select the older LD fault first.
- Do not write the load’s destination: the load failed.
- Do not allow the younger
DADDresult to alter architectural state. - Handle the load page fault and restart at
LDif it is resolved. - Re-execute the instruction stream. If
DADDstill faults when reached, handle it then.
The younger fault need not be preserved as a pending event across the handler; replay can rediscover it. It may disappear if handler activity changes relevant state. This explains the slide’s conditional sequence: fix the first cause, then handle the second if it still occurs.
DADD and its arithmetic-trap behavior belong to the lecture’s teaching example, not standard RISC-V integer addition.
Example 3: The younger fault is detected first (slide 22)
The younger instruction cannot fetch, while the older load is still progressing toward its data access.
| Instruction | C1 | C2 | C3 | C4 | C5 |
|---|---|---|---|---|---|
| LD (older) | IF | ID | EX | MEM: data page fault | WB |
| DADD (younger) | IF: instruction page fault | Fault record carried | Fault record carried | Fault record carried |
The fault-record entries show a conceptual pipeline placeholder, not successful decoding/execution of an instruction whose fetch failed.
At C2, the CPU has detected a fault at the younger instruction’s address. It cannot yet take that fault as the next precise exception because the older load could still fail.
At C4, the older load faults. Its data page fault must be handled first, despite being detected two cycles later. Discard the younger work, resolve the load fault, and restart at the load. If the instruction-fetch fault remains on replay, handle it later.
If the older load had instead succeeded, it would finish before the younger instruction-fetch fault was taken.
Detection order: younger instruction-fetch fault, then older data fault.
Required handling order: older instruction first.
Status flags and ordered handling
Slide 23 proposes associating an exception status with each instruction, setting it on detection, disabling that instruction’s writes, and triggering the exception when the instruction reaches the final stage.
To understand the whole mechanism, combine slide 23 with slide 12’s suppression of younger writes:
- Carry the fault status alongside the instruction or failed-fetch placeholder. A practical implementation also needs the cause and relevant PC/address.
- Let older instructions advance and finish.
- Prevent the flagged instruction from writing registers or memory.
- Select the oldest eligible fault at the ordered handling point.
- Prevent younger visible effects, discard younger work, and redirect to the handler.
Important assumption: A simple last-stage scheme relies on ordering through that stage. If multicycle instructions can complete out of order, use buffering, serialization, rollback, or another mechanism that restores the required program-order boundary. Merely adding a flag to an otherwise uncontrolled pipeline is insufficient.
Stores need particular care: blocking WB alone does not undo a younger store that already changed memory in MEM. Store visibility must be delayed or otherwise recoverable until it is safe.
Implementation choices (slides 17-19)
| Choice in the lecture | Benefit | Cost or limit |
|---|---|---|
| Accept imprecise exceptions | Less recovery control | Restart and debugging become difficult |
| Fast imprecise / slow precise mode | Precision available when required | Serialization reduces overlap |
| Determine exception possibility early | Later instructions wait until older work is safe | Requires early detection; can delay issue |
| Buffer results until older instructions finish | Allows execution overlap with controlled visibility | Additional storage and ordering logic |
Slide 17’s approximately tenfold debug-mode slowdown is a historical example, not the expected cost of all precise-exception processors.
Instruction-set complications
Early side effects and rollback (slide 24)
An autoincrement memory instruction can update its address register before its memory access is guaranteed to complete. If the access faults and execution retries with the incremented register, it can access the wrong location or increment twice.
Explanatory example: conceptually load from address A and then increase the pointer by 8. If the pointer becomes A+8 before a fault at A is resolved, replay must restore A or avoid repeating the increment. Buffer the pointer update, or roll it back before retry.
Implicit condition codes (slide 25)
Condition codes are architectural state too. Their implicit writes create dependencies, must be handled during context save/recovery, and constrain instruction scheduling between the flag-setting instruction and a branch, including delay-slot scheduling in relevant architectures.
Complex instructions (slide 26)
Instructions with unequal internal work are difficult to fit into a uniform pipeline. Pipelining their microinstructions can help execution organization, but exception recovery still needs a correct architectural instruction boundary.
Connection to branch flushing
Control Dependencies and Speculation explains why moving a load before a branch can introduce a new fault and how nontrapping dead-result computations can be moved safely.
A branch misprediction and an exception both redirect control and discard younger work. An exception also supplies a cause and a restart/continuation context to a handler. A flush discards work; a stall delays work. Delaying only the handler does not help if younger instructions keep committing effects.
Common mistakes
- Choosing the first detected fault instead of the oldest fault eligible for handling.
- Equating result completion with architectural commit.
- Assuming in-order issue guarantees in-order completion.
- Suppressing register writes while overlooking younger stores or condition-code changes.
- Assuming a younger recorded fault must still occur after replay.
Related and source
Exceptions and Interrupts, Multicycle Operations, RAW and WAW Hazards, Structural Hazards in Multicycle Pipelines, Pipelining.
E. Sanchez, Exceptions and interrupts in pipelined processors, ASE 2026/27, slides 12 and 16-26. Source PDF: Exceptions and interrupts in pipelined processors.pdf. Timing tables and state explanations are study reconstructions; slide 18 supplies relative completion order, while slides 21-22 supply the five-stage alignments. No exact FP cycle latencies are claimed.
Dynamic scheduling connection
Basic Tomasulo operand tracking does not by itself guarantee recovery of architectural state. The dynamic-scheduling lesson distinguishes saved operand versions from speculative results and in-order commit. Tomasulo Dynamic Scheduling > 6. Renaming does not itself provide rollback
Hardware speculation connection
The ROB-based implementation records faults provisionally, ignores faults from squashed instructions and handles a surviving fault at the oldest uncommitted boundary. Hardware Speculation and the Reorder Buffer > 6. Fault detection versus taking an exception