From 3ec78a17c9be6effa8e457c1a28bc93b74420d31 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 1 Sep 2022 15:55:39 +0300 Subject: [PATCH] power_insn: refactor name matching algorithm --- src/openpower/decoder/power_insn.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 9147446d..2ab2da11 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -839,14 +839,27 @@ class PPCDatabase: return super().__init__() def __getitem__(self, key): + def exact_match(key, record): + for name in record.names: + if name == key: + return True + + return False + + def Rc_match(key, record): + if not key.endswith("."): + return False + + if not record.rc is _RCOE.RC: + return False + + return exact_match(key[:-1], record) + for (section, records) in self.__db.items(): for record in records: - for name in record.names: - if ((key == name) or - ((record.rc is _RC.RC) and - key.endswith(".") and - name == key[:-1])): - return (section, record) + if (exact_match(key, record) or + Rc_match(key, record)): + return (section, record) return (None, None) -- 2.30.2