2 from openpower
.decoder
.power_enums
import find_wiki_dir
3 from openpower
.decoder
.power_insn
import (Database
, MarkdownDatabase
,
4 FieldsDatabase
, PPCDatabase
,
5 IntegerOpcode
, PatternOpcode
,
8 root
= pathlib
.Path(root
)
9 mdwndb
= MarkdownDatabase()
10 fieldsdb
= FieldsDatabase()
12 # create by-sections first. these will be the markdown tables
15 path
= (root
/ "insndb.csv")
16 with
open(path
, "r", encoding
="UTF-8") as stream
:
17 for section
in parse(stream
, Section
.CSV
):
18 sections
[str(section
.path
)] = section
19 insns
[str(section
.path
)] = []
20 for (name
, section
) in sections
.items():
23 # enumerate all instructions and drop them into sections
26 insns
[str(insn
.section
.path
)].append(insn
)
29 def do_table(insns
, section
):
30 start
, end
= section
.bitsel
.start
, section
.bitsel
.end
31 print ("start-end", start
, end
)
34 lowermask
= (1<<half
)-1
35 uppermask
= (1<<(bitlen
-half
))-1
37 # debug-print all opcodes first
39 opcode
= insn
.section
.opcode
40 if not isinstance(opcode
, list):
43 print ("op", insn
.name
, op
)
45 for i
in range(1<<bitlen
):
46 # calculate row, column
48 upper
= (i
>>half
) & uppermask
49 print (i
, bin(lower
), bin(upper
))
50 if lower
not in table_entries
:
51 table_entries
[lower
] = {}
52 table_entries
[lower
][upper
] = i
54 key
= i
<< (31-end
) # MSB0-order shift up by *end*
55 print ("search", i
, hex(key
))
59 if not isinstance(opcode
, list):
62 if ((op
.value
& op
.mask
) == (key
& op
.mask
)):
63 print ("match", i
, hex(key
), insn
.name
)
65 do_table(insns
['minor_30.csv'], sections
['minor_30.csv'])