back.pysim: implement *.
authorwhitequark <whitequark@whitequark.org>
Tue, 18 Dec 2018 18:02:21 +0000 (18:02 +0000)
committerwhitequark <whitequark@whitequark.org>
Tue, 18 Dec 2018 18:02:21 +0000 (18:02 +0000)
nmigen/back/pysim.py
nmigen/test/test_sim.py

index d49ff41ec9afcc81cb57828fc24b333faa94d74b..206f19972109e66d80103024819f1e67f5525ff7 100644 (file)
@@ -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 == "|":
index 3294b6c855cc8f6f97efded5c8cc16eb017a641f..f91c932f9d0d0469277de96296e4e1a2d45e1811 100644 (file)
@@ -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))