experimenting getting power decoder into shape
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 3 Mar 2020 18:41:35 +0000 (18:41 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 3 Mar 2020 18:41:35 +0000 (18:41 +0000)
src/decoder/power_decoder.py
src/decoder/test/test_power_decoder.py

index 148e1c37d283c925383bfd8643c231b444b392b3..39c7976dd6c38ef01ad6d53e85d86e67d3a2ddf6 100644 (file)
@@ -83,7 +83,7 @@ class PowerDecoder(Elaboratable):
 
         self.op = PowerOp()
         self.suffix = suffix
-        if suffix[1] - suffix[0] >= width:
+        if suffix is not None and suffix[1] - suffix[0] >= width:
             self.suffix = None
         self.width = width
 
@@ -93,9 +93,10 @@ class PowerDecoder(Elaboratable):
     def divide_opcodes(self):
         divided = {}
         mask = self.suffix_mask()
+        print ("mask", hex(mask))
         for row in self.opcodes:
             opcode = row['opcode']
-            if self.opint:
+            if self.opint and '-' not in opcode:
                 opcode = int(opcode, 0)
             key = opcode & mask >> (self.suffix[0])
             opcode = opcode >> self.suffix[1]
@@ -129,7 +130,7 @@ class PowerDecoder(Elaboratable):
             with m.Switch(self.opcode_in):
                 for row in self.opcodes:
                     opcode = row['opcode']
-                    if self.opint:
+                    if self.opint and '-' not in opcode:
                         opcode = int(opcode, 0)
                     if not row['unit']:
                         continue
index c0a82863871ea2ede96de6d0a8e484969e9c7503..925fd10e440d02dabcfe2c3da684306b4f3dc751 100644 (file)
@@ -80,6 +80,8 @@ class DecoderTestCase(FHDLTestCase):
 
     def generate_ilang(self, width, csvname, opint=True, suffix=None):
         prefix = os.path.splitext(csvname)[0]
+        if suffix:
+            prefix += ".%s" % str(suffix).replace(" ", "")[1:-1]
         dut = PowerDecoder(width, get_csv(csvname), opint, suffix=suffix)
         vl = rtlil.convert(dut, ports=dut.ports())
         with open("%s_decoder.il" % prefix, "w") as f:
@@ -89,9 +91,9 @@ class DecoderTestCase(FHDLTestCase):
         self.run_test(6, "major.csv")
         self.generate_ilang(6, "major.csv")
 
-    # def test_minor_19(self):
-    #     self.run_test(3, "minor_19.csv")
-    #     self.generate_ilang(3, "minor_19.csv")
+    #def test_minor_19(self):
+    #    self.run_test(10, "minor_19.csv", suffix=(0, 5))
+    #    self.generate_ilang(10, "minor_19.csv", suffix=(0, 5))
 
     def test_minor_30(self):
         self.run_test(4, "minor_30.csv")
@@ -100,10 +102,15 @@ class DecoderTestCase(FHDLTestCase):
     def test_minor_31(self):
         self.run_test(10, "minor_31.csv", suffix=(0, 5))
         self.generate_ilang(10, "minor_31.csv", suffix=(0, 5))
+        assert False
+
+    #def test_minor_31_prefix(self):
+    #    self.run_test(10, "minor_31.csv", suffix=(5, 10))
+    #    self.generate_ilang(10, "minor_31.csv", suffix=(5, 10))
 
     def test_extra(self):
-        self.run_test(32, "extra.csv", False)
-        self.generate_ilang(32, "extra.csv", False)
+        self.run_test(32, "extra.csv", opint=False)
+        self.generate_ilang(32, "extra.csv", opint=False)
 
 
 if __name__ == "__main__":