From e5922c1737fee77d71556ad62b13420af3306321 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Wed, 17 Aug 2022 14:48:50 +0300 Subject: [PATCH] power_insn: fix opcode-based lookups --- src/openpower/decoder/power_insn.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 824aff14..bc2cecc0 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -618,17 +618,31 @@ class Database: def __iter__(self): yield from self.__items + @_functools.lru_cache(maxsize=None) def __contains__(self, key): if isinstance(key, int): return self.__opcodes.__contains__(key) + elif isinstance(key, int): + for (opcode, insn) in self.__opcodes.items(): + if ((opcode.value & opcode.mask) == + (key & opcode.mask)): + return True + return False elif isinstance(key, str): return self.__names.__contains__(key) else: raise KeyError(key) + @_functools.lru_cache(maxsize=None) def __getitem__(self, key): - if isinstance(key, int): + if isinstance(key, Opcode): return self.__opcodes.__getitem__(key) + elif isinstance(key, int): + for (opcode, insn) in self.__opcodes.items(): + if ((opcode.value & opcode.mask) == + (key & opcode.mask)): + return insn + raise KeyError(key) elif isinstance(key, str): return self.__names.__getitem__(key) else: -- 2.30.2