4 ## Copyright(c) 2019-2024 rev.ng Labs Srl. 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/>.
23 from io
import StringIO
29 ## Generate code to be fed to the idef_parser
33 ## Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
37 ## A2_add(RdV, in RsV, in RtV) {
41 ## A2_add represents the instruction tag. Then we have a list of TCGv
42 ## that the code generated by the parser can expect in input. Some of
43 ## them are inputs ("in" prefix), while some others are outputs.
46 hex_common
.read_semantics_file(sys
.argv
[1])
47 hex_common
.calculate_attribs()
48 hex_common
.init_registers()
49 tagregs
= hex_common
.get_tagregs()
50 tagimms
= hex_common
.get_tagimms()
52 with
open(sys
.argv
[-1], "w") as f
:
53 f
.write('#include "macros.inc"\n\n')
55 for tag
in hex_common
.tags
:
56 ## Skip the priv instructions
57 if "A_PRIV" in hex_common
.attribdict
[tag
]:
59 ## Skip the guest instructions
60 if "A_GUEST" in hex_common
.attribdict
[tag
]:
62 ## Skip instructions that saturate in a ternary expression
63 if tag
in {"S2_asr_r_r_sat", "S2_asl_r_r_sat"}:
65 ## Skip instructions using switch
66 if tag
in {"S4_vrcrotate_acc", "S4_vrcrotate"}:
68 ## Skip trap instructions
69 if tag
in {"J2_trap0", "J2_trap1"}:
71 ## Skip 128-bit instructions
72 if tag
in {"A7_croundd_ri", "A7_croundd_rr"}:
85 ## Skip interleave/deinterleave instructions
86 if tag
in {"S2_interleave", "S2_deinterleave"}:
88 ## Skip instructions using bit reverse
99 ## Skip other unsupported instructions
100 if tag
== "S2_cabacdecbin" or tag
== "A5_ACS":
102 if tag
.startswith("Y"):
104 if tag
.startswith("V6_"):
106 if ( tag
.startswith("F") and
116 if tag
.endswith("_locked"):
118 if "A_COF" in hex_common
.attribdict
[tag
]:
120 if ( tag
.startswith('R6_release_') ):
122 ## Skip instructions that are incompatible with short-circuit
123 ## packet register writes
124 if ( tag
== 'S2_insert' or
125 tag
== 'S2_insert_rp' or
126 tag
== 'S2_asr_r_svw_trun' or
134 for regtype
, regid
in regs
:
135 reg
= hex_common
.get_register(tag
, regtype
, regid
)
136 prefix
= "in " if reg
.is_read() else ""
137 arguments
.append(f
"{prefix}{reg.reg_tcg()}")
139 for immlett
, bits
, immshift
in imms
:
140 arguments
.append(hex_common
.imm_name(immlett
))
142 f
.write(f
"{tag}({', '.join(arguments)}) {{\n")
144 if hex_common
.need_ea(tag
):
145 f
.write("size4u_t EA; ")
146 f
.write(f
"{hex_common.semdict[tag]}\n")
150 if __name__
== "__main__":