HeadlinesBriefing favicon HeadlinesBriefing.com

Inside CPU Pipelines: Mastny’s Visual Guide to Hazards and Branching

Hacker News •
×

Tim Mastny uses a Hacker News post to walk readers through the inner workings of a classic 5‑stage MIPS pipeline. He cites Dan Luu’s branch‑prediction write‑up and Rodrigo Copetti’s PlayStation analysis as sparks that pushed him past high‑level concepts into concrete details. The guide assumes familiarity with the assembly‑line model but expands on decoding, hazard detection and forwarding.

The article shows how a non‑pipelined CPU stalls while each component works in isolation, then adds inter‑stage registers to keep instruction fields alive across cycles. When an add reaches write‑back, a later sub would overwrite its destination; the Hazard Detection Unit compares source and destination fields to insert bubbles. A Forwarding Unit can route the intermediate result directly to execution, removing stalls for many R‑type ops.

Branch handling builds on those mechanisms. Mastny outlines a simple “predict not taken” scheme where the execution stage evaluates the branch condition, forwards the outcome, and injects a nop if the prediction fails. He also mentions branch‑delay slots as a modest hardware shortcut. By visualizing each unit’s signals, the post gives engineers a concrete map for debugging and extending pipeline designs.