From: Dmitry Selyutin Date: Sun, 6 Nov 2022 09:29:55 +0000 (+0300) Subject: power_insn: sort opcodes by sections X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5f5a440a7242626d183c2726b18fa10dcf96818b;p=openpower-isa.git power_insn: sort opcodes by sections --- diff --git a/src/openpower/decoder/isa/caller.py b/src/openpower/decoder/isa/caller.py index accce0c2..5faa41fe 100644 --- a/src/openpower/decoder/isa/caller.py +++ b/src/openpower/decoder/isa/caller.py @@ -1527,8 +1527,8 @@ class ISACaller(ISACallerHelper, ISAFPHelpers, StepLoop): opcode = yield self.dec2.dec.opcode_in opcode = SelectableInt(value=opcode, bits=32) pfx = SVP64Instruction.Prefix(opcode) - log("prefix test: opcode:", pfx.po, bin(pfx.po), pfx.id) - self.is_svp64_mode = bool((pfx.po == 0b000001) and (pfx.id == 0b11)) + log("prefix test: opcode:", pfx.PO, bin(pfx.PO), pfx.id) + self.is_svp64_mode = bool((pfx.PO == 0b000001) and (pfx.id == 0b11)) self.pc.update_nia(self.is_svp64_mode) # set SVP64 decode yield self.dec2.is_svp64_mode.eq(self.is_svp64_mode) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 4c51a09b..3a756d26 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -1352,7 +1352,7 @@ class Instruction(_Mapping): class WordInstruction(Instruction): _: _Field = range(0, 32) - po: _Field = range(0, 6) + PO: _Field = range(0, 6) @classmethod def assemble(cls, db, opcode, arguments): @@ -1439,7 +1439,7 @@ class PrefixedInstruction(Instruction): _: _Field = range(64) prefix: Prefix suffix: Suffix - po: Suffix.po + PO: Suffix.PO @classmethod def integer(cls, value, byteorder="little"): @@ -2489,7 +2489,8 @@ class Database: db = set() names = {} - opcodes = _collections.defaultdict(set) + opcodes = _collections.defaultdict( + lambda: _collections.defaultdict(set)) for (name, mdwn) in mdwndb: if name.startswith("sv."): @@ -2507,7 +2508,7 @@ class Database: PO = section.opcode if PO is None: PO = ppc[0].opcode - opcodes[PO.value].add(record) + opcodes[section][PO.value].add(record) self.__db = sorted(db) self.__names = dict(sorted(names.items())) @@ -2527,25 +2528,16 @@ class Database: @_functools.lru_cache(maxsize=None) def __getitem__(self, key): - # specific hunt for all "extra.csv" matches. TODO: separate db of extras - if isinstance(key, Instruction): - ki = int(key) - for k, records in self.__opcodes.items(): - for record in records: - if str(record.section.path).endswith("extra.csv"): - if record.match(key=ki): - return record - # now look by XO-match, first, which is much better sorted. - # not in major.csv (e.g. 17 which is in extra.csv) already done above - if isinstance(key, (int, Instruction)): - key = int(key) - XO = int(_SelectableInt(value=int(key), bits=32)[0:6]) - assert XO in self.__opcodes # should have been caught by extra.csv - for record in self.__opcodes[XO]: - if record.match(key=key): - return record - # hunt by string instead + if isinstance(key, WordInstruction): + PO = int(key.PO) + for (section, group) in self.__opcodes.items(): + for record in group[PO]: + if record.match(key=key): + return record + + return None + elif isinstance(key, str): return self.__names.get(key) - return None + raise ValueError("instruction or name expected") diff --git a/src/openpower/sv/trans/pysvp64dis.py b/src/openpower/sv/trans/pysvp64dis.py index 03de5435..3722af09 100644 --- a/src/openpower/sv/trans/pysvp64dis.py +++ b/src/openpower/sv/trans/pysvp64dis.py @@ -40,7 +40,7 @@ def load(ifile, byteorder=ByteOrder.LITTLE, **_): elif length < 4: raise IOError(insn) insn = _WordInstruction.integer(value=insn, byteorder=byteorder) - if insn.po == 0x1: + if insn.PO == 0x1: suffix = cpfile.read(4) length = len(suffix) if length == 0: diff --git a/src/openpower/sv/trans/svp64.py b/src/openpower/sv/trans/svp64.py index 12bef488..d3aaa2eb 100644 --- a/src/openpower/sv/trans/svp64.py +++ b/src/openpower/sv/trans/svp64.py @@ -1525,7 +1525,7 @@ class SVP64Asm: log() # update prefix PO and ID (aka PID) - svp64_prefix.po = 0x1 + svp64_prefix.PO = 0x1 svp64_prefix.id = 0b11 # fiinally yield the svp64 prefix and the thingy. v3.0b opcode