]>
git.proxmox.com Git - mirror_qemu.git/blob - target/hexagon/gen_analyze_funcs.py
4 ## Copyright(c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
26 ## Helpers for gen_analyze_func
28 def is_predicated(tag
):
29 return 'A_CONDEXEC' in hex_common
.attribdict
[tag
]
31 def analyze_opn_old(f
, tag
, regtype
, regid
, regno
):
32 regN
= "%s%sN" % (regtype
, regid
)
33 predicated
= "true" if is_predicated(tag
) else "false"
35 if (regid
in {"ss", "tt"}):
36 f
.write("// const int %s = insn->regno[%d];\n" % \
38 elif (regid
in {"dd", "ee", "xx", "yy"}):
39 f
.write(" const int %s = insn->regno[%d];\n" % (regN
, regno
))
40 f
.write(" ctx_log_reg_write_pair(ctx, %s, %s);\n" % \
42 elif (regid
in {"s", "t", "u", "v"}):
43 f
.write("// const int %s = insn->regno[%d];\n" % \
45 elif (regid
in {"d", "e", "x", "y"}):
46 f
.write(" const int %s = insn->regno[%d];\n" % (regN
, regno
))
47 f
.write(" ctx_log_reg_write(ctx, %s, %s);\n" % \
50 print("Bad register parse: ", regtype
, regid
)
51 elif (regtype
== "P"):
52 if (regid
in {"s", "t", "u", "v"}):
53 f
.write("// const int %s = insn->regno[%d];\n" % \
55 elif (regid
in {"d", "e", "x"}):
56 f
.write(" const int %s = insn->regno[%d];\n" % (regN
, regno
))
57 f
.write(" ctx_log_pred_write(ctx, %s);\n" % (regN
))
59 print("Bad register parse: ", regtype
, regid
)
60 elif (regtype
== "C"):
62 f
.write("// const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \
65 f
.write(" const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \
67 f
.write(" ctx_log_reg_write_pair(ctx, %s, %s);\n" % \
70 f
.write("// const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \
73 f
.write(" const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \
75 f
.write(" ctx_log_reg_write(ctx, %s, %s);\n" % \
78 print("Bad register parse: ", regtype
, regid
)
79 elif (regtype
== "M"):
81 f
.write("// const int %s = insn->regno[%d];\n"% \
84 print("Bad register parse: ", regtype
, regid
)
85 elif (regtype
== "V"):
86 if (regid
in {"dd", "xx"}):
87 f
.write("// const int %s = insn->regno[%d];\n" %\
89 elif (regid
in {"uu", "vv"}):
90 f
.write("// const int %s = insn->regno[%d];\n" % \
92 elif (regid
in {"s", "u", "v", "w"}):
93 f
.write("// const int %s = insn->regno[%d];\n" % \
95 elif (regid
in {"d", "x", "y"}):
96 f
.write("// const int %s = insn->regno[%d];\n" % \
99 print("Bad register parse: ", regtype
, regid
)
100 elif (regtype
== "Q"):
101 if (regid
in {"d", "e", "x"}):
102 f
.write("// const int %s = insn->regno[%d];\n" % \
104 elif (regid
in {"s", "t", "u", "v"}):
105 f
.write("// const int %s = insn->regno[%d];\n" % \
108 print("Bad register parse: ", regtype
, regid
)
109 elif (regtype
== "G"):
110 if (regid
in {"dd"}):
111 f
.write("// const int %s = insn->regno[%d];\n" % \
113 elif (regid
in {"d"}):
114 f
.write("// const int %s = insn->regno[%d];\n" % \
116 elif (regid
in {"ss"}):
117 f
.write("// const int %s = insn->regno[%d];\n" % \
119 elif (regid
in {"s"}):
120 f
.write("// const int %s = insn->regno[%d];\n" % \
123 print("Bad register parse: ", regtype
, regid
)
124 elif (regtype
== "S"):
125 if (regid
in {"dd"}):
126 f
.write("// const int %s = insn->regno[%d];\n" % \
128 elif (regid
in {"d"}):
129 f
.write("// const int %s = insn->regno[%d];\n" % \
131 elif (regid
in {"ss"}):
132 f
.write("// const int %s = insn->regno[%d];\n" % \
134 elif (regid
in {"s"}):
135 f
.write("// const int %s = insn->regno[%d];\n" % \
138 print("Bad register parse: ", regtype
, regid
)
140 print("Bad register parse: ", regtype
, regid
)
142 def analyze_opn_new(f
, tag
, regtype
, regid
, regno
):
143 regN
= "%s%sN" % (regtype
, regid
)
145 if (regid
in {"s", "t"}):
146 f
.write("// const int %s = insn->regno[%d];\n" % \
149 print("Bad register parse: ", regtype
, regid
)
150 elif (regtype
== "P"):
151 if (regid
in {"t", "u", "v"}):
152 f
.write("// const int %s = insn->regno[%d];\n" % \
155 print("Bad register parse: ", regtype
, regid
)
156 elif (regtype
== "O"):
158 f
.write("// const int %s = insn->regno[%d];\n" % \
161 print("Bad register parse: ", regtype
, regid
)
163 print("Bad register parse: ", regtype
, regid
)
165 def analyze_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
):
166 if (hex_common
.is_pair(regid
)):
167 analyze_opn_old(f
, tag
, regtype
, regid
, i
)
168 elif (hex_common
.is_single(regid
)):
169 if hex_common
.is_old_val(regtype
, regid
, tag
):
170 analyze_opn_old(f
,tag
, regtype
, regid
, i
)
171 elif hex_common
.is_new_val(regtype
, regid
, tag
):
172 analyze_opn_new(f
, tag
, regtype
, regid
, i
)
174 print("Bad register parse: ", regtype
, regid
, toss
, numregs
)
176 print("Bad register parse: ", regtype
, regid
, toss
, numregs
)
179 ## Generate the code to analyze the instruction
180 ## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
182 ## static void analyze_A2_add(DisasContext *ctx)
184 ## Insn *insn G_GNUC_UNUSED = ctx->insn;
185 ## const int RdN = insn->regno[0];
186 ## ctx_log_reg_write(ctx, RdN, false);
187 ## // const int RsN = insn->regno[1];
188 ## // const int RtN = insn->regno[2];
191 def gen_analyze_func(f
, tag
, regs
, imms
):
192 f
.write("static void analyze_%s(DisasContext *ctx)\n" %tag
)
195 f
.write(" Insn *insn G_GNUC_UNUSED = ctx->insn;\n")
198 ## Analyze all the registers
199 for regtype
, regid
, toss
, numregs
in regs
:
200 analyze_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
207 hex_common
.read_semantics_file(sys
.argv
[1])
208 hex_common
.read_attribs_file(sys
.argv
[2])
209 hex_common
.read_overrides_file(sys
.argv
[3])
210 hex_common
.read_overrides_file(sys
.argv
[4])
211 ## Whether or not idef-parser is enabled is
212 ## determined by the number of arguments to
215 ## 5 args. -> not enabled,
216 ## 6 args. -> idef-parser enabled.
218 ## The 6:th arg. then holds a list of the successfully
219 ## parsed instructions.
220 is_idef_parser_enabled
= len(sys
.argv
) > 6
221 if is_idef_parser_enabled
:
222 hex_common
.read_idef_parser_enabled_file(sys
.argv
[5])
223 hex_common
.calculate_attribs()
224 tagregs
= hex_common
.get_tagregs()
225 tagimms
= hex_common
.get_tagimms()
227 with
open(sys
.argv
[-1], 'w') as f
:
228 f
.write("#ifndef HEXAGON_TCG_FUNCS_H\n")
229 f
.write("#define HEXAGON_TCG_FUNCS_H\n\n")
231 for tag
in hex_common
.tags
:
232 gen_analyze_func(f
, tag
, tagregs
[tag
], tagimms
[tag
])
234 f
.write("#endif /* HEXAGON_TCG_FUNCS_H */\n")
236 if __name__
== "__main__":