power_insn: sort opcodes by sections
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 09:29:55 +0000 (12:29 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 15 Jan 2023 19:47:22 +0000 (22:47 +0300)
src/openpower/decoder/isa/caller.py
src/openpower/decoder/power_insn.py
src/openpower/sv/trans/pysvp64dis.py
src/openpower/sv/trans/svp64.py

index accce0c2b2e5f664e20c1de01b28497b41284793..5faa41fe2c20b97909c78bc1f031593ee331ed93 100644 (file)
@@ -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)
index 4c51a09b0051f67166a062c0036b6010a82cf250..3a756d26e24865ed2b91e72c9dbffadb9c2a36c6 100644 (file)
@@ -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")
index 03de5435cd66afb669636a6a2ea38ed6dfe4ccc8..3722af0961a8043e6c10cd49078b89883586e2e9 100644 (file)
@@ -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:
index 12bef488a6c1ff12a22ccc5dea2a2103bb251345..d3aaa2ebba9a74d8d7a6fc14635c499432585357 100644 (file)
@@ -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