From 2e4530aec74d2f1c2a745984fa00e7d0e7096a8c Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 17 Mar 2021 20:28:32 -0700 Subject: [PATCH] change csv opcode field to require 0b... prefix and opint=True --- src/soc/decoder/power_decoder.py | 33 ++++++++++++++-------- src/soc/decoder/test/test_power_decoder.py | 4 +-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/soc/decoder/power_decoder.py b/src/soc/decoder/power_decoder.py index 79dd7951..2b52cf5f 100644 --- a/src/soc/decoder/power_decoder.py +++ b/src/soc/decoder/power_decoder.py @@ -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, diff --git a/src/soc/decoder/test/test_power_decoder.py b/src/soc/decoder/test/test_power_decoder.py index 0a18c77b..682b0bf7 100644 --- a/src/soc/decoder/test/test_power_decoder.py +++ b/src/soc/decoder/test/test_power_decoder.py @@ -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__": -- 2.30.2