Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Debug a Queue That Advances While Stalled

Hardware interview practice

Debug a Queue That Advances While Stalled

MediumMemory SystemsSystemVerilog

A queue passes all tests when out_ready is always high but loses data under backpressure. The read pointer update shown below is the first divergence from the reference queue. Verify the failure, repair the transfer condition, and add a regression that prevents recurrence.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

assign out_valid = (count != 0);
assign out_data  = mem[rptr];
always_ff @(posedge clk) begin
  if (!rst_n) rptr <= '0;
  else if (out_valid) rptr <= rptr + 1'b1; // faulty
end
Reviewed example

Work through one case

Input
Case 1: Queue A,B and hold ready low for two cycles
Case 2: Raise ready while A is valid
Case 3: Assert reset during a stall
Expected output
Case 1: faulty RTL displays A then B; repaired RTL holds A for both cycles
Case 2: exactly one pop occurs and B may appear after the accepting edge
Case 3: the queue empties, out_valid drops, and no pre-reset item is later reported as transferred

The shown result follows by applying this rule: The debug method locates the first pointer/reference-queue divergence rather than only observing the final missing packet. The cases also demonstrate this requirement: Add an assertion for stable stalled output and a scoreboard test that applies randomized ready gaps, then retain the smallest failing seed as a regression.

What to cover

Requirements

  1. Reproduce with a nonempty queue and out_ready=0 for at least two cycles; identify that out_data changes because rptr advances without a transfer.
  2. Define pop as out_valid&&out_ready and advance rptr and decrement count only on pop, with simultaneous push/pop handled by the existing queue contract.
  3. Active-low synchronous reset clears rptr, wptr, and count so both queue ends realign; while out_valid&& !out_ready, out_valid and out_data must remain stable and no item may be removed.
  4. Add an assertion for stable stalled output and a scoreboard test that applies randomized ready gaps, then retain the smallest failing seed as a regression.
asic.fyi · Learn silicon end to end.info@asic.fyi