power_insn: remove the whitespaces properly
[openpower-isa.git] / src / openpower / decoder / power_table.py
index 356c01643dcdac1671c45e56a5d2ef1e37fb7734..32f308669be48bd569b7e164661e8427c1d5e771 100644 (file)
@@ -47,43 +47,45 @@ def do_table(fname, insns, section, divpoint):
     # debug-print all opcodes first
     opcode_per_insn = {}
     for insn in insns:
-        #fields = []
-        #fields += [(insn.ppc.opcode.value, insn.ppc.bitsel)]
-        #opcode = FieldsOpcode(fields)
-        opcode = insn.ppc.opcode
-        if not isinstance(opcode, list):
-            opcode = [opcode]
-        for op in opcode:
+        opcodes = []
+        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)
         if insn.name not in opcode_per_insn:
             opcode_per_insn[insn.name] = []
-        opcode_per_insn[insn.name] += opcode
+        opcode_per_insn[insn.name] += opcodes
 
+    # along the way work out the maximum length of the instruction name
+    # that goes into the table.
     maxnamelen = 0
-    for i in range(1<<bitlen):
+
+    # for every possible XO value, work out the row and column as lower and
+    # upper halves, and if there is a opcode match put the instruction
+    # name into that XO table_entry
+
+    for XO in range(1<<bitlen):
         # calculate row, column
-        lower = i & lowermask
-        upper = (i>>half) & uppermask
-        print (i, bin(lower), bin(upper))
-        if upper not in table_entries:
+        lower = XO & lowermask
+        upper = (XO>>half) & uppermask
+        print ("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
-        # create an XO
-        key = i
-        print ("search", i, hex(key))
-        # start hunting
+        # hunt through all instructions, check XO against value/mask
         for insn in insns:
             opcode = opcode_per_insn[insn.name]
             for op in opcode:
-                #print ("    search", i, hex(key), insn.name,
+                #print ("    search", XO, hex(key), insn.name,
                 #                       hex(op.value), hex(op.mask))
-                if ((op.value & op.mask) == (key & op.mask)):
-                    print ("    match", i, hex(key), insn.name)
-                    assert (table_entries[upper][lower] is None,
-                            "entry %d %d should be empty "
+                if ((op.value & op.mask) == (XO & op.mask)):
+                    print ("    match", bin(XO), insn.name)
+                    assert table_entries[upper][lower] is None, \
+                            "entry %d %d (XO %s) should be empty "  \
                             "contains %s conflicting %s" % \
-                            (lower, upper, str(table_entries[upper][lower]),
-                             insn.name))
+                            (lower, upper, bin(XO),
+                             str(table_entries[upper][lower]),
+                             insn.name)
                     table_entries[upper][lower] = insn.name
                     maxnamelen = max(maxnamelen, len(insn.name))
                     continue
@@ -91,18 +93,21 @@ def do_table(fname, insns, section, divpoint):
     print (table_entries)
     # now got the table: print it out
 
+    # create the markdown header. first line: |   |00|01|10|11|   |
     table = []
-    line = [" "*half]
+    line = [" "*6]
     for j in range(1<<(half)):
         hdr = binmaxed(half, j)
         line.append(maxme(maxnamelen, hdr))
-    line.append(" "*half)
+    line.append(" "*6)
     table.append("|" + "|".join(line) + "|")
-    line = ["-"*half] + ["-"*maxnamelen] * (1<<(half)) + ["-"*half]
+    # 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(half, i)
+        hdr = binmaxed(6, i)
         line = [hdr]
         for j in range(1<<(half)):
             line.append(maxme(maxnamelen, table_entries[i][j] or " "))
@@ -112,4 +117,5 @@ def do_table(fname, insns, section, divpoint):
     print ("\n".join(table))
 
 do_table('minor_30.csv', insns, sections, divpoint=2)
+#do_table('minor_22.csv', insns, sections, divpoint=5)