summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-11-07 17:47:45 -0600
committerJason Ekstrand <[email protected]>2018-11-08 10:09:22 -0600
commit61e15348c435f0533b5b6b488ed353e16daa5f79 (patch)
tree1ee4636287dda312df43f404c1d127149e82ec7d /src/compiler
parent344cfe69809757be354fe129d7a849408c335dbe (diff)
nir: Add a read_mask helper for ALU instructions
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir.c8
-rw-r--r--src/compiler/nir/nir.h13
2 files changed, 14 insertions, 7 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 0be40d257f5..249b9357c3f 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1530,13 +1530,7 @@ nir_ssa_def_components_read(const nir_ssa_def *def)
nir_alu_src *alu_src = exec_node_data(nir_alu_src, use, src);
int src_idx = alu_src - &alu->src[0];
assert(src_idx >= 0 && src_idx < nir_op_infos[alu->op].num_inputs);
-
- for (unsigned c = 0; c < NIR_MAX_VEC_COMPONENTS; c++) {
- if (!nir_alu_instr_channel_used(alu, src_idx, c))
- continue;
-
- read_mask |= (1 << alu_src->swizzle[c]);
- }
+ read_mask |= nir_alu_instr_src_read_mask(alu, src_idx);
} else {
return (1 << def->num_components) - 1;
}
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index a0ae9a4430e..f4f6b106505 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -952,6 +952,19 @@ nir_alu_instr_channel_used(const nir_alu_instr *instr, unsigned src,
return (instr->dest.write_mask >> channel) & 1;
}
+static inline nir_component_mask_t
+nir_alu_instr_src_read_mask(const nir_alu_instr *instr, unsigned src)
+{
+ nir_component_mask_t read_mask = 0;
+ for (unsigned c = 0; c < NIR_MAX_VEC_COMPONENTS; c++) {
+ if (!nir_alu_instr_channel_used(instr, src, c))
+ continue;
+
+ read_mask |= (1 << instr->src[src].swizzle[c]);
+ }
+ return read_mask;
+}
+
/*
* For instructions whose destinations are SSA, get the number of channels
* used for a source