RTL Design #58 · 2026-11-20 · FIFOs · Medium · about 25 min
A first-word-fall-through FIFO
Build a first-word-fall-through FIFO, fwft_fifo, in fwft.sv. Unlike a FIFO with a registered read port, the oldest word is already on rdata whenever the FIFO is not empty: you don't ask for it first. rd_en means "I have taken the word on rdata; move to the next one."
Requirements:
- Storage is
DEPTHwords ofWbits (DEPTHis a power of two, 4 by default). Words come out in the order they went in. - A write happens on a rising edge where
wr_enis 1 andfullis 0. A read happens on a rising edge whererd_enis 1 andemptyis 0. Otherwise the request is ignored. Both can happen on the same edge, each judged by thefullandemptyvalues in that cycle: with the FIFO full, a write alongside a read is ignored. fullandemptyare combinational functions of what the FIFO holds:fullis 1 exactly whenDEPTHwords are stored,emptyexactly when none are.- While
emptyis 0,rdatais the oldest stored word, in the same cycle, with no read needed. Whileemptyis 1,rdatais don't-care. rst_nis a synchronous, active-low reset that empties the FIFO.
Example, DEPTH = 4, starting empty:
| edge | wr_en / wdata | rd_en | state after the edge |
|---|---|---|---|
| 1 | 1 / 0x11 | 0 | empty 0, rdata 0x11 |
| 2 | 1 / 0x22 | 0 | rdata still 0x11 |
| 3 | 0 | 1 | rdata 0x22 (0x11 was consumed) |
| 4 | 0 | 1 | empty 1 |
Write and run your answer in the browser. The hidden tests check it, and it’s free.