3 # This script was committed on 20/11/2019 and it would probably make sense to remove
4 # it after the next release branches.
6 # This script is pipe based and converts an arm_neon.td (or arm_fp16.td) file
7 # using the old single-char type modifiers to an equivalent new-style form where
8 # each modifier is orthogonal and they can be composed.
10 # It was used to directly generate the .td files on main, so if you have any
11 # local additions I would suggest implementing any modifiers here, and running
12 # it over your entire pre-merge .td files rather than trying to resolve any
53 def typespec_elt_size(typespec
):
56 elif "s" in typespec
or "h" in typespec
:
58 elif "i" in typespec
or "f" in typespec
:
60 elif "l" in typespec
or "d" in typespec
:
66 def get_resize(cur
, desired
):
77 def remap_protocol(proto
, typespec
, name
):
80 # Conversions like to see the integer type so they know signedness.
84 and name
!= "vcvt_f32_f64"
85 and name
!= "vcvt_f64_f32"
88 default_width
= typespec_elt_size(typespec
)
89 inconsistent_width
= False
91 new_width
= typespec_elt_size(elt
)
92 if new_width
and new_width
!= default_width
:
93 inconsistent_width
= True
96 for i
, c
in enumerate(proto
):
97 # void and pointers make for bad discriminators in CGBuiltin.cpp.
103 elif inconsistent_width
:
104 # Otherwise it's a fixed output width modifier.
106 f
"warning: {name} uses fixed output size but has inconsistent input widths: {proto} {typespec}\n"
110 # y: scalar of half float
111 resize
= get_resize(default_width
, 16)
112 cur_mod
= f
"1F{resize}"
115 resize
= get_resize(default_width
, 32)
116 cur_mod
= f
"1F{resize}"
118 # o: scalar of double
119 resize
= get_resize(default_width
, 64)
120 cur_mod
= f
"1F{resize}"
122 # I: scalar of 32-bit signed
123 resize
= get_resize(default_width
, 32)
124 cur_mod
= f
"1S{resize}"
126 # L: scalar of 64-bit signed
127 resize
= get_resize(default_width
, 64)
128 cur_mod
= f
"1S{resize}"
130 # I: scalar of 32-bit unsigned
131 resize
= get_resize(default_width
, 32)
132 cur_mod
= f
"1U{resize}"
134 # O: scalar of 64-bit unsigned
135 resize
= get_resize(default_width
, 64)
136 cur_mod
= f
"1U{resize}"
138 # f: float (int args)
139 resize
= get_resize(default_width
, 32)
140 cur_mod
= f
"F{resize}"
142 # F: double (int args)
143 resize
= get_resize(default_width
, 64)
144 cur_mod
= f
"F{resize}"
147 resize
= get_resize(default_width
, 16)
148 cur_mod
= f
"F{resize}"
150 # 0: half (int args), ignore 'Q' size modifier.
151 resize
= get_resize(default_width
, 16)
152 cur_mod
= f
"Fq{resize}"
154 # 1: half (int args), force 'Q' size modifier.
155 resize
= get_resize(default_width
, 16)
156 cur_mod
= f
"FQ{resize}"
158 if len(cur_mod
) == 0:
159 raise Exception(f
"WTF: {c} in {name}")
161 if key_type
!= 0 and key_type
== i
:
164 if len(cur_mod
) == 1:
167 res
+= "(" + cur_mod
+ ")"
172 def replace_insts(m
):
173 start
, end
= m
.span("proto")
176 new_proto
= remap_protocol(m
["proto"], m
["kinds"], m
["name"])
177 return m
.group()[:start
] + new_proto
+ m
.group()[end
:]
180 INST
= re
.compile(r
'Inst<"(?P<name>.*?)",\s*"(?P<proto>.*?)",\s*"(?P<kinds>.*?)"')
182 new_td
= INST
.sub(replace_insts
, sys
.stdin
.read())
183 sys
.stdout
.write(new_td
)