forked from Wren6991/Hazard3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultilib-gen-gen.py
More file actions
executable file
·75 lines (68 loc) · 1.98 KB
/
multilib-gen-gen.py
File metadata and controls
executable file
·75 lines (68 loc) · 1.98 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# Generate a multilib configure line for riscv-gnu-toolchain with useful
# combinations of extensions supported by both Hazard3 and mainline GCC
# (currently GCC 14). Use as:
# ./configure ... --with-multilib-generator="$(path/to/multilib-gen-gen.py)"
base = "rv32i"
abi = "-ilp32--"
options = [
"m",
"a",
"c",
"zba",
"zbb",
"zbc",
"zbs",
"zbkb",
"zbkx",
"zca",
"zcb",
"zcmp",
"zmmul"
]
# Do not build for LHS except when *all of* RHS is also present. This cuts
# down on the number of configurations. A leading "!" means antidependency,
# i.e. an incompatibility.
depends_on = {
"m": ["!zmmul" ],
"zmmul": ["!m" ],
"zbb": ["m", "zba", "zbs" ],
"zba": ["m", "zbb", "zbs" ],
"zbs": ["m", "zba", "zbb" ],
"zbkb": ["zbb" ],
"zbc": ["zba", "zbb", "zbs", "zbkb"],
"zbkx": ["zba", "zbb", "zbs", "zbkb"],
"zifencei": ["zicsr" ],
"c": ["!zca" ],
"zca": ["!c" ],
"zcb": ["zca" ],
"zcmp": ["zca", "zcb", ],
}
l = []
for i in range(2 ** len(options)):
isa = base
violates_dependencies = False
for j in (j for j in range(len(options)) if i & (1 << j)):
opt = options[j]
if opt in depends_on:
for dep in depends_on[opt]:
inverted_dep = dep.startswith("!")
if inverted_dep: dep = dep[1:]
if inverted_dep == bool(i & (1 << options.index(dep))):
violates_dependencies = True
break
if violates_dependencies:
break
if len(opt) > 1:
isa += "_"
isa += opt
isa += "_zicsr_zifencei"
if not violates_dependencies:
l.append(isa + abi)
# Bonus RV32E configs:
l.append("rv32e_zicsr_zifencei-ilp32e--")
l.append("rv32ema_zicsr_zifencei-ilp32e--")
l.append("rv32emac_zicsr_zifencei-ilp32e--")
l.append("rv32ema_zicsr_zifencei_zba_zbb_zbc_zbkb_zbkx_zbs_zca_zcb_zcmp-ilp32e--")
print(";".join(l))
print(len(l))