5.2.12 · D1Processor Datapath & Pipelining

Foundations — Precise exceptions in pipelines

1,972 words9 min readBack to topic

This page assumes you know nothing. Before we can talk about "precise exceptions" (the parent topic), we must build every word and symbol that topic throws at you. We go in order — each idea uses only ideas already defined.


1. What an instruction is

We will call the instructions — the subscript is just their position in program order (the order they are written). comes after and before . That ordering is the single most important idea on this whole page; hold onto it.


2. Architectural state — the "official" picture

Figure — Precise exceptions in pipelines

Look at figure s01: the blue cups are architectural state (visible), the grey scratch pad holds temporary results the program cannot see. An instruction only "counts" the instant its result crosses from grey to blue.


3. Stages — chopping an instruction into steps

Executing one instruction is not instant. We split the work into 5 stages, each done by a different piece of hardware:

Notice: WB is last, and WB is where the "official score" moves. Every mechanism in the parent note is really about controlling WB.

Prerequisite depth on stages lives in 5.2.1-Pipelining-basics.


4. Pipelining — why instructions overlap

Figure — Precise exceptions in pipelines

Figure s02 is the core diagram of the whole subject. Time runs left to right. Each row is an instruction; each coloured block is a stage. Read a vertical slice (one clock cycle) and you see five different instructions in five different stages simultaneously.

Now stare at the vertical dashed line marked Cycle 5 in s02:

This is exactly the snapshot the parent note uses. Everything after this is: what happens if blows up right here?


5. Exception — the "something went wrong" event

For the handler to do its job it must see a clean, believable machine — as if the program had run one instruction at a time and stopped exactly at the culprit. Producing that clean view is the definition of precise.


6. PC and EPC — bookmarks


7. Precise vs imprecise — the punchline picture

Now we can finally state the topic precisely.

Figure — Precise exceptions in pipelines

Figure s03 shows the target state after faults. The green instructions () are done. The red ones () are erased — as if never run. There is a clean dividing line between "done" and "never happened," with no half-finished instruction straddling it. That clean line is precision.


8. Bubble / NOP — the eraser


9. In-order vs out-of-order, and the Reorder Buffer

Data flowing between overlapping instructions before WB is handled by forwarding — mentioned so you know where those hidden scratch values come from.


How it all feeds the topic

Instruction and program order

Architectural state

Five stages IF ID EX MEM WB

Pipelining overlap

Out of order completion problem

Exception event

Handler needs clean state

Precise exception goal

PC and EPC bookmarks

Bubble and flush eraser

ROB commit in order

Speculation bit

Precise exceptions in pipelines

Every box is a term you now own. The parent note simply combines them.


Equipment checklist

Cover the right side and test yourself. If any answer surprises you, reread that section.

What does the subscript in mean?
Its position in program order — is the third instruction as written.
Which single pipeline stage changes architectural state?
WB (Write Back) — nothing is official until WB.
Define architectural state in one line.
The registers and memory the program is allowed to see; the "official score."
Why do overlapping pipeline stages threaten precision?
Out-of-order completion — a younger instruction can finish before an older one, giving a straddling done/not-done line.
What are the three guarantees of a precise exception?
Earlier instructions fully done, faulting-and-later change nothing, EPC points at the culprit.
What does EPC store and why?
The PC of the faulting instruction, so we know the crime scene and where to resume after the handler.
What is a bubble / NOP used for here?
An eraser — flushing an instruction to a NOP so it reaches WB harmlessly, changing no state.
What is "commit" in a Reorder Buffer?
The in-order moment a result moves from the hidden ROB into official architectural state.
Why does a speculation bit let us ignore some faults?
A wrongly-guessed instruction should never have run, so its exception is discarded on flush.