RTL Design #26 · 2026-10-19 · Priority encoders · Easy · about 10 min
Lowest request wins
ffs is a find-first-set block for eight request lines. idx is the index of the lowest-numbered bit of req that is 1, and valid is 1 whenever any bit of req is set. With no request, valid is 0 and idx is 0. It's purely combinational.
For example, req = 8'b0001_0100 gives idx = 2 and valid = 1.
The current version doesn't report the right bit for some inputs, and valid is wrong for some too. Fix ffs.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.