]>
git.proxmox.com Git - mirror_qemu.git/blob - target/hexagon/gen_helper_protos.py
4 ## Copyright(c) 2019-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_helper_prototype
39 def_helper_types_pair
= {
49 def gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
):
50 if hex_common
.is_pair(regid
):
51 f
.write(f
", {def_helper_types_pair[regtype]}")
52 elif hex_common
.is_single(regid
):
53 f
.write(f
", {def_helper_types[regtype]}")
55 hex_common
.bad_register(regtype
, regid
, toss
, numregs
)
59 ## Generate the DEF_HELPER prototype for an instruction
60 ## For A2_add: Rd32=add(Rs32,Rt32)
62 ## DEF_HELPER_3(A2_add, s32, env, s32, s32)
64 def gen_helper_prototype(f
, tag
, tagregs
, tagimms
):
70 numscalarreadwrite
= 0
71 for regtype
, regid
, toss
, numregs
in regs
:
72 if hex_common
.is_written(regid
):
74 if hex_common
.is_scalar_reg(regtype
):
76 if hex_common
.is_readwrite(regid
):
77 if hex_common
.is_scalar_reg(regtype
):
78 numscalarreadwrite
+= 1
80 if numscalarresults
> 1:
81 ## The helper is bogus when there is more than one result
82 f
.write(f
"DEF_HELPER_1({tag}, void, env)\n")
84 ## Figure out how many arguments the helper will take
85 if numscalarresults
== 0:
86 def_helper_size
= len(regs
) + len(imms
) + numscalarreadwrite
+ 1
87 if hex_common
.need_pkt_has_multi_cof(tag
):
89 if hex_common
.need_pkt_need_commit(tag
):
91 if hex_common
.need_part1(tag
):
93 if hex_common
.need_slot(tag
):
95 if hex_common
.need_PC(tag
):
97 if hex_common
.helper_needs_next_PC(tag
):
99 if hex_common
.need_condexec_reg(tag
, regs
):
101 f
.write(f
"DEF_HELPER_{def_helper_size}({tag}")
102 ## The return type is void
105 def_helper_size
= len(regs
) + len(imms
) + numscalarreadwrite
106 if hex_common
.need_pkt_has_multi_cof(tag
):
108 if hex_common
.need_pkt_need_commit(tag
):
110 if hex_common
.need_part1(tag
):
112 if hex_common
.need_slot(tag
):
114 if hex_common
.need_PC(tag
):
116 if hex_common
.need_condexec_reg(tag
, regs
):
118 if hex_common
.helper_needs_next_PC(tag
):
120 f
.write(f
"DEF_HELPER_{def_helper_size}({tag}")
122 ## Generate the qemu DEF_HELPER type for each result
123 ## Iterate over this list twice
124 ## - Emit the scalar result
125 ## - Emit the vector result
127 for regtype
, regid
, toss
, numregs
in regs
:
128 if hex_common
.is_written(regid
):
129 if not hex_common
.is_hvx_reg(regtype
):
130 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
133 ## Put the env between the outputs and inputs
138 for regtype
, regid
, toss
, numregs
in regs
:
139 if hex_common
.is_written(regid
):
140 if hex_common
.is_hvx_reg(regtype
):
141 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
144 ## For conditional instructions, we pass in the destination register
145 if "A_CONDEXEC" in hex_common
.attribdict
[tag
]:
146 for regtype
, regid
, toss
, numregs
in regs
:
147 if hex_common
.is_writeonly(regid
) and not hex_common
.is_hvx_reg(
150 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
153 ## Generate the qemu type for each input operand (regs and immediates)
154 for regtype
, regid
, toss
, numregs
in regs
:
155 if hex_common
.is_read(regid
):
156 if hex_common
.is_hvx_reg(regtype
) and hex_common
.is_readwrite(regid
):
158 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
160 for immlett
, bits
, immshift
in imms
:
163 ## Add the arguments for the instruction pkt_has_multi_cof,
164 ## pkt_needs_commit, PC, next_PC, slot, and part1 (if needed)
165 if hex_common
.need_pkt_has_multi_cof(tag
):
167 if hex_common
.need_pkt_need_commit(tag
):
169 if hex_common
.need_PC(tag
):
171 if hex_common
.helper_needs_next_PC(tag
):
173 if hex_common
.need_slot(tag
):
175 if hex_common
.need_part1(tag
):
181 hex_common
.read_semantics_file(sys
.argv
[1])
182 hex_common
.read_attribs_file(sys
.argv
[2])
183 hex_common
.read_overrides_file(sys
.argv
[3])
184 hex_common
.read_overrides_file(sys
.argv
[4])
185 ## Whether or not idef-parser is enabled is
186 ## determined by the number of arguments to
189 ## 5 args. -> not enabled,
190 ## 6 args. -> idef-parser enabled.
192 ## The 6:th arg. then holds a list of the successfully
193 ## parsed instructions.
194 is_idef_parser_enabled
= len(sys
.argv
) > 6
195 if is_idef_parser_enabled
:
196 hex_common
.read_idef_parser_enabled_file(sys
.argv
[5])
197 hex_common
.calculate_attribs()
198 tagregs
= hex_common
.get_tagregs()
199 tagimms
= hex_common
.get_tagimms()
201 output_file
= sys
.argv
[-1]
202 with
open(output_file
, "w") as f
:
203 for tag
in hex_common
.tags
:
204 ## Skip the priv instructions
205 if "A_PRIV" in hex_common
.attribdict
[tag
]:
207 ## Skip the guest instructions
208 if "A_GUEST" in hex_common
.attribdict
[tag
]:
210 ## Skip the diag instructions
213 if tag
== "Y6_diag0":
215 if tag
== "Y6_diag1":
218 if hex_common
.skip_qemu_helper(tag
):
220 if hex_common
.is_idef_parser_enabled(tag
):
223 gen_helper_prototype(f
, tag
, tagregs
, tagimms
)
226 if __name__
== "__main__":