~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/compiler/nir/nir_builder_opcodes_h.py

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
def needs_num_components(opcode):
35
35
   return "replicated" in opcode.name
 
36
 
 
37
def intrinsic_prefix(name):
 
38
   if name in build_prefixed_intrinsics:
 
39
      return 'nir_build'
 
40
   else:
 
41
      return 'nir'
36
42
%>
37
43
 
38
44
% for name, opcode in sorted(opcodes.items()):
56
62
% endfor
57
63
 
58
64
% for name, opcode in sorted(INTR_OPCODES.items()):
 
65
% if opcode.indices:
59
66
struct _nir_${name}_indices {
60
67
   int _; /* exists to avoid empty initializers */
61
68
% for index in opcode.indices:
62
69
   ${index.c_data_type} ${index.name};
63
70
% endfor
64
71
};
 
72
% endif
65
73
% endfor
66
74
 
67
75
<%
120
128
   % endif
121
129
   % if opcode.has_dest:
122
130
      % if opcode.dest_components == 0:
123
 
      nir_ssa_dest_init(&intrin->instr, &intrin->dest, intrin->num_components, ${get_intrinsic_bitsize(opcode)}, NULL);
 
131
      nir_ssa_dest_init(&intrin->instr, &intrin->dest, intrin->num_components, ${get_intrinsic_bitsize(opcode)});
124
132
      % else:
125
 
      nir_ssa_dest_init(&intrin->instr, &intrin->dest, ${opcode.dest_components}, ${get_intrinsic_bitsize(opcode)}, NULL);
 
133
      nir_ssa_dest_init(&intrin->instr, &intrin->dest, ${opcode.dest_components}, ${get_intrinsic_bitsize(opcode)});
126
134
      % endif
127
135
   % endif
128
136
   % for i in range(opcode.num_srcs):
155
163
% for name, opcode in sorted(INTR_OPCODES.items()):
156
164
% if opcode.indices:
157
165
#ifdef __cplusplus
158
 
#define nir_build_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
 
166
#define ${intrinsic_prefix(name)}_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
159
167
_nir_build_${name}(build${intrinsic_macro_list(opcode)}, _nir_${name}_indices{0, __VA_ARGS__})
160
168
#else
161
 
#define nir_build_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
 
169
#define ${intrinsic_prefix(name)}_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
162
170
_nir_build_${name}(build${intrinsic_macro_list(opcode)}, (struct _nir_${name}_indices){0, __VA_ARGS__})
163
171
#endif
164
172
% else:
165
 
#define nir_build_${name} _nir_build_${name}
 
173
#define nir_${name} _nir_build_${name}
166
174
% endif
 
175
% if name in build_prefixed_intrinsics:
167
176
#define nir_${name} nir_build_${name}
 
177
% endif
 
178
% endfor
 
179
 
 
180
% for name in ['flt', 'fge', 'feq', 'fneu']:
 
181
static inline nir_ssa_def *
 
182
nir_${name}_imm(nir_builder *build, nir_ssa_def *src1, double src2)
 
183
{
 
184
   return nir_${name}(build, src1, nir_imm_floatN_t(build, src2, src1->bit_size));
 
185
}
 
186
% endfor
 
187
 
 
188
% for name in ['ilt', 'ige', 'ieq', 'ine', 'ult', 'uge']:
 
189
static inline nir_ssa_def *
 
190
nir_${name}_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
 
191
{
 
192
   return nir_${name}(build, src1, nir_imm_intN_t(build, src2, src1->bit_size));
 
193
}
 
194
% endfor
 
195
 
 
196
% for prefix in ['i', 'u']:
 
197
static inline nir_ssa_def *
 
198
nir_${prefix}gt_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
 
199
{
 
200
   return nir_${prefix}lt(build, nir_imm_intN_t(build, src2, src1->bit_size), src1);
 
201
}
 
202
 
 
203
static inline nir_ssa_def *
 
204
nir_${prefix}le_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
 
205
{
 
206
   return nir_${prefix}ge(build, nir_imm_intN_t(build, src2, src1->bit_size), src1);
 
207
}
168
208
% endfor
169
209
 
170
210
#endif /* _NIR_BUILDER_OPCODES_ */"""
173
213
from nir_intrinsics import INTR_OPCODES, WRITE_MASK, ALIGN_MUL
174
214
from mako.template import Template
175
215
 
 
216
# List of intrinsics that also need a nir_build_ prefixed factory macro.
 
217
build_prefixed_intrinsics = [
 
218
   "load_deref",
 
219
   "store_deref",
 
220
   "copy_deref",
 
221
   "memcpy_deref",
 
222
 
 
223
   "load_param",
 
224
 
 
225
   "load_global",
 
226
   "load_global_constant",
 
227
   "store_global",
 
228
 
 
229
   "load_reg",
 
230
   "store_reg",
 
231
 
 
232
   "deref_mode_is",
 
233
]
 
234
 
176
235
print(Template(template).render(opcodes=opcodes,
177
236
                                type_size=type_size,
178
237
                                type_base_type=type_base_type,
179
238
                                INTR_OPCODES=INTR_OPCODES,
180
239
                                WRITE_MASK=WRITE_MASK,
181
 
                                ALIGN_MUL=ALIGN_MUL))
 
240
                                ALIGN_MUL=ALIGN_MUL,
 
241
                                build_prefixed_intrinsics=build_prefixed_intrinsics))