Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Architecture Metrics Reference
  • Workload Taxonomy for Architects
  • Architecture Glossary
  • Computer Architecture Cheatsheet
  • Pipeline Fundamentals14
    • Pipeline Throughput
      • The Five-Stage Datapath
      • Stage Depth and Clock Period
      • CPI and Speedup Arithmetic
      • Hazard Classes: Structural, Data and Control
      • Forwarding and Stalls
    • Branch Prediction and Fetch
    • Out-of-Order Superscalar Execution
  • Memory Hierarchy15
  • NoC and Interconnect Architecture6
  • Coherency and Memory Ordering9
  • Performance Analysis9
  • Accelerator Architectures6
  • SoC Architecture Tradeoffs9
  • Architecture Interview Prep14
Loading lesson

‹Pipeline Throughput
  1. Topics
  2. Computer Architecture
  3. Pipeline Fundamentals
  4. Pipeline Throughput
  5. The Five-Stage Datapath

Computer Architecture · All levels

The Five-Stage Datapath

What each of the five stages does and what the pipeline registers carry between them.

On this page

    What lives in each stage

    Each stage owns one job. Fetch produces an instruction word, decode produces operands, execute produces a result, memory produces loaded data, and writeback retires it.

    Stages communicate only through pipeline registers. No stage reaches into another stage directly.

    Register

    Data carried

    Control carried

    IF/ID

    Instruction word, PC, PC+4

    Valid bit

    ID/EX

    Two operands, immediate, rs/rd names

    ALU op, RegWrite, MemRead, MemWrite, Branch

    EX/MEM

    ALU result, store data, rd name

    RegWrite, MemRead, MemWrite, branch outcome

    MEM/WB

    Loaded word or ALU result, rd name

    RegWrite, result select

    Registers carry data plus control

    Control travels with its instruction. A MemRead bit in ID/EX belongs to the instruction in that register, not to the stage.

    This pairing is what makes stalls and flushes local decisions. Each register can be held or cleared without touching the others.

    Valid and kill alignment

    A stall freezes the PC and IF/ID and injects a bubble into ID/EX. The bubble is a register with control bits cleared, so it retires as a no-op.

    A flush clears the wrong-path registers and gates side effects. A killed store must never write memory and a killed writeback must never write the register file.

    • Stall: hold PC and IF/ID, inject a bubble into ID/EX.

    • Flush: clear IF/ID and ID/EX on a taken branch, gate memory and register writes.

    • Bubble: valid 0 with control 0, safe to retire.

    Common pitfall

    Moving logic across a stage boundary without updating the forwarding and flush assumptions breaks producer-consumer pairs. Revalidate every moved pair against the hazard rules in the later lessons.

    Interview

    Likely probe: what each pipeline register holds and what kill must gate. Answer with the register table above, then state that kill gates memory writes, register writes and valid propagation together.

    Check yourself A load-use hazard stalls one cycle. Which registers hold and which one takes the bubble?

    The PC and IF/ID hold, so the same instruction is fetched again. ID/EX takes the bubble while the load advances to MEM.

    Check yourself A branch resolves taken in EX. Which in-flight work is discarded?

    The instructions in IF/ID and ID/EX came from the wrong path, so both registers are cleared. Their pending writes are gated off.

    Testbench

    A five-deep valid pipeline with kill, plus a testbench that checks steady-state count, five-cycle latency and kill clearing.

    pipe_valid.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    module pipe_valid (
      input  logic clk,
      input  logic rst_n,
      input  logic in_valid,
      input  logic kill,
      output logic out_valid
    );
      logic [4:0] v;
      always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) v <= 5'b0;
        else begin
          v[0] <= in_valid & ~kill;
          v[1] <= v[0] & ~kill;
          v[2] <= v[1] & ~kill;
          v[3] <= v[2] & ~kill;
          v[4] <= v[3] & ~kill;
        end
      end
      assign out_valid = v[4];
    endmodule
    

    Related topics

    • Pipelining

    Previous

    5 / 86

    Next: Stage Depth and Clock Period

    Up next

    Up nextStage Depth and Clock Period

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • CPI and Speedup Arithmetic
    • Hazard Classes: Structural, Data and Control
    • Forwarding and Stalls