Skip to content
systemcoding.dev
Hardware

Implement a VALID/READY register slice in Verilog

Cut a long combinational path by putting one register stage in a valid/ready stream, without losing a transfer or reordering data.

2 min read
Summarize in AI

A valid/ready stream moves a word when valid and ready are both high at a clock edge. When a long chain of logic sits between two modules, a register slice breaks the data path with a flip-flop and keeps the handshake correct. This version holds one word, and the slot is free whenever it is empty or being emptied this cycle.

slice.vverilog
module slice #(parameter W = 8) (
    input  wire         clk,
    input  wire         rst,
    input  wire         in_valid,
    output wire         in_ready,
    input  wire [W-1:0] in_data,
    output reg          out_valid,
    input  wire         out_ready,
    output reg  [W-1:0] out_data
);
    assign in_ready = !out_valid || out_ready;

    always @(posedge clk) begin
        if (rst) begin
            out_valid <= 1'b0;
        end else if (in_ready) begin
            out_valid <= in_valid;
            if (in_valid) out_data <= in_data;
        end
    end
endmodule

When the slot is full and the consumer is not ready, in_ready falls and the producer holds its data, which is the rule that stops words from being lost. Data and valid are registered, so the path from the producer into the slice ends at a flip-flop.

This slice does not register ready. The path from out_ready to in_ready is still combinational, so a chain of these slices passes the ready signal through all of them in one cycle. When ready is the long path, add a second register stage that stores a skid word, which costs a second data register.

Taggedverilog
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.