bug #672: invert testing in sv.minmax and add Rc=1
[openpower-isa.git] / src / openpower / decoder / power_table.py
index c1fa52a65d720fe53d329f777adcdb0e3432a129..008cb946ee01316d1b64b31d19217ada0ad9606b 100644 (file)
@@ -1,31 +1,17 @@
-import pathlib
+import collections
 from openpower.decoder.power_enums import find_wiki_dir 
-from openpower.decoder.power_insn import (Database, MarkdownDatabase,
-                                          FieldsDatabase, PPCDatabase,
-                                          IntegerOpcode, PatternOpcode,
-                                          parse, Section, BitSel,
-                                          FieldsOpcode)
-root = find_wiki_dir()
-root = pathlib.Path(root)
-mdwndb = MarkdownDatabase()
-fieldsdb = FieldsDatabase()
+from openpower.insndb.core import Database
+from openpower.util import log
 
-# 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)
+insns = collections.defaultdict(list)
 
-# enumerate all instructions and drop them into sections
-db = Database(root)
-for insn in db:
-    insns[str(insn.section.path)].append(insn)
-    print (insn)
+# create by-sections first. these will be the markdown tables
+# then enumerate all instructions and drop them into sections
+for insn in Database(find_wiki_dir()):
+    key = insn.section.path.name
+    sections[key] = insn.section
+    insns[key].append(insn)
 
 def maxme(num, s):
     return s.ljust(num)
@@ -38,7 +24,7 @@ def do_table(fname, insns, section, divpoint):
     insns = insns[fname]
     section = sections[fname]
     start, end = section.bitsel.start, section.bitsel.end
-    print ("start-end", start, end)
+    log("start-end", start, end)
     bitlen = end-start+1
     half = divpoint
     lowermask = (1<<half)-1
@@ -51,7 +37,7 @@ def do_table(fname, insns, section, divpoint):
         for op in insn.ppc: # insn.ppc is a MultiPPCRecord which is a tuple
             opcodes.append(op.opcode)
         for op in opcodes:
-            print ("op", insn.name, op)
+            log("op", insn.name, op)
         if insn.name not in opcode_per_insn:
             opcode_per_insn[insn.name] = []
         opcode_per_insn[insn.name] += opcodes
@@ -68,7 +54,7 @@ def do_table(fname, insns, section, divpoint):
         # calculate row, column
         lower = XO & lowermask
         upper = (XO>>half) & uppermask
-        print ("search", XO, bin(XO), bin(lower), bin(upper))
+        log("search", XO, bin(XO), bin(lower), bin(upper))
         if upper not in table_entries: # really should use defaultdict here
             table_entries[upper] = {}
         table_entries[upper][lower] = None
@@ -76,22 +62,24 @@ def do_table(fname, insns, section, divpoint):
         for insn in insns:
             opcode = opcode_per_insn[insn.name]
             for op in opcode:
-                #print ("    search", XO, hex(key), insn.name,
+                #log("    search", XO, hex(key), insn.name,
                 #                       hex(op.value), hex(op.mask))
                 if ((op.value & op.mask) == (XO & op.mask)):
-                    print ("    match", bin(XO), insn.name)
+                    log("    match", bin(XO), insn.name)
                     assert table_entries[upper][lower] is None, \
-                            "entry %d %d should be empty "  \
+                            "entry %d %d (XO %s) should be empty "  \
                             "contains %s conflicting %s" % \
-                            (lower, upper, str(table_entries[upper][lower]),
+                            (lower, upper, bin(XO),
+                             str(table_entries[upper][lower]),
                              insn.name)
                     table_entries[upper][lower] = insn.name
                     maxnamelen = max(maxnamelen, len(insn.name))
                     continue
 
-    print (table_entries)
+    log(table_entries)
     # now got the table: print it out
 
+    # create the markdown header. first line: |   |00|01|10|11|   |
     table = []
     line = [" "*6]
     for j in range(1<<(half)):
@@ -99,9 +87,11 @@ def do_table(fname, insns, section, divpoint):
         line.append(maxme(maxnamelen, hdr))
     line.append(" "*6)
     table.append("|" + "|".join(line) + "|")
+    # second line: |--|--|--|--|--|--|
     line = ["-"*6] + ["-"*maxnamelen] * (1<<(half)) + ["-"*6]
     table.append("|" + "|".join(line) + "|")
 
+    # now the rows, the row number goes into first and last column
     for i in range(1<<(bitlen-half)):
         hdr = binmaxed(6, i)
         line = [hdr]
@@ -110,8 +100,7 @@ def do_table(fname, insns, section, divpoint):
         line.append(hdr)
         table.append("|" + "|".join(line) + "|")
 
-    print ("\n".join(table))
+    print("\n".join(table))
 
 do_table('minor_30.csv', insns, sections, divpoint=2)
 #do_table('minor_22.csv', insns, sections, divpoint=5)
-