From 9d02f07d0690d7d1487e78601fd44ae0fe7ddbd1 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 6 Nov 2022 12:29:55 +0300 Subject: [PATCH] power_insn: support tables priorities --- openpower/isatables/insndb.csv | 26 ++++++++++++------------ src/openpower/decoder/power_insn.py | 31 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/openpower/isatables/insndb.csv b/openpower/isatables/insndb.csv index 80b483de..b8f8ad2f 100644 --- a/openpower/isatables/insndb.csv +++ b/openpower/isatables/insndb.csv @@ -1,13 +1,13 @@ -path,opcode,bitsel,suffix,mode -minor_19.csv,19,21:30,NONE,pattern -minor_30.csv,30,27:30,NONE,pattern -minor_31.csv,31,21:30,0b101,integer -minor_58.csv,58,30:31,NONE,integer -minor_62.csv,62,30:31,NONE,integer -minor_22.csv,22,21:31,NONE,pattern -minor_5.csv,5,21:31,NONE,pattern -minor_4.csv,4,26:31,NONE,integer -minor_63.csv,63,21:30,NONE,pattern -minor_59.csv,59,21:30,NONE,pattern -major.csv,NONE,0:5,NONE,integer -extra.csv,NONE,0:31,NONE,pattern +path,opcode,bitsel,suffix,mode,priority +minor_19.csv,19,21:30,NONE,pattern,normal +minor_30.csv,30,27:30,NONE,pattern,normal +minor_31.csv,31,21:30,0b101,integer,normal +minor_58.csv,58,30:31,NONE,integer,normal +minor_62.csv,62,30:31,NONE,integer,normal +minor_22.csv,22,21:31,NONE,pattern,normal +minor_5.csv,5,21:31,NONE,pattern,normal +minor_4.csv,4,26:31,NONE,integer,normal +minor_63.csv,63,21:30,NONE,pattern,normal +minor_59.csv,59,21:30,NONE,pattern,normal +major.csv,NONE,0:5,NONE,integer,normal +extra.csv,NONE,0:31,NONE,pattern,high diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index cc5d0e5c..1eabff03 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -62,6 +62,29 @@ class Verbosity(_enum.Enum): return (self.value < other.value) +@_functools.total_ordering +class Priority(_enum.Enum): + LOW = -1 + NORMAL = 0 + HIGH = +1 + + @classmethod + def _missing_(cls, value): + if isinstance(value, str): + value = value.upper() + try: + return cls[value] + except ValueError: + return super()._missing_(value) + + def __lt__(self, other): + if not isinstance(other, self.__class__): + return NotImplemented + + # NOTE: the order is inversed, LOW < NORMAL < HIGH + return (self.value > other.value) + + def dataclass(cls, record, keymap=None, typemap=None): if keymap is None: keymap = {} @@ -488,6 +511,12 @@ class Section: suffix: Suffix mode: Mode opcode: IntegerOpcode = None + priority: Priority = Priority.NORMAL + + def __lt__(self, other): + if not isinstance(other, self.__class__): + return NotImplemented + return (self.priority < other.priority) @classmethod def CSV(cls, record): @@ -2335,7 +2364,7 @@ class PPCDatabase: records = _collections.defaultdict(set) path = (root / "insndb.csv") with open(path, "r", encoding="UTF-8") as stream: - for section in parse(stream, Section.CSV): + for section in sorted(parse(stream, Section.CSV)): path = (root / section.path) opcode_cls = { section.Mode.INTEGER: IntegerOpcode, -- 2.30.2