Hardware interview practice
Build a two-stage elastic packet pipe
A packet stream needs two registered storage stages and must tolerate arbitrary downstream backpressure without loss, duplication, or reordering. Implement a two-entry elastic pipeline for data and last.
Starting point
Question code
input logic clk, rst_n;
input logic in_valid; output logic in_ready;
input logic [31:0] in_data; input logic in_last;
output logic out_valid; input logic out_ready;
output logic [31:0] out_data; output logic out_last;Reviewed example
Work through one case
Input
The stages contain A then B, out_ready=1, and input C is valid on edge E0Expected output
A retires at E0; after E0 the registered order is B then CThe downstream stage is allowed to advance, so B shifts to the output stage while C replaces B in the input stage on the same edge.
What to cover
Requirements
- Accept input only when in_valid and in_ready are both 1, and retire output only when out_valid and out_ready are both 1.
- Provide exactly two registered entries, preserve order, and permit a simultaneous pop and push when full; an item accepted into an empty pipe at E0 becomes visible after E1.
- While out_valid=1 and out_ready=0, keep out_valid, out_data, and out_last stable and never overwrite the blocked item.
- Asserting rst_n=0 asynchronously empties both entries; after synchronous reset release no output is valid until a new item traverses the pipe.
