change csv opcode field to require 0b... prefix and opint=True
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 18 Mar 2021 03:28:32 +0000 (20:28 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 18 Mar 2021 03:28:32 +0000 (20:28 -0700)
src/soc/decoder/power_decoder.py
src/soc/decoder/test/test_power_decoder.py

index 79dd79518be18a680315091e4230eaac1cf3438c..2b52cf5fbc19f156a3020576e0fee59aabee27d5 100644 (file)
@@ -169,6 +169,23 @@ def get_pname(field, pname):
     return "%s_%s" % (pname, field)
 
 
+class PatternOpcode(str):
+    pass
+
+
+def parse_opcode(opcode, opint=True):
+    assert opint
+    if isinstance(opcode, (int, PatternOpcode)):
+        return opcode
+    assert isinstance(opcode, str)
+    assert opcode.startswith('0b')
+    if '-' not in opcode:
+        opcode = int(opcode, 0)
+    else:
+        opcode = PatternOpcode(opcode[2:])
+    return opcode
+
+
 class PowerOp:
     """PowerOp - a dynamic class that stores (subsets of) CSV rows of data
     about a PowerISA instruction.  this is a "micro-code" expanded format
@@ -316,9 +333,7 @@ class PowerDecoder(Elaboratable):
         mask = self.suffix_mask(d)
         print("mask", hex(mask))
         for row in d.opcodes:
-            opcode = row['opcode']
-            if d.opint and '-' not in opcode:
-                opcode = int(opcode, 0)
+            opcode = parse_opcode(row['opcode'], d.opint)
             key = opcode & mask
             opcode = opcode >> d.suffix
             if key not in divided:
@@ -354,7 +369,7 @@ class PowerDecoder(Elaboratable):
                     bitsel = (d.suffix+d.bitsel[0], d.bitsel[1])
                     sd = Subdecoder(pattern=None, opcodes=row,
                                     bitsel=bitsel, suffix=None,
-                                    opint=False, subdecoders=[])
+                                    opint=True, subdecoders=[])
                     mname = get_pname("dec_sub%d" % key, self.pname)
                     subdecoder = PowerDecoder(width=32, dec=sd,
                                               name=mname,
@@ -381,13 +396,7 @@ class PowerDecoder(Elaboratable):
                     case_does_something = True
                 eq += seqs
                 for row in d.opcodes:
-                    opcode = row['opcode']
-                    if d.opint:
-                        assert opcode.startswith('0b')
-                        if '-' not in opcode:
-                            opcode = int(opcode, 0)
-                        else:
-                            opcode = opcode[2:]
+                    opcode = parse_opcode(row['opcode'], d.opint)
                     if not row['unit']:
                         continue
                     if self.row_subsetfn:
@@ -571,7 +580,7 @@ def create_pdecode(name=None, col_subset=None, row_subset=None):
     dec.append(Subdecoder(pattern=None, opint=True, opcodes=opcodes,
                           bitsel=(26, 32), suffix=None, subdecoders=pminor))
     opcodes = get_csv("extra.csv")
-    dec.append(Subdecoder(pattern=None, opint=False, opcodes=opcodes,
+    dec.append(Subdecoder(pattern=None, opint=True, opcodes=opcodes,
                           bitsel=(0, 32), suffix=None, subdecoders=[]))
 
     return TopPowerDecoder(32, dec, name=name, col_subset=col_subset,
index 0a18c77bbe329cb0f28ece7bc826af9084acfbe0..682b0bf7b6e9c907b4f5ae97d3ca3845496a304c 100644 (file)
@@ -141,8 +141,8 @@ class DecoderTestCase(FHDLTestCase):
     # #    self.run_tst(10, "minor_31.csv", suffix=(5, 10))
 
     # def test_extra(self):
-    #     self.run_tst(32, "extra.csv", opint=False)
-    #     self.generate_ilang(32, "extra.csv", opint=False)
+    #     self.run_tst(32, "extra.csv", opint=True)
+    #     self.generate_ilang(32, "extra.csv", opint=True)
 
 
 if __name__ == "__main__":