Code conversion
The amaranth.lib.coding module provides building blocks for conversion between different encodings of binary numbers.
One-hot coding
- class amaranth.lib.coding.Encoder
Encode one-hot to binary.
If one bit in
iis asserted,nis low andoindicates the asserted bit. Otherwise,nis high andois0.- Parameters:
width (int) – Bit width of the input
- Attributes:
i (Signal(width), in) – One-hot input.
o (Signal(range(width)), out) – Encoded natural binary.
n (Signal, out) – Invalid: either none or multiple input bits are asserted.
- class amaranth.lib.coding.Decoder
Decode binary to one-hot.
If
nis low, only thei-th bit inois asserted. Ifnis high,ois0.- Parameters:
width (int) – Bit width of the output.
- Attributes:
i (Signal(range(width)), in) – Input binary.
o (Signal(width), out) – Decoded one-hot.
n (Signal, in) – Invalid, no output bits are to be asserted.
Priority coding
- class amaranth.lib.coding.PriorityEncoder
Priority encode requests to binary.
If any bit in
iis asserted,nis low andoindicates the least significant asserted bit. Otherwise,nis high andois0.- Parameters:
width (int) – Bit width of the input.
- Attributes:
i (Signal(width), in) – Input requests.
o (Signal(range(width)), out) – Encoded natural binary.
n (Signal, out) – Invalid: no input bits are asserted.