nir: add a helper function for getting the number of source components
authorConnor Abbott <cwabbott0@gmail.com>
Sun, 25 Jan 2015 16:42:34 +0000 (11:42 -0500)
committerConnor Abbott <cwabbott0@gmail.com>
Tue, 27 Jan 2015 02:26:36 +0000 (21:26 -0500)
Unlike with non-SSA ALU instructions, where if they're per-component
you have to look at the writemask to know which source channels are
being used, SSA ALU instructions always have all the possible channels
enabled so we can just look at the number of components in the SSA
definition for per-component instructions to say how many source
components are being used.

v2: use new name nir_ssa_alu_instr_src_components()

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
Signed-off-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir.h

index 3fb9d3b5fbe372e215af72fb0da38d30b4784bc0..980fdd08f3353285ffa1c84cab75d45f9fb6c651 100644 (file)
@@ -652,6 +652,21 @@ nir_alu_instr_channel_used(nir_alu_instr *instr, unsigned src, unsigned channel)
    return (instr->dest.write_mask >> channel) & 1;
 }
 
+/*
+ * For instructions whose destinations are SSA, get the number of channels
+ * used for a source
+ */
+static inline unsigned
+nir_ssa_alu_instr_src_components(nir_alu_instr *instr, unsigned src)
+{
+   assert(instr->dest.dest.is_ssa);
+
+   if (nir_op_infos[instr->op].input_sizes[src] > 0)
+      return nir_op_infos[instr->op].input_sizes[src];
+
+   return instr->dest.dest.ssa.num_components;
+}
+
 typedef enum {
    nir_deref_type_var,
    nir_deref_type_array,