From e391f9b0503e18ed3f9b9878e0ce6992cb590950 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 3 Sep 2022 17:33:46 +0100 Subject: [PATCH] add power_table.py start of creating markdown Appendix D tables --- src/openpower/decoder/power_table.py | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/openpower/decoder/power_table.py diff --git a/src/openpower/decoder/power_table.py b/src/openpower/decoder/power_table.py new file mode 100644 index 00000000..da35cdb8 --- /dev/null +++ b/src/openpower/decoder/power_table.py @@ -0,0 +1,58 @@ +import pathlib +from openpower.decoder.power_enums import find_wiki_dir +from openpower.decoder.power_insn import (Database, MarkdownDatabase, + FieldsDatabase, PPCDatabase, + IntegerOpcode, PatternOpcode, + parse, Section) +root = find_wiki_dir() +root = pathlib.Path(root) +mdwndb = MarkdownDatabase() +fieldsdb = FieldsDatabase() + +# create by-sections first. these will be the markdown tables +sections = {} +insns = {} +path = (root / "insndb.csv") +with open(path, "r", encoding="UTF-8") as stream: + for section in parse(stream, Section.CSV): + sections[str(section.path)] = section + insns[str(section.path)] = [] +for (name, section) in sections.items(): + print (name, section) + +# enumerate all instructions and drop them into sections +db = Database(root) +for insn in db: + insns[str(insn.section.path)].append(insn) + print (insn) + +def do_table(insns, section): + start, end = section.bitsel.start, section.bitsel.end + print ("start-end", start, end) + bitlen = end-start+1 + half = bitlen // 2 + xomask = ((1<>half) & uppermask + print (i, bin(lower), bin(upper)) + if lower not in table_entries: + table_entries[lower] = {} + table_entries[lower][upper] = i + # create an XO + key = i << start + print ("search", i, hex(key)) + # start hunting + for insn in insns: + opcode = insn.opcode + if not isinstance(opcode, list): + opcode = [opcode] + for op in opcode: + if ((op.value & op.mask & xomask) == (key & op.mask & xomask)): + print ("match", i, hex(key), insn.name) + +do_table(insns['minor_30.csv'], sections['minor_30.csv']) -- 2.30.2