An undersized FIFO is a functional bug with a long fuse: it passes every short test and overflows on the first long burst in the system. Depth is therefore a signoff calculation, written in the design document with its inputs named, not a power-of-two guess. The three inputs are the burst length, the rate mismatch during the burst, and the synchroniser latency hiding recent reads and writes.
During a burst the writer outruns the reader and occupancy grows by the rate difference accumulated over the burst. On top of that, each side works from a stale view of the other pointer, so a few extra entries cover the in-flight synchroniser delay. Almost-flag margins for pipeline reaction time add further entries where the producer cannot stop instantly.
All numbers below are illustrative: a burst of B = 120 words, write rate twice the read rate, and a synchroniser and flag latency worth about 2 entries each way.
illustrative depth sizing, recomputed two ways (B = 120 words, fw:fr = 2:1)
method 1, rate difference:
accumulated = B x (1 - fr / fw) = 120 x (1 - 1/2) = 60 words
synchroniser margin = 4 entries (about 2 entries per direction for the synchroniser and flag latency)
total = 60 + 4 = 64 -> next power of two: 64
method 2, time based (same inputs, counting from the burst duration):
burst lasts 120 write cycles = 60 read cycles; reads remove 60 words
net stored = 120 - 60 = 60 words; plus 4 margin = 64 -> depth 64
both countings agree: 64 entriesInput | Where it comes from | If it is unknown |
|---|---|---|
Burst length B | The protocol or the producer's maximum burst | Measure the longest burst in system simulation; do not guess |
Rate ratio fw:fr | Clock frequencies and the producer/consumer duty cycles | Assume the worst supported combination |
Synchroniser margin | Synchroniser stages plus flag pipeline depth | Allow at least 2 entries per crossing direction |
Reviewers ask for the sizing calculation and its three inputs, then check the testbench covers the worst case: a full-length burst at the worst rate ratio with the consumer stalled at the start. A FIFO that is only ever tested half-full is not signed off.
Accumulated 80 x (1 - 1/4) = 60, plus 4 = 64 entries. Recompute by time: the burst lasts 80 write cycles = 20 read cycles, reads remove 20, net 60, plus 4 = 64. Both agree.