배울 내용

  • Encode the highest-priority active input into a binary code.
  • Distinguish a priority encoder from a plain encoder.
  • Read the priority truth table — multiple inputs active resolves to the highest one.
  • Write the priority Boolean expressions: each higher input masks lower ones.
  • Apply priority encoders in interrupt controllers and bus arbitration.

작동 원리

An encoder is the inverse of a decoder: it converts a one-hot input pattern into a binary code. A priority encoder handles the case where more than one input might be active — it returns the binary index of the highest-priority active input, ignoring lower-priority ones.

This 4-to-2 priority encoder takes 4 inputs (I0–I3, where I3 has highest priority) and produces a 2-bit output (Y1, Y0): - If I3 is active: output 11 (decimal 3) - Else if I2 is active: output 10 (decimal 2) - Else if I1 is active: output 01 (decimal 1) - Else if I0 is active: output 00 (decimal 0) - If all inactive: output 00 plus a separate "valid" bit goes low

A "valid" output (sometimes called V or GS — Group Select) signals whether any input was active. Without it, an output of 00 is ambiguous: it could mean I0 is active or it could mean none are.

Boolean expressions use priority masking: Y1 = I3 + I2 (high if either of the upper two inputs is active); Y0 = I3 + (¬I2 · I1) (high if I3 is active, OR if I1 is active and I2 isn't masking it).

진리표

X = don't care. The encoder picks the highest-numbered active input. V (valid) signals whether any input is active.

입력 출력
I3I2I1I0 Y1Y0V
0000 000 Nothing active — V=0, Y meaningless
0001 001 Only I0 — code 00, V=1
0010 011 Only I1 — code 01
0011 011 I1 wins over I0
0100 101 Only I2 — code 10
0111 101 I2 wins over I1, I0
1000 111 Only I3 — code 11
1111 111 I3 wins over all — highest priority

불 대수식

Y1=I3+I2Y_1 = I_3 + I_2

High bit of code: set if either of the upper two inputs is active.

Y0=I3+I2I1Y_0 = I_3 + \overline{I_2} \cdot I_1

Low bit: set if I3 is active, OR if I1 is active without I2 masking it.

V=I3+I2+I1+I0V = I_3 + I_2 + I_1 + I_0

Valid = OR of all inputs. Tells the consumer whether the encoded output is meaningful.

단계별로 시도해 보세요

위 임베드에서 입력을 설정한 후, 예상 결과를 읽고 직접 확인하세요.

  1. 1
    I3 = 0 I2 = 0 I1 = 0 I0 = 0
    예상: Y1Y0=00, V=0
    관찰 포인트: No inputs active — V is low. The output code is 00 but you ignore it because V=0.
  2. 2
    I3 = 0 I2 = 0 I1 = 0 I0 = 1
    예상: Y1Y0=00, V=1
    관찰 포인트: Only I0 → code 00 (= 0) and V=1. The encoder confirms valid output even though Y is all zeros.
  3. 3
    I3 = 0 I2 = 1 I1 = 1 I0 = 1
    예상: Y1Y0=10, V=1
    관찰 포인트: I0, I1, and I2 all active. I2 has the highest priority so the encoder outputs 10 (= 2). I0 and I1 are ignored.
  4. 4
    I3 = 1 I2 = 1 I1 = 1 I0 = 1
    예상: Y1Y0=11, V=1
    관찰 포인트: All inputs active → I3 wins, output 11. Priority encoders always tell you about the highest-numbered active input.

사용된 구성 요소

실제 응용 사례

Interrupt controllers. Multiple peripheral interrupts arrive simultaneously; a priority encoder picks the highest-priority one and presents its vector to the CPU. Crucial for pre-emptive scheduling.

Cache way replacement. When a cache evicts a line, a priority encoder selects which way to replace based on LRU bits or replacement policy.

Bus arbitration. Multiple bus masters request simultaneously; a priority encoder selects the highest-priority requester to grant the bus to.

Floating-point normalize. After arithmetic, the leading-1 detection of the mantissa uses a priority encoder to determine the shift count for normalization.

Resource allocation. Any "first available slot" search uses a priority encoder to find the lowest-numbered free resource quickly.

자주 묻는 질문

Why need a priority encoder instead of a plain encoder?
A plain encoder assumes exactly one input is high (one-hot input). If two inputs are high simultaneously, a plain encoder produces an undefined (or arbitrary) output. Priority encoders deterministically pick the highest, even with multiple active inputs.
What's the role of the V (valid) output?
Without V, an output of 00 is ambiguous — it could mean I0 is active or no inputs are active. V=1 confirms 'output is meaningful'; V=0 means 'ignore the encoded output.' Critical for systems that take action only on real input events.
How does this differ from picking the LSB-first instead of MSB-first?
Some priority encoders output the lowest-priority active input (LSB-first). The choice depends on the application — interrupt controllers usually pick highest-priority; resource allocators often pick lowest-numbered. This circuit is MSB-first.
How does the encoder behave with glitches?
If an input bus glitches during transition, the encoded output may briefly show the wrong value. Critical systems either register the encoder output to a flip-flop or require inputs to be stable for one or more clocks before sampling.
Where is this used in CPU interrupt handling?
Multiple interrupt-request lines (IRQ0–IRQ31, etc.) feed a priority encoder; the output is the active interrupt's vector index, used to look up the corresponding interrupt service routine. Hardware does this in nanoseconds — much faster than scanning in software.

학습 계속하기