
A FIFO's full flag works when the producer sits right next to it and reacts in the same cycle. Real producers rarely do. The stop signal crosses a few flops to reach the producer, and data already launched travels through a few pipeline stages before it reaches the FIFO. By the time the producer stops, several more beats are on their way, and the FIFO must have room for every one of them.
This is Part 36 of the FIFO Series. The usual answer is an almost-full threshold set below the depth by the round-trip latency. We look at why that wastes space and can even deadlock a small FIFO, and then build a predictive version that counts exactly what can still arrive, so the FIFO fills to the last entry and never overflows.
Key takeaways
- With a stop path of D cycles and a data path of P cycles, up to R = D + P beats can arrive after the FIFO decides to stop. The FIFO must reserve room for them.
- A fixed threshold reserves R entries all the time. It is simple and safe, but those entries are never used, and a FIFO no deeper than R never lets anything through.
- A predictive threshold remembers the last R go decisions and reserves room only for cycles when the producer was allowed to send. It fills the FIFO completely.
- The predictive rule is a credit counter kept at the receiver. It needs no credit return path, only the round-trip latency as a parameter.
- Get R exactly right. Too small overflows the FIFO; too large only wastes space. Assert both no overflow and that every push matches a go from R cycles earlier.
In this part
- What problem a predictive almost-full solves
- The interface
- Micro-architecture: counting what is on its way
- RTL sketch
- Corner cases
- Timing, area and power
- Verification checklist
- Interview questions
- Where it is used in real chips
- The rest of the series
What problem a predictive almost-full solves
Picture a producer that launches a beat into a pipeline of P stages, with the last stage driving push into the FIFO. The FIFO drives a registered go signal back, and that signal passes through D flops before the producer sees it. A beat that arrives at the FIFO in cycle t was launched because the producer saw go high, and that go left the FIFO R = D + P cycles before t.

The textbook fix is an almost-full flag with a threshold of DEPTH minus R. Drop go when the count reaches the threshold, and the R beats still in flight fit in the space left. It works, but it reserves R entries every cycle, including the many cycles when nothing is in flight because go was already low. In a deep FIFO that is a modest waste. In a shallow one it is serious: if DEPTH is R or less, the threshold is zero or negative, and go never rises at all.
The interface
The read side is the familiar pop, rdata and empty. The write side has push and wdata, and the FIFO drives go instead of full. The contract is simple: the producer may launch a beat in any cycle in which it sees go high, after its D-cycle delay, and must launch nothing otherwise. The FIFO promises to accept every beat that arrives. There is no full output to obey at the FIFO end, because by the time a beat arrives it is too late to refuse it.
R is a parameter, and it must be the true round trip. It counts every flop on the go path and every stage on the data path, including any retiming flops that physical design adds later.
Micro-architecture: counting what is on its way
The FIFO knows its own history. It keeps a shift register of its last R go values and a counter win of how many of them were high. Each high bit in that window is a beat that may still arrive. A low bit is a cycle when the producer was told to stop, so nothing from that cycle can arrive.
The rule is then a budget. In each cycle, compute the next count and the next window. Raise go for the next cycle only if the next count, plus every beat that may still arrive, plus one more beat for this new go, fits in the FIFO:
go_next = (count_next + win_next + 1 <= DEPTH)
The invariant count + win <= DEPTH holds every cycle, which is exactly the statement that the FIFO can absorb everything in flight. The fixed threshold is the same rule with win replaced by R, its worst case.

The timing diagram below was produced by the same model used to check the RTL. With DEPTH 6, D of 1 and P of 2, go falls in cycle 7, three beats sent earlier still arrive, and the count stops at exactly 6. As soon as the consumer pops and the window is empty, go rises again, while a fixed threshold would wait until the count fell to 2.

If this looks like credit flow control from Part 11, it is. DEPTH - count - win is the number of credits the producer would hold. The difference is where the counter lives: here it stays at the FIFO, and the only thing that crosses the link is a single go bit.
RTL sketch
module predictive_af_fifo #(
parameter int W = 32,
parameter int DEPTH = 16, // any value
parameter int R = 4, // round trip D + P, at least 2
localparam int AW = $clog2(DEPTH),
localparam int CW = $clog2(DEPTH + R + 2)
) (
input logic clk,
input logic rst_n,
input logic push, // arrives R cycles after a go
input logic [W-1:0] wdata,
input logic pop,
output logic [W-1:0] rdata,
output logic empty,
output logic go // registered, sent back to the producer
);
logic [W-1:0] mem [DEPTH];
logic [AW-1:0] wptr, rptr;
logic [CW-1:0] count, win;
logic [R-1:0] hist; // hist[k]: go, k+1 cycles ago
assign empty = (count == 0);
wire do_pop = pop && !empty;
wire do_push = push; // room is guaranteed by the go rule
wire [CW-1:0] count_n = count + do_push - do_pop;
wire [CW-1:0] win_n = win - hist[R-1] + go;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin
wptr <= '0;
rptr <= '0;
count <= '0;
win <= '0;
hist <= '0;
go <= 1'b0;
end else begin
if (do_push) wptr <= (wptr == AW'(DEPTH - 1)) ? '0 : wptr + 1'b1;
if (do_pop) rptr <= (rptr == AW'(DEPTH - 1)) ? '0 : rptr + 1'b1;
count <= count_n;
win <= win_n;
hist <= {hist[R-2:0], go};
go <= (count_n + win_n + 1'b1 <= CW'(DEPTH));
end
always_ff @(posedge clk) begin
if (do_push) mem[wptr] <= wdata;
if (do_pop) rdata <= mem[rptr];
end
endmodule
The sketch was checked with a cycle-accurate Python model that includes the producer, its D-cycle view of go and the P-stage data pipe. Over 2.1 million cycles, at depths from 2 to 16 and round trips from 2 to 8, with steady, random and bursty consumers, no beat ever arrived at a full FIFO, every push matched a go from exactly R cycles earlier, and the data order matched a reference queue. A negative run with R set one cycle short overflowed within a few hundred cycles, as it should.
Corner cases
- DEPTH no larger than R. The fixed threshold never lets a beat through. The predictive rule still works, at reduced rate. With the timing in this sketch the full loop is R + 2 cycles, and in the model the throughput with an always-ready consumer was DEPTH divided by R + 2 until DEPTH reached R + 2, then one beat per cycle.
- A producer that does not use every go. The window counts go cycles, not beats sent, so an idle producer makes the FIFO reserve space it does not need. That is safe and wastes at most the beats of one round trip. Counting real beats would need information the FIFO does not have.
- Pops in flight. Never count on a future pop. A consumer that stalls in the next cycle would turn that optimism into an overflow.
- Reset.
goand the window reset to zero, so nothing is in flight. If the producer comes out of reset later than the FIFO, that is still safe; the reverse needs the producer to treatgoas low until it has seen a valid value. - R changes after layout. A flop added to the go path or the data path makes the real round trip longer than R, and the FIFO can overflow. Make R a parameter tied to the pipeline definition, and keep the overflow assertion in gate-level runs.
Timing, area and power
- Area. R flops of history and a small counter, against R entries of storage saved, or a FIFO that works at all below R entries. For any data width above a few bits, the predictive rule is cheaper than the storage it frees.
- Timing. The go rule is an add and a compare on next-state values. If that path is too long, compute the compare from registered count and window and add 1 to R. That costs one entry of headroom and keeps the logic short.
- Sizing. To run at one beat per cycle through stops and restarts, the FIFO must still hold at least one round trip of data. The predictive rule does not reduce that need. It makes better use of every entry above it, so the FIFO buffers more when the consumer is bursty.
- Power. Fewer stop and start cycles mean fewer pipeline bubbles and fewer toggles on the go path. The data path itself is unchanged.
Verification checklist
- Model the producer exactly: D flops on
go, P stages on the data path, and a random choice to launch or not when allowed. - Assertions:
a_no_overflow: assert property (@(posedge clk) disable iff (!rst_n) push |-> (count < DEPTH)); a_go_earlier: assert property (@(posedge clk) disable iff (!rst_n) push |-> hist[R-1]); a_budget: assert property (@(posedge clk) disable iff (!rst_n) count + win <= DEPTH); - A scoreboard on data order, and a test with R deliberately set one too small to prove the overflow assertion fires.
- Coverage: the count reaching exactly DEPTH, go rising while beats are still in flight, long consumer stalls, and DEPTH at or below R.
- Compare against a fixed threshold: average occupancy should be higher with the predictive rule for intermittent consumers, never lower.
Interview questions
1. The producer sees your stop signal three cycles late. Where do you set almost-full?
A strong answer counts the full round trip, including the data pipeline, not only the stop delay. It sets the threshold at DEPTH minus R and explains why a threshold one entry higher can overflow.
2. Your FIFO has 4 entries and the round trip is 5 cycles. What happens?
A strong answer sees that a fixed threshold never opens, and proposes counting the go cycles in flight instead, accepting a lower rate rather than a deadlock.
3. How is this related to credit-based flow control?
A strong answer shows that DEPTH minus count minus the window is the credit count, and compares a receiver-side counter with credits returned across the link.
4. Can you also count pops that are about to happen?
A strong answer says no, because a consumer can stall at any time, and only already-committed events can be used in the budget.
5. How would you verify the threshold?
A strong answer models the producer and both delays exactly, asserts no overflow and the go history, runs a negative test with a wrong R, and covers the FIFO filling to the last entry.
Where it is used in real chips
Almost-full with a latency budget appears wherever stop signals travel further than one cycle: NoC router input buffers fed across long wires, DMA engines writing into deep pipelines, PCIe and AXI bridges with retiming stages between the source and the buffer, and accelerator datapaths where a load unit streams tiles through several pipeline stages into a staging FIFO.
The rest of the series
Part 35 changed the depth of a FIFO while it was running without losing order.
Part 37 lets entries complete in any order while they still retire in the order they were allocated.


Your comments will be moderated before it appears here.