forked from jiegec/unofficial-loongarch-intrinsics-guide
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_instr.py
47 lines (41 loc) · 1.76 KB
/
check_instr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import glob
# Update site directory before running: `poetry run mkdocs build`
for ext in ["lsx", "lasx"]:
encoding = {}
# find known insts from binutils-gdb
for line in open("../binutils-gdb/opcodes/loongarch-opc.c"):
line = line.strip()
if line.startswith("{") and line.endswith("},"):
parts = line.split(",")
if '"' in parts[2]:
name = parts[2].split('"')[1]
fmt = line.split('"')[3]
# convert fmt to our naming
encoded = []
for part in fmt.split(","):
if len(part) == 0:
continue
if part[0] == "x":
encoded.append("xr")
elif part[0] == "v":
encoded.append("vr")
elif part[0] == "r":
encoded.append("r")
elif part[0] == "c":
encoded.append("fcc")
elif part[0] == "u" or part[0] == "s":
encoded.append("imm")
encoding[name] = ", ".join(encoded)
# print(name, ", ".join(encoded))
# find documented intrinsics
for f in glob.glob(f"./site/{ext}/**/*.html", recursive=True):
# forgive me to use the simple but fragile way to parse html
for line in open(f, "r"):
if line.startswith("Instruction:"):
# check instruction format
inst = line[12:].strip()
name = inst.split(" ")[0]
fmt = encoding[name]
args = " ".join(inst.split(";")[0].split(" ")[1:])
if args != fmt:
print("Mismatch inst=", inst, ",args=", args, ",fmt=", fmt)