From ecc40620715a996e57d3777f4a7cdeb2ad74697d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 27 Jun 2013 12:56:57 -0600 Subject: [PATCH] genlib/coding.py: binary vs. one-hot, priority coding --- migen/genlib/coding.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 migen/genlib/coding.py 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<