[Mesa-dev] [PATCH 4/5] nir: Make some helpers for copying ALU src/dests.
Jason Ekstrand
jason at jlekstrand.net
Wed Jan 21 20:17:20 PST 2015
On Wed, Jan 21, 2015 at 5:26 PM, Eric Anholt <eric at anholt.net> wrote:
> There aren't many users yet, but I wanted to do this from my scalarizing
> pass.
> ---
> src/glsl/nir/nir.c | 18 ++++++++++++++++++
> src/glsl/nir/nir.h | 5 ++++-
> src/glsl/nir/nir_lower_vec_to_movs.c | 7 ++-----
> src/glsl/nir/nir_opt_peephole_select.c | 5 +----
> 4 files changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
> index 16ad2da..e414df9 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, nir_alu_src *src, void *mem_ctx)
> +{
>
We already have nir_src_copy which returns a nir_src instead of taking a
pointer. TBH, I'm not sure which I prefer, but it would be good to be
consistent. Thoughts?
> + 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, 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 8dc5222..7f0aa36 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -569,7 +569,10 @@ typedef struct {
> unsigned write_mask : 4; /* ignored if dest.is_ssa is true */
> } nir_alu_dest;
>
> -#define OPCODE(name, num_inputs, output_size, output_type, \
> +void nir_alu_src_copy(nir_alu_src *dest, nir_alu_src *src, void *mem_ctx);
> +void nir_alu_dest_copy(nir_alu_dest *dest, nir_alu_dest *src, void
> *mem_ctx);
> +
> +#define OPCODE(name, num_inputs, output_size, output_type, \
>
Accidental whitespace change?
> 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 a3120b6..022889e 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 023fae5..a5ac11f 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);
> }
> --
> 2.1.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150121/3dabce7d/attachment.html>
More information about the mesa-dev
mailing list