CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Find First One Priority Encoder

HardVerilog / SystemVerilogBuild

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 WIDTH value.
  • valid must be 0 and first_one must be 0 when req is all zeros.
  • Priority is strictly given to the least significant bit (index 0 has highest priority).

Topics

ParameterizedCombinationalPriority EncoderArbitration

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.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks