
This part is built on a challenge shared by Rahul Behl of Tenstorrent. In a LinkedIn post about how he interviews RTL and DV engineers, he described three FIFO challenges, and he has published all three as PPA challenges on QuickSilicon, with a synthesis and timing report after every run. This is the second of them, the FIFO-based ID Tracker: a FIFO of requests that must flag, every cycle, which request IDs are currently stored in it, even when an ID appears more than once. The analysis below is our own.
This is Part 20 of the FIFO series. Part 19 answered one ID per query port by searching every entry. Here the question is every ID, every cycle, as a vector. That changes which structure wins, and it opens up a neat trick that needs neither a search nor a counter.
Key takeaways
- The output is a vector with one bit per possible ID, set while at least one copy of that ID is stored. Duplicates are what make it hard.
- Decode-and-OR over the stored entries is correct and needs no extra state, but costs DEPTH times NID gates and a DEPTH-wide OR per ID.
- A counter per ID handles duplicates with an increment on push and a decrement on pop, and the nonzero flag can be registered.
- A cheaper exact answer stores, per ID, the pointer of its youngest copy. A pop clears the bit only when it removes that youngest copy.
- Same-cycle push and pop of the same ID, and push and pop at full, are where wrong answers hide. The set must win.
In this part
- The problem
- The interface
- Three structures
- The youngest-copy pointer
- RTL sketch
- Corner cases
- Timing, area and power
- Verification checklist
- Interview questions
- Where it is used in real chips
- The rest of the series
The problem
A request FIFO holds entries, each with an ID from a fixed range of NID values. Every cycle the block must output present[NID-1:0], where bit k is set exactly when at least one stored entry has ID k. IDs can repeat. The FIFO still pushes and pops in strict order.
Why would anyone need the whole vector? Because many consumers look at it at once. An arbiter may need to skip every request whose ID is already in flight. A scheduler may need to see which threads have work queued. A response path may need to know which IDs are safe to retire. Each would otherwise need its own query port from Part 19, and with enough ports the search becomes the biggest block in the design.
The interface
The FIFO side is the same as Part 19: push, wid, wdata, full, pop, rid, rdata and empty. The new output is present. As in Part 19, it describes the entries stored at the start of the cycle: a push this cycle shows up next cycle, and a pop this cycle still counts this cycle. That definition lets present come straight from flip-flops, which is the best thing you can offer the many consumers that read it.
Three structures

A. Decode and OR. Decode each valid slot's ID into a one-hot vector and OR all the vectors together. Duplicates are handled for free, because an OR does not care how many ones it sees. There is no extra state. The cost is DEPTH times NID AND gates and NID OR trees, each DEPTH inputs wide, sitting between the ID registers and the output. For a small FIFO with few IDs this is the smallest answer. As DEPTH grows, the OR trees get deeper and the gate count grows with the product.
B. A counter per ID. Keep cnt[k], AW+1 bits wide so it can reach DEPTH. Increment it when ID k is pushed, decrement it when ID k pops, and leave it alone when both happen in the same cycle. Bit k of the output is cnt[k] != 0. To get the output from flops, register the nonzero flag alongside the count and compute its next value from the next count. The cost is NID small up/down counters plus two decoders, one for the push ID and one for the pop ID.
C. A youngest-copy pointer per ID. The same storage as B, but no adders. It is described next.
The youngest-copy pointer
The counter in option B carries more information than the output needs. The output only asks whether a copy is left. In a FIFO, copies leave in the order they arrived, so the last copy of ID k to leave is the youngest copy, the one pushed most recently. If we remember where the youngest copy lives, we know exactly when the last copy leaves.
So keep last[k], the full pointer, including the wrap bit, of the most recent push of ID k. On a push of ID k, set present[k] and write the write pointer into last[k]. On a pop of ID k, compare the read pointer with last[k]. If they are equal, the entry leaving is the youngest copy, so no copy remains and present[k] clears. If not, a younger copy is still inside, so the bit stays set. A push of ID k in the same cycle sets the bit again, and the set wins.
Why is the equality safe? While present[k] is set, last[k] names a live entry, and live pointers are unique within the window that the wrap bit covers. A pointer value from many laps ago could alias, but it is never compared: the compare only happens when ID k is popping, which means a copy of k is live, which means last[k] was written by that copy or a younger one.

The trace shows both outcomes. In cycle 3 an ID 3 pops from pointer 0 while last[3] is 2, so ID 3 stays present. In cycle 4 a new ID 3 is pushed, moving last[3] to 3, while the only ID 5 pops from pointer 1, which equals last[5], so ID 5 clears. ID 3 only clears in cycle 6, when the copy at pointer 3 leaves.
RTL sketch
module fifo_id_tracker #(
parameter int W = 32,
parameter int NID = 16,
parameter int DEPTH = 8, // power of two
localparam int IDW = $clog2(NID),
localparam int AW = $clog2(DEPTH)
) (
input logic clk,
input logic rst_n,
input logic push,
input logic [IDW-1:0] wid,
input logic [W-1:0] wdata,
output logic full,
input logic pop,
output logic [IDW-1:0] rid,
output logic [W-1:0] rdata,
output logic empty,
output logic [NID-1:0] present
);
logic [W-1:0] data [DEPTH];
logic [IDW-1:0] id [DEPTH];
logic [AW:0] last [NID]; // pointer of the youngest copy of each ID
logic [AW:0] wptr, rptr;
wire do_pop = pop && !empty;
wire do_push = push && (!full || do_pop);
assign empty = (wptr == rptr);
assign full = ((wptr ^ rptr) == {1'b1, {AW{1'b0}}});
assign rid = id[rptr[AW-1:0]];
assign rdata = data[rptr[AW-1:0]];
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin
wptr <= '0;
rptr <= '0;
present <= '0;
end else begin
for (int k = 0; k < NID; k++) begin
if (do_pop && rid == k && rptr == last[k]) present[k] <= 1'b0;
if (do_push && wid == k) present[k] <= 1'b1; // set wins
end
if (do_push) wptr <= wptr + 1'b1;
if (do_pop) rptr <= rptr + 1'b1;
end
always_ff @(posedge clk)
if (do_push) begin
last[wid] <= wptr;
data[wptr[AW-1:0]] <= wdata;
id[wptr[AW-1:0]] <= wid;
end
endmodule
The last array has no reset. That is safe for the same reason the compare is safe: last[k] is only read when ID k is popping, and by then a push of ID k has written it.
Corner cases
- Push and pop of the same ID in one cycle. If the pop removes the youngest copy, the clear and the set land on the same bit. The set wins and
last[k]moves to the new entry. Getting this order wrong drops an ID that is still stored. - Push and pop at full. The push writes the slot the pop is leaving. Nothing in this design is indexed by slot except the data and ID arrays, so there is no clash beyond the one above.
- Every entry the same ID. The bit stays set through DEPTH pops and clears on the last. A counter design would need to reach DEPTH here, which is why its width is AW+1 and not AW.
- Pop when empty. Ignored by
do_pop, so the staleridfrom a freed slot never reaches the clear logic. - Flush. A synchronous flush must clear the whole
presentvector in the same cycle it moves the read pointer.lastneeds no change.
Timing, area and power
- Area by option. A has no state but scales with DEPTH times NID. B and C both store NID times (AW+1) bits. C replaces each up/down adder with an equality compare, which is smaller and has no carry chain. In a challenge that reports synthesis after every run, comparing A against C at the given DEPTH and NID is the first experiment to make.
- The pop path. The longest path in B and C is the read pointer through the DEPTH-to-1 ID mux, the decoder, the compare and the bit's next-state logic. Keep a registered copy of the head ID, updated on every pop from the next entry, and the mux leaves the path.
- The output. In B and C,
presentcomes straight from flops, so every consumer gets a full cycle. In A it comes out of an OR tree, and every consumer pays for that tree in its own timing. - Large ID spaces. With many possible IDs and a shallow FIFO, the per-ID state in B and C dominates and A, or the search from Part 19, wins again. The crossover is a library question, so measure it.
- Power. Only one bit can set and one can clear per cycle, so B and C toggle very little. A re-evaluates the whole OR array whenever an ID register changes.
Verification checklist
- A reference queue, and every cycle a check that
presentequals the set of IDs in the queue. - Run a second implementation as a checker. A decode-and-OR model is simple enough to trust and catches any clear that fires too early or too late.
- Assertions:
a_set_wins: assert property (@(posedge clk) disable iff (!rst_n) push && !full |=> present[$past(wid)]); a_empty: assert property (@(posedge clk) disable iff (!rst_n) empty |-> present == '0); - Coverage: same-ID push and pop in one cycle with the youngest copy leaving, a full FIFO of one ID, every ID cleared at least once, and push and pop at full.
- Use a small ID pool for most of the run so duplicates are constant, and a full-range pool for the rest so every bit of
presenttoggles.
A cycle-accurate Python model of this RTL ran 480,000 random cycles at depths 2 to 16 with 2 to 16 IDs. Every cycle it compared present with a reference queue, a decode-and-OR model and a counter-per-ID model, and all four agreed. It also reproduces the worked trace above.
Interview questions
1. Why does a set-on-push, clear-on-pop bit per ID fail?
A strong answer gives the duplicate case: two copies of an ID, one pops, the bit clears while a copy is still stored. Then it offers a count or a youngest-copy pointer as the fix.
2. Compare decode-and-OR with a counter per ID.
A strong answer weighs DEPTH times NID gates and an OR tree on the output path against NID counters of AW+1 bits with registered outputs, and says which wins for shallow and deep FIFOs.
3. Can you do it without counters?
A strong answer arrives at the youngest-copy pointer: in a FIFO the last copy to leave is the youngest, so remembering its pointer and comparing at the pop is enough. It then argues why the compare cannot alias.
4. Push and pop of the same ID in one cycle, and the pop is the youngest copy. What happens?
A strong answer says the set must win, last moves to the new entry, and shows the ordering of the RTL lines that makes it so.
5. What limits the clock frequency, and how do you fix it?
A strong answer traces the read pointer through the head ID mux, the decode and the compare, and removes the mux with a registered head ID.
Where it is used in real chips
Presence vectors appear wherever many consumers need to know which IDs are busy. Interconnect bridges and AXI interfaces use them to block requests whose ID is already outstanding. NoC routers and network interfaces track which sources or virtual channels have traffic queued. DMA engines and accelerators track which channels or contexts have work pending, and PCIe interface logic tracks which tags are in use.
The rest of the series
Part 19 covered the ID-aware FIFO, which answers one ID per query by searching every entry.
Part 21 turns the search into a lookup that returns data: the associative FIFO, which matches by address or ID and picks the right copy in circular order.
Want to test your own answer? Try the FIFO-based ID Tracker challenge on QuickSilicon and see how your design synthesizes and times.


Your comments will be moderated before it appears here.