Module 7: Advanced RTL Design Techniques · 7.3 Pipeline Design

Stalls and Bubbles

Simple pipelines assume that downstream logic accepts new transaction data on every clock cycle. In practical hardware systems, downstream consumers experience temporary backpressure. A receiving FIFO becomes full, a memory interface encounters wait states, or a shared bus becomes busy. An unmanaged pipeline overwrites unread data under backpressure conditions. Digital designs require formal flow-control mechanisms to pause data progression safely.

Implementing Pipeline Stalls

Section 5.5 introduced the clock-enable pattern for individual flip-flops. A pipeline stall applies clock-enable control to all stage registers simultaneously. When the stall condition asserts, all pipeline stages hold their current data values:

`timescale 1ns / 1ps
`default_nettype none

module stallable_pipeline (
    input  wire        clk, rst_n,
    input  wire        stall,          // When asserted, freezes all pipeline registers
    input  wire [15:0] data_in,
    input  wire        valid_in,
    output reg  [15:0] data_out,
    output reg         valid_out
);
    reg [15:0] stage1_data, stage2_data;
    reg        stage1_valid, stage2_valid;

    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            stage1_data  <= 16'b0; stage1_valid <= 1'b0;
            stage2_data  <= 16'b0; stage2_valid <= 1'b0;
            data_out     <= 16'b0; valid_out    <= 1'b0;
        end else if (!stall) begin
            // Advance pipeline stages only when not stalled
            stage1_data  <= data_in;         stage1_valid <= valid_in;
            stage2_data  <= stage1_data + 1; stage2_valid <= stage1_valid;
            data_out     <= stage2_data;     valid_out    <= stage2_valid;
        end
        // When stall asserts, registers retain values implicitly
    end
endmodule

The condition else if (!stall) controls assignment execution. When stall = 1'b1, register update statements do not execute, preserving the pipeline state.

Differentiating Stalls and Bubbles

A stall freezes every register across the pipeline. No data moves forward until backpressure deasserts.

A bubble invalidates a single pipeline slot while remaining stages continue to advance. Processors use bubbles to cancel speculative instructions without halting the execution pipeline:

Stall: every stage holds. Bubble: the pipeline moves, one slot is invalid
Figure 1: A stall freezes every stage; a bubble marks one slot invalid and keeps moving

To insert a bubble, force that stage’s valid flag to zero for one clock cycle:

always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        stage1_valid <= 1'b0;
    end else if (flush) begin
        stage1_valid <= 1'b0;   // Insert bubble: mark slot invalid
        stage1_data  <= data_in; // Pipeline continues advancing
    end else if (!stall) begin
        stage1_valid <= valid_in;
        stage1_data  <= data_in;
    end
end

Downstream logic ignores data slots where the valid bit is zero.

Implementing Ready-Valid Handshake Backpressure

Pipelines receive backpressure signals from downstream consumer circuits. Standard bus protocols (such as AXI4-Stream) use a ready-valid handshake mechanism:

wire downstream_ready;                        // Consumer asserts when ready to receive
wire stall = valid_out && !downstream_ready; // Stall when valid data cannot be accepted

The qualification valid_out && ensures the pipeline stalls only when an actual result awaits transfer. If the pipeline contains invalid bubble cycles, execution continues without halting.

Verification Exercise

Add a flush control input to the stallable_pipeline module. Configure flush to insert a bubble into stage 1 without stalling subsequent stages. Write a testbench to verify that flushed transactions produce valid_out = 0.

View Solution
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        stage1_data <= 16'b0; stage1_valid <= 1'b0;
        stage2_data <= 16'b0; stage2_valid <= 1'b0;
        data_out    <= 16'b0; valid_out    <= 1'b0;
    end else if (!stall) begin
        stage1_data  <= data_in;
        stage1_valid <= flush ? 1'b0 : valid_in;   // Clear valid bit during flush
        stage2_data  <= stage1_data + 1;
        stage2_valid <= stage1_valid;
        data_out     <= stage2_data;
        valid_out    <= stage2_valid;
    end
end

The testbench drives valid_in = 1 and flush = 1 simultaneously. Observing signals confirms that the flushed data does not produce an active valid_out signal at the pipeline exit.

Stalls and bubbles provide precise flow control for high-speed digital datapaths. The next article combines these concepts to build a pipelined multiply-accumulate unit.

← Inserting a Pipeline Stage into Existing Logic A Pipelined Multiply-Accumulate Unit →