Overview
In a pipelined microprocessor, multiple instructions are overlapped to improve performance, even though the instruction set architecture (ISA) defines behavior as strict sequential execution over architectural state such as registers, the program counter, and memory. To keep pipelined execution faithful to those sequential ISA semantics, implementations use mechanisms such as interlocking and data forwarding. Hazard detection is the pipeline-control role that recognizes hazard conditions in this overlapped execution and initiates the appropriate response, such as stalling or using forwarding. [C1]
Role in pipelined execution
Pipelining creates the possibility that one instruction in an earlier stage depends on results or control decisions from instructions farther down the pipeline. The evidence describes these situations as hazard conditions that may require the pipeline to stop making progress for a cycle, or to cancel instructions after a branch misprediction. Such cycles can correspond to zero ISA-level progress while still preserving safety with respect to the sequential model. [C2]
Data hazards
A data hazard occurs when an instruction farther down the pipeline imposes a dependency on an instruction currently in decode. In the described STALL pipeline variant, no data forwarding is used; instead, an instruction can stall in the decode stage for up to three cycles whenever an instruction farther down the pipeline imposes a data hazard. [C3]
Forwarding can reduce the need for stalls. In the described LF variant, an additional forwarding path from the data-memory output to the pipeline register feeding the data-memory input allows some load/use hazards to be resolved by forwarding rather than stalling. [C4]
Control hazards and cancellation
The evidence also describes branch-prediction variants in which instructions may be canceled if a prediction is wrong. In the NT variant, branches are predicted not taken unless unconditional; in the BTFNT variant, lower-address branches are predicted taken and higher-address branches are predicted not taken unless unconditional. In both cases, up to two instructions must be canceled if the branch is mispredicted. [C5]
Verification implications
Formal verification of a pipelined processor must account for hazard behavior. Burch-Dill-style safety verification proves that each processor cycle has an effect consistent with some number of ISA steps, including k = 0, where the pipeline makes no ISA-level progress. The evidence explicitly gives pipeline stalls for hazard conditions and instruction cancellation after mispredicted branches as examples of such zero-progress cycles. [C2]
Safety alone is not enough: a processor that deadlocks, or does nothing forever, can satisfy a safety property. The evidence therefore states that liveness must also be verified to show that the processor cannot enter a state where it never makes forward progress, and specifically to show that the pipeline does not stall indefinitely. [C6]
Practical design pattern
Within the provided evidence, hazard handling appears as a combination of:
- Stalling: holding an instruction in decode when a downstream instruction imposes a data hazard.
- Forwarding: routing a value from a later pipeline point to avoid some stalls, including some load/use hazards.
- Cancellation: removing in-flight instructions after a branch misprediction.
These mechanisms are part of the broader pipeline-control logic that preserves the ISA’s sequential semantics despite overlapped execution. [C1][C3][C4][C5]