From: Luke Kenneth Casson Leighton Date: Mon, 17 Aug 2020 11:10:51 +0000 (+0100) Subject: add Mask class X-Git-Tag: 24jan2021_ls180~29 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8c7ddaf9d2c92266628cfc46a5ce01d70c08ff9f;p=nmutil.git add Mask class --- 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 +