Synchronous FIFO (Show-Ahead)

Medium · Memories & FIFOs · Parameterization & Generate

Design a synchronous FIFO (first-in, first-out queue) with a single clock, in show-ahead (also called "first-word fall-through") style: whenever the FIFO is not empty, dout already shows the oldest entry, and pop removes it.

Parameters

ParameterDefaultMeaning
WIDTH8Data width in bits, WIDTH >= 1.
DEPTH8Number of entries: a power of two, DEPTH >= 2.

Your design must work for every legal combination: the hidden tests also instantiate it with non-default values, including the smallest legal ones. The examples use the defaults.

Ports

PortDirWidthMeaning
clkinput1Clock.
rstinput1Synchronous, active-high reset (takes effect only at a rising edge of clk).
pushinput1Write request: append din at the tail.
dininputWIDTHData to write.
popinput1Read request: remove the head entry.
doutoutputWIDTHThe head (oldest) entry, valid whenever empty = 0.
fulloutput11 when the FIFO holds DEPTH entries.
emptyoutput11 when the FIFO holds 0 entries.
countoutput$clog2(DEPTH)+1Number of entries, 0..DEPTH.

Behavior

All state changes happen at the rising edge of clk. At an edge with rst = 1, the FIFO becomes empty (count = 0, empty = 1, full = 0); stored data need not be cleared.

At an edge with rst = 0, let n be the number of entries before the edge:

pushpopConditionEffect
00nothing
10n < DEPTHdin is appended; n + 1 entries
10n == DEPTH (full)ignored (data is dropped, nothing changes)
01n > 0head entry removed; n − 1 entries
01n == 0 (empty)ignored
110 < nboth happen: the head is removed and din appended; still n entries. This includes the full case (n == DEPTH): a push is accepted when a pop frees a slot at the same edge.
11n == 0 (empty)the pop is ignored and the push happens: 1 entry, dout = din after the edge

Outputs depend only on the stored state: full, empty, count and (while the FIFO is not empty) dout reflect the FIFO contents after the most recent edge and must not depend combinationally on push, pop or din; they change only at a rising edge. In particular, after an edge that writes into an empty FIFO, dout shows that value immediately in the next cycle (no extra read latency), and after an edge that pops, dout shows the next entry. When empty = 1, the value of dout is not checked.

Example (DEPTH = 8)

edgepushdinpopcontents after the edge (head first)doutcountemptyfull
0 (rst)xxx––010
11A10A1A1100
21B20A1 B2A1200
31C31B2 C3B2200
40x1C3C3100
50x1––010
60x1– (ignored)–010
71D41D4 (pop ignored)D4100

Sign up free to solve Synchronous FIFO (Show-Ahead) in your browser.

More Memories & FIFOs problems