Code Conversion

The torii.lib.coding module provides building blocks for conversion between different encodings of binary numbers.

One-hot coding

class torii.lib.coding.Encoder(*args: Any, src_loc_at: int = 0, **kwargs: Any)

Encode one-hot to binary.

If one bit in i is asserted, n is low and o indicates the asserted bit. Otherwise, n is high and o is 0.

Parameters:

width (int) – Bit width of the input

Variables:
  • 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 torii.lib.coding.Decoder(*args: Any, src_loc_at: int = 0, **kwargs: Any)

Decode binary to one-hot.

If n is low, only the i-th bit in o is asserted. If n is high, o is 0.

Parameters:

width (int) – Bit width of the output.

Variables:
  • 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

torii.lib.coding.PriorityEncoder

alias of Encoder

torii.lib.coding.PriorityDecoder

alias of Decoder

Gray coding

torii.lib.coding.GrayEncoder

alias of Encoder

torii.lib.coding.GrayDecoder

alias of Decoder