Priority Encoder
Medium · Combinational · SystemVerilog · VHDL
A premium problem. Subscribe to open it in the editor, run the testbench and see where your design lands.
Design a priority encoder that grants the three highest-priority requests out of sixteen.
Bit 15 of req has the highest priority and bit 0 the lowest. grant has a bit set for each of the three highest-priority set bits of req, or for every set bit when fewer than three are set, and no others. n_grants is the number of bits set in grant.
pos0, pos1 and pos2 are the positions of the granted bits, from highest priority to lowest. A position output with no grant behind it is don't care.
The module is combinational.
- Encoding
- Arbitration & flow control