[Mesa-dev] [PATCH A 08/15] nir/builder: Create sized helpers for unsized conversion opcodes
Jason Ekstrand
jason at jlekstrand.net
Fri Nov 9 03:45:09 UTC 2018
Because we need to know the size and we can't infer it from the source,
we add a suffixed builder helper for each possible destination size the
opcode supports.
---
src/compiler/nir/nir_builder.h | 18 +++++++++++++++---
src/compiler/nir/nir_builder_opcodes_h.py | 16 ++++++++++++++--
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 3271a480520..f79e0114cda 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -352,8 +352,9 @@ nir_imm_ivec4(nir_builder *build, int x, int y, int z, int w)
}
static inline nir_ssa_def *
-nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
- nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)
+nir_build_sized_alu(nir_builder *build, nir_op op, unsigned dest_bit_size,
+ nir_ssa_def *src0, nir_ssa_def *src1,
+ nir_ssa_def *src2, nir_ssa_def *src3)
{
const nir_op_info *op_info = &nir_op_infos[op];
nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
@@ -386,7 +387,8 @@ nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
/* Figure out the bitwidth based on the source bitwidth if the instruction
* is variable-width.
*/
- unsigned bit_size = nir_alu_type_get_type_size(op_info->output_type);
+ unsigned bit_size = dest_bit_size;
+ nir_alu_type_get_type_size(op_info->output_type);
if (bit_size == 0) {
for (unsigned i = 0; i < op_info->num_inputs; i++) {
unsigned src_bit_size = instr->src[i].src.ssa->bit_size;
@@ -425,6 +427,16 @@ nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
return &instr->dest.dest.ssa;
}
+static inline nir_ssa_def *
+nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
+ nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)
+{
+ const unsigned dest_bit_size =
+ nir_alu_type_get_type_size(nir_op_infos[op].output_type);
+ return nir_build_sized_alu(build, op, dest_bit_size,
+ src0, src1, src2, src3);
+}
+
#include "nir_builder_opcodes.h"
static inline nir_ssa_def *
diff --git a/src/compiler/nir/nir_builder_opcodes_h.py b/src/compiler/nir/nir_builder_opcodes_h.py
index e600093e9f6..b0e30d406fe 100644
--- a/src/compiler/nir/nir_builder_opcodes_h.py
+++ b/src/compiler/nir/nir_builder_opcodes_h.py
@@ -35,11 +35,22 @@ def src_list(num_srcs):
%>
% for name, opcode in sorted(opcodes.items()):
+% if opcode.is_unsized_conversion:
+% for bit_size in type_sizes(opcode.output_type):
+static inline nir_ssa_def *
+nir_${name}${bit_size}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
+{
+ return nir_build_sized_alu(build, nir_op_${name}, ${bit_size},
+ ${src_list(opcode.num_inputs)});
+}
+% endfor
+% else:
static inline nir_ssa_def *
nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
{
return nir_build_alu(build, nir_op_${name}, ${src_list(opcode.num_inputs)});
}
+% endif
% endfor
/* Generic builder for system values. */
@@ -65,8 +76,9 @@ nir_${name}(nir_builder *build)
#endif /* _NIR_BUILDER_OPCODES_ */"""
-from nir_opcodes import opcodes
+from nir_opcodes import opcodes, type_sizes
from nir_intrinsics import INTR_OPCODES
from mako.template import Template
-print(Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES))
+print(Template(template).render(opcodes=opcodes, type_sizes=type_sizes,
+ INTR_OPCODES=INTR_OPCODES))
--
2.19.1
More information about the mesa-dev
mailing list