"""
def __init__(self, width):
self.i = Signal(width) # one-hot
- self.o = Signal(max=width) # binary
+ self.o = Signal(max=max(2, width)) # binary
self.n = Signal() # invalid: none or multiple
act = dict((1<<j, self.o.eq(j)) for j in range(width))
act["default"] = self.n.eq(1)
"""
def __init__(self, width):
self.i = Signal(width) # one-hot, lsb has priority
- self.o = Signal(max=width) # binary
+ self.o = Signal(max=max(2, width)) # binary
self.n = Signal() # none
for j in range(width)[::-1]: # last has priority
self.comb += If(self.i[j], self.o.eq(j))
"""
def __init__(self, width):
- self.i = Signal(max=width) # binary
+ self.i = Signal(max=max(2, width)) # binary
self.n = Signal() # none/invalid
self.o = Signal(width) # one-hot
act = dict((j, self.o.eq(1<<j)) for j in range(width))
else:
self.assertEqual(o, 1<<i)
self.run_with(cb, 256)
+
+class SmallPrioEncCase(SimCase, unittest.TestCase):
+ class TestBench(SimBench):
+ def __init__(self):
+ self.submodules.dut = PriorityEncoder(1)
+
+ def test_sizes(self):
+ self.assertEqual(flen(self.tb.dut.i), 1)
+ self.assertEqual(flen(self.tb.dut.o), 1)
+ self.assertEqual(flen(self.tb.dut.n), 1)
+
+ def test_run_sequence(self):
+ seq = list(range(1))
+ def cb(tb, tbp):
+ if seq:
+ tbp.dut.i = seq.pop(0)
+ i = tbp.dut.i
+ if tbp.dut.n:
+ self.assertEqual(i, 0)
+ else:
+ o = tbp.dut.o
+ if o > 0:
+ self.assertEqual(i & 1<<(o - 1), 0)
+ self.assertGreaterEqual(i, 1<<o)
+ self.run_with(cb, 5)