RTL Design #45 · 2026-11-07 · Almost-full · Easy · about 10 min
An almost-full flag that warns one entry too late
fill_level in fill_level.sv tracks how many entries a downstream buffer holds. count goes up on an accepted push and down on an accepted pop (a push is accepted only while full is 0, a pop only while empty is 0).
almost_full is a backpressure warning to the source: it must be 1 exactly while AF or fewer of the DEPTH slots are still free — that is, while DEPTH - count <= AF. With the defaults DEPTH = 8 and AF = 2, it should already be high when count reaches 6.
The current design raises almost_full one level too late. Fix fill_level.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.