Priority Encoder
A priority encoder outputs the index of the highest-priority active input, resolving the case where several inputs are asserted at once.
From Many Lines to a Number
A plain binary encoder assumes exactly one of its inputs is active and outputs that input's index. Real systems break that assumption: several requests can arrive together. A priority encoder handles this by defining a fixed ranking and outputting the index of the highest-ranked active input, ignoring the rest.
It typically also produces a valid (or 'any') output that is asserted when at least one input is active, distinguishing an all-zero index that means 'input 0' from one that means 'nothing requested'.
| i3 | i2 | i1 | i0 | out | v |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | xx | 0 |
| 0 | 0 | 0 | 1 | 00 | 1 |
| 0 | 0 | 1 | x | 01 | 1 |
| 0 | 1 | x | x | 10 | 1 |
| 1 | x | x | x | 11 | 1 |
How It Is Built
A common structure scans from the most significant input downward. Each output bit is a chain of logic that says 'this input is the winner only if no higher input is active.' A leading-zero counter is the same function in disguise: finding the position of the most significant set bit is a priority-encode of the bit vector.
- Resolves simultaneous requests by fixed rank
- Emits a valid flag to distinguish index 0 from no request
- Equivalent to leading-zero / leading-one detection
Where It Is Used
Interrupt controllers use a priority encoder to pick which of many pending interrupts the processor should service first. Bus arbiters use one to grant a shared resource to the highest-priority requester. Floating-point normalization uses leading-zero detection, a priority encode, to decide how far to shift a mantissa.
Naive priority encoders have delay proportional to the number of inputs because of the scan chain. Wide encoders use a tree structure to bring delay down to the logarithm of the input count, and can be made fairer by rotating the priority order over time so no requester starves.