From 4199674edd9b1801c4d3efd8aef7c1d74dd31c61 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 18 Dec 2018 18:02:21 +0000 Subject: [PATCH] back.pysim: implement *. --- nmigen/back/pysim.py | 2 ++ nmigen/test/test_sim.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index d49ff41..206f199 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -113,6 +113,8 @@ class _RHSValueCompiler(AbstractValueTransformer): return lambda state: normalize(lhs(state) + rhs(state), shape) if value.op == "-": return lambda state: normalize(lhs(state) - rhs(state), shape) + if value.op == "*": + return lambda state: normalize(lhs(state) * rhs(state), shape) if value.op == "&": return lambda state: normalize(lhs(state) & rhs(state), shape) if value.op == "|": diff --git a/nmigen/test/test_sim.py b/nmigen/test/test_sim.py index 3294b6c..f91c932 100644 --- a/nmigen/test/test_sim.py +++ b/nmigen/test/test_sim.py @@ -66,6 +66,12 @@ class SimulatorUnitTestCase(FHDLTestCase): self.assertStatement(stmt, [C(0, 4), C(1, 4)], C(-1, 4)) self.assertStatement(stmt, [C(0, 4), C(10, 4)], C(-10, 5)) + def test_mul(self): + stmt = lambda y, a, b: y.eq(a * b) + self.assertStatement(stmt, [C(2, 4), C(1, 4)], C(2, 8)) + self.assertStatement(stmt, [C(2, 4), C(2, 4)], C(4, 8)) + self.assertStatement(stmt, [C(7, 4), C(7, 4)], C(49, 8)) + def test_and(self): stmt = lambda y, a, b: y.eq(a & b) self.assertStatement(stmt, [C(0b1100, 4), C(0b1010, 4)], C(0b1000, 4)) -- 2.30.2