Why you need this in addition to empty
A consumer that only reacts to empty finds out it has run dry at the worst possible moment — the exact cycle it needed data. Many real consumers (a display pipeline reading from a line buffer, a streaming DSP core, a network transmit FIFO feeding a MAC) need advance warning that the well is running low so they can trigger a refill, raise an interrupt, or throttle their own output before they actually starve. almost_empty provides that low-water-mark warning.
This is the mirror image of the almost-full FIFO problem in this track — same underlying occupancy counter, opposite threshold comparison — but it’s worth building both explicitly since real designs frequently need one without the other (e.g. a write-only ingress FIFO cares only about almost_full; a read-only prefetch buffer cares only about almost_empty).
Interface
| Signal | Direction | Description |
|---|---|---|
ALMOST_EMPTY_THRESHOLD |
parameter | Occupancy at or below which almost_empty should assert. |
wr_en / wr_data |
input | Write port, same semantics as the basic Synchronous FIFO. |
rd_en / rd_data |
input/output | Read port, same fall-through semantics as the basic Synchronous FIFO. |
full |
output | High when the FIFO holds exactly DEPTH entries. |
empty |
output | High when the FIFO holds zero entries. |
almost_empty |
output | High when occupancy <= ALMOST_EMPTY_THRESHOLD. |
Correctness constraints
almost_emptymust assert whenever occupancy is at or belowALMOST_EMPTY_THRESHOLD, including the fully-empty case (emptyimpliesalmost_empty).- A completely full FIFO (occupancy
== DEPTH) must never reportalmost_empty, unlessALMOST_EMPTY_THRESHOLD >= DEPTH(a degenerate configuration that should be avoided). 0 <= ALMOST_EMPTY_THRESHOLD <= DEPTHmust hold.- The flag must be derived from registered occupancy state only, so it settles cleanly every cycle without depending combinationally on the current cycle’s
rd_en/wr_en. - All of the base Synchronous FIFO’s correctness constraints (no full+empty overlap, dropped writes while full, dropped reads while empty, strict ordering) still apply.