Computing Library › Digital Logic & Circuits
Digital Logic & Circuits

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'.

Kronos motion — three outputs
i3i2i1i0outv
0000xx0
0001001
001x011
01xx101
1xxx111

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.

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.