Choose at most four pointer steps that expose five broken FIFO pointer wraps.
Hardware context: FIFO pointer wrap and reset under sustained traffic. Drive enough accepted traffic to wrap both pointers repeatedly at an irregular depth.
A FIFO’s read and write pointers step through its slots and wrap back to 0 after the last one. Most wrap bugs only show at the wrap itself, and only at some depths: a FIFO of depth 4 hides a pointer that wraps at a power of two.
The function next_ptr in the specification is correct. Five copies of it each hide one wrap bug. In the task stimulus, call try_step(ptr, depth) once per step you want to test, at most four times.
Each step runs through the correct function and every broken copy. A copy is caught when it returns a different slot on at least one of your steps. After a run you see which copies you caught.
Signals in the timeline
| Signal | Width | Role |
|---|---|---|
hidden_bug | 8 | input of each check |
Full specification
// The next slot of a circular FIFO pointer, for a FIFO of depth slots.
function automatic int next_ptr(input int ptr, input int depth);
return (ptr == depth - 1) ? 0 : ptr + 1;
endfunction
task automatic stimulus();
// ptr, depth
try_step(0, 4);
endtask
Rules for your steps: at most 4 calls, depth 1 to 16, and ptr 0 to depth - 1 (a slot that exists).
Examples
Example 1
Your steps follow the rules- Input
stimulus() makes 4 calls
- Output
inputs_legal = yes
Every ptr is a real slot of its depth.
Example 2
The wrap at depth 3- Input
try_step(2, 3)
- Output
caught = yes
The correct pointer goes back to 0; the power-of-two copy goes to 3.
Example 3
The step before the wrap- Input
try_step(1, 3)
- Output
caught = yes
At depth 3, slot 1 steps to slot 2. The copy that wraps one slot early goes back to 0.
Constraints and contract
- Call try_step at most 4 times.
- depth is 1 to 16 and ptr is a real slot, 0 to depth - 1.
- Do not call next_ptr yourself.
Hints
Hint 1
A step in the middle of the slots is the same for every copy. Where can a wrap bug show?
Hint 2
Try the wrap at a depth that is not a power of two, and the step just before the wrap.
Hint 3
Two depths are special: the smallest one, and one large enough to need a fourth pointer bit.
What this judge verifies: Your steps run through the correct pointer function and five broken copies. Passing shows your steps separate each broken copy from the correct one.
6 checks on Verilator · local server. Run the examples first, then check the full regression. The suite is local and inspectable. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 6 steps and the final capstone