{
bi_instr *I = rzalloc(b->shader, bi_instr);
I->op = BI_OPCODE_${opcode.replace('.', '_').upper()};
+
+% if ops[opcode]["variable_dests"]:
+ I->nr_dests = nr_dests;
+% else:
I->nr_dests = ${ops[opcode]["dests"]};
- I->nr_srcs = ${src_count(ops[opcode])};
% for dest in range(ops[opcode]["dests"]):
I->dest[${dest}] = dest${dest};
% endfor
+%endif
+
+% if ops[opcode]["variable_srcs"]:
+ I->nr_srcs = nr_srcs;
+% else:
+ I->nr_srcs = ${src_count(ops[opcode])};
% for src in range(src_count(ops[opcode])):
I->src[${src}] = src${src};
% endfor
+% endif
+
% for mod in ops[opcode]["modifiers"]:
% if not should_skip(mod, opcode):
I->${mod} = ${mod};
return I;
}
-% if ops[opcode]["dests"] == 1:
+% if ops[opcode]["dests"] == 1 and not ops[opcode]["variable_dests"]:
static inline
bi_index bi_${opcode.replace('.', '_').lower()}(${signature(ops[opcode], modifiers, no_dests=True)})
{
["bi_builder *b"] +
(["nir_alu_type type"] if typeful == True else []) +
(["unsigned bitsize"] if sized == True else []) +
- ["bi_index dest{}".format(i) for i in range(0 if no_dests else op["dests"])] +
- ["bi_index src{}".format(i) for i in range(src_count(op))] +
+ (["unsigned nr_dests"] if op["variable_dests"] else
+ ["bi_index dest{}".format(i) for i in range(0 if no_dests else op["dests"])]) +
+ (["unsigned nr_srcs"] if op["variable_srcs"] else
+ ["bi_index src{}".format(i) for i in range(src_count(op))]) +
["{} {}".format(
"bool" if len(modifiers[T[0:-1]] if T[-1] in "0123" else modifiers[T]) == 2 else
"enum bi_" + T[0:-1] if T[-1] in "0123" else
["uint32_t {}".format(imm) for imm in op["immediates"]])
def arguments(op, temp_dest = True):
- return ", ".join(
- ["b"] +
- ["bi_temp(b->shader)" if temp_dest else 'dest{}'.format(i) for i in range(op["dests"])] +
- ["src{}".format(i) for i in range(src_count(op))] +
- modifier_signature(op) +
- op["immediates"])
+ dest_pattern = "bi_temp(b->shader)" if temp_dest else 'dest{}'
+ dests = [dest_pattern.format(i) for i in range(op["dests"])]
+ srcs = ["src{}".format(i) for i in range(src_count(op))]
+
+ # Variable source/destinations just pass in the count
+ if op["variable_dests"]:
+ dests = ["nr_dests"]
+
+ if op["variable_srcs"]:
+ srcs = ["nr_srcs"]
+
+ return ", ".join(["b"] + dests + srcs + modifier_signature(op) + op["immediates"])
print(Template(COPYRIGHT + TEMPLATE).render(ops = ir_instructions, modifiers =
modifier_lists, signature = signature, arguments = arguments, src_count =
'staging': ins.attrib.get('staging', '').split('=')[0],
'staging_count': ins.attrib.get('staging', '=0').split('=')[1],
'dests': int(ins.attrib.get('dests', '1')),
+ 'variable_dests': ins.attrib.get('variable_dests', False),
+ 'variable_srcs': ins.attrib.get('variable_srcs', False),
'unused': ins.attrib.get('unused', False),
'pseudo': ins.attrib.get('pseudo', False),
'message': ins.attrib.get('message', 'none'),
'staging': ins['staging'],
'srcs': len(ins['srcs']),
'dests': ins['dests'],
+ 'variable_dests': ins['variable_dests'],
+ 'variable_srcs': ins['variable_srcs'],
'modifiers': [[m[0][0], m[2]] for m in ins['modifiers']],
'immediates': [m[0] for m in ins['immediates']]
}
'key': key,
'srcs': variants[0]['srcs'],
'dests': variants[0]['dests'],
+ 'variable_dests': variants[0]['variable_dests'],
+ 'variable_srcs': variants[0]['variable_srcs'],
'staging': variants[0]['staging'],
'immediates': sorted(variants[0]['immediates']),
'modifiers': modifiers,