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
52 def typespec_elt_size(typespec
):
55 elif 's' in typespec
or 'h' in typespec
:
57 elif 'i' in typespec
or 'f' in typespec
:
59 elif 'l' in typespec
or 'd' in typespec
:
64 def get_resize(cur
, desired
):
75 def remap_protocol(proto
, typespec
, name
):
78 # Conversions like to see the integer type so they know signedness.
79 if 'vcvt' in name
and '_f' in name
and name
!= 'vcvt_f32_f64' and name
!= 'vcvt_f64_f32':
81 default_width
= typespec_elt_size(typespec
)
82 inconsistent_width
= False
84 new_width
= typespec_elt_size(elt
)
85 if new_width
and new_width
!= default_width
:
86 inconsistent_width
= True
89 for i
, c
in enumerate(proto
):
90 # void and pointers make for bad discriminators in CGBuiltin.cpp.
96 elif inconsistent_width
:
97 # Otherwise it's a fixed output width modifier.
98 sys
.stderr
.write(f
'warning: {name} uses fixed output size but has inconsistent input widths: {proto} {typespec}\n')
101 # y: scalar of half float
102 resize
= get_resize(default_width
, 16)
103 cur_mod
= f
'1F{resize}'
106 resize
= get_resize(default_width
, 32)
107 cur_mod
= f
'1F{resize}'
109 # o: scalar of double
110 resize
= get_resize(default_width
, 64)
111 cur_mod
= f
'1F{resize}'
113 # I: scalar of 32-bit signed
114 resize
= get_resize(default_width
, 32)
115 cur_mod
= f
'1S{resize}'
117 # L: scalar of 64-bit signed
118 resize
= get_resize(default_width
, 64)
119 cur_mod
= f
'1S{resize}'
121 # I: scalar of 32-bit unsigned
122 resize
= get_resize(default_width
, 32)
123 cur_mod
= f
'1U{resize}'
125 # O: scalar of 64-bit unsigned
126 resize
= get_resize(default_width
, 64)
127 cur_mod
= f
'1U{resize}'
129 # f: float (int args)
130 resize
= get_resize(default_width
, 32)
131 cur_mod
= f
'F{resize}'
133 # F: double (int args)
134 resize
= get_resize(default_width
, 64)
135 cur_mod
= f
'F{resize}'
138 resize
= get_resize(default_width
, 16)
139 cur_mod
= f
'F{resize}'
141 # 0: half (int args), ignore 'Q' size modifier.
142 resize
= get_resize(default_width
, 16)
143 cur_mod
= f
'Fq{resize}'
145 # 1: half (int args), force 'Q' size modifier.
146 resize
= get_resize(default_width
, 16)
147 cur_mod
= f
'FQ{resize}'
149 if len(cur_mod
) == 0:
150 raise Exception(f
'WTF: {c} in {name}')
152 if key_type
!= 0 and key_type
== i
:
155 if len(cur_mod
) == 1:
158 res
+= '(' + cur_mod
+ ')'
162 def replace_insts(m
):
163 start
, end
= m
.span('proto')
166 new_proto
= remap_protocol(m
['proto'], m
['kinds'], m
['name'])
167 return m
.group()[:start
] + new_proto
+ m
.group()[end
:]
169 INST
= re
.compile(r
'Inst<"(?P<name>.*?)",\s*"(?P<proto>.*?)",\s*"(?P<kinds>.*?)"')
171 new_td
= INST
.sub(replace_insts
, sys
.stdin
.read())
172 sys
.stdout
.write(new_td
)