From 8c7ddaf9d2c92266628cfc46a5ce01d70c08ff9f Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 17 Aug 2020 12:10:51 +0100 Subject: [PATCH] add Mask class --- src/nmutil/mask.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/nmutil/mask.py diff --git a/src/nmutil/mask.py b/src/nmutil/mask.py new file mode 100644 index 0000000..a75d7e3 --- /dev/null +++ b/src/nmutil/mask.py @@ -0,0 +1,19 @@ +from nmigen import Module, Signal, Elaboratable +from nmigen.utils import log2_int + + +class Mask(Elaboratable): + def __init__(self, sz): + self.sz = sz + self.shift = Signal(log2_int(sz, False)) + self.mask = Signal(sz) + + def elaborate(self, platform): + m = Module() + + for i in range(self.sz): + with m.If(self.shift > i): + m.d.comb += self.mask[i].eq(1) + + return m + -- 2.30.2