Find First One Priority Encoder
High-performance arbiters and interrupt controllers rely on priority encoders to rapidly identify the highest-priority request among multiple contenders. When multiple devices assert their request lines simultaneously, the hardware must deterministically select exactly one to grant access.
The module computes the binary index of the least significant bit that is set to 1 in a parameterized request vector. It outputs this index alongside a valid flag indicating whether any bit was set. If the input vector is entirely zeros, the valid flag must be de-asserted and the index output must default to zero. The circuit must evaluate completely within a single clock cycle without inferring any state elements.
| Parameter/Port | Direction | Width | Description | |----------------|-----------|-------|-------------| | WIDTH | parameter | integer | Width of the input vector; defaults to 16 | | req | input | WIDTH | Request input vector | | first_one | output | $clog2(WIDTH) | Binary index of the lowest set bit; 0 if req is 0 | | valid | output | 1 | Asserted to 1 if at least one bit in req is 1; otherwise 0 |
Constraints
- Purely combinational logic; no latches or flip-flops may be inferred.
- The module must correctly handle any parameterized
WIDTHvalue. validmust be 0 andfirst_onemust be 0 whenreqis all zeros.- Priority is strictly given to the least significant bit (index 0 has highest priority).
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.