diff --git a/migen/genlib/coding.py b/migen/genlib/coding.py new file mode 100644 index 000000000..559dab055 --- /dev/null +++ b/migen/genlib/coding.py @@ -0,0 +1,55 @@ +from migen.fhdl.std import * + +""" +Encoders and decoders between binary and one-hot representation + +i: input (binary or one-hot) +o: output (one-hot or binary) +n: "none" signal (in/out), binary value is invalid +""" + +class Encoder(Module): + def __init__(self, width): + self.i = Signal(width) # one-hot + self.o = Signal(max=width) # binary + self.n = Signal() # invalid: none or multiple + act = dict((1<