diff options
author | Eric Anholt <[email protected]> | 2015-01-21 15:55:23 -0800 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2015-01-23 16:37:16 -0800 |
commit | b2001278169b1f943c0bb6edb2d6985348beab4a (patch) | |
tree | edfffead2b420b1a14aa4f1d5c7811129776843d /src/glsl | |
parent | 15063d2ad0945004ef387511d0c805bbe734bc5f (diff) |
nir: Make some helpers for copying ALU src/dests.
There aren't many users yet, but I wanted to do this from my scalarizing
pass.
v2: Constify the src arguments.
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/nir/nir.c | 18 | ||||
-rw-r--r-- | src/glsl/nir/nir.h | 4 | ||||
-rw-r--r-- | src/glsl/nir/nir_lower_vec_to_movs.c | 7 | ||||
-rw-r--r-- | src/glsl/nir/nir_opt_peephole_select.c | 5 |
4 files changed, 25 insertions, 9 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index 16ad2da945c..0f9bfd947cf 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -175,6 +175,24 @@ nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx) return ret; } +void +nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx) +{ + dest->src = nir_src_copy(src->src, mem_ctx); + dest->abs = src->abs; + dest->negate = src->negate; + for (unsigned i = 0; i < 4; i++) + dest->swizzle[i] = src->swizzle[i]; +} + +void +nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src, void *mem_ctx) +{ + dest->dest = nir_dest_copy(src->dest, mem_ctx); + dest->write_mask = src->write_mask; + dest->saturate = src->saturate; +} + static inline void block_add_pred(nir_block *block, nir_block *pred) { diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 15f8f465f19..b3e6dfab340 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -569,6 +569,10 @@ typedef struct { unsigned write_mask : 4; /* ignored if dest.is_ssa is true */ } nir_alu_dest; +void nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx); +void nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src, + void *mem_ctx); + #define OPCODE(name, num_inputs, output_size, output_type, \ input_sizes, input_types, algebraic_props) \ nir_op_##name, diff --git a/src/glsl/nir/nir_lower_vec_to_movs.c b/src/glsl/nir/nir_lower_vec_to_movs.c index a3120b66635..022889e8d6f 100644 --- a/src/glsl/nir/nir_lower_vec_to_movs.c +++ b/src/glsl/nir/nir_lower_vec_to_movs.c @@ -57,15 +57,12 @@ lower_vec_to_movs_block(nir_block *block, void *mem_ctx) assert(src_idx < nir_op_infos[vec->op].num_inputs); nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov); - mov->src[0].src = nir_src_copy(vec->src[src_idx].src, mem_ctx); - mov->src[0].negate = vec->src[src_idx].negate; - mov->src[0].abs = vec->src[src_idx].abs; + nir_alu_src_copy(&mov->src[0], &vec->src[src_idx], mem_ctx); /* We only care about the one swizzle */ mov->src[0].swizzle[i] = vec->src[src_idx].swizzle[0]; - mov->dest.dest = nir_dest_copy(vec->dest.dest, mem_ctx); - mov->dest.saturate = vec->dest.saturate; + nir_alu_dest_copy(&mov->dest, &vec->dest, mem_ctx); mov->dest.write_mask = (1u << i); nir_instr_insert_before(&vec->instr, &mov->instr); diff --git a/src/glsl/nir/nir_opt_peephole_select.c b/src/glsl/nir/nir_opt_peephole_select.c index 9f541fef19d..21bdd263bd5 100644 --- a/src/glsl/nir/nir_opt_peephole_select.c +++ b/src/glsl/nir/nir_opt_peephole_select.c @@ -154,10 +154,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state) assert(mov->instr.type == nir_instr_type_alu); assert(mov->op == nir_op_fmov || mov->op == nir_op_imov); - sel->src[idx].src = nir_src_copy(mov->src[0].src, state->mem_ctx); - sel->src[idx].negate = mov->src[0].negate; - sel->src[idx].abs = mov->src[0].abs; - memcpy(sel->src[idx].swizzle, mov->src[0].swizzle, 4); + nir_alu_src_copy(&sel->src[idx], &mov->src[0], state->mem_ctx); } else { sel->src[idx].src = nir_src_copy(src->src, state->mem_ctx); } |