diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-03-09 20:32:00 -0400 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-03-10 19:25:59 +0000 |
commit | 48e50efd5de7b9ad79f89ba5183a1f45214d501d (patch) | |
tree | e735e646ed214442a0e33aa3d7fc3f20744ef967 /src/panfrost/bifrost/bifrost_compile.c | |
parent | 929baf3f88d381313dce7883dfe827305ce55702 (diff) |
pan/bi: Allow inlining constants
This will allow us to optimize out the constant moves (although that
will require a DCE pass which has yet to be written).
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4139>
Diffstat (limited to 'src/panfrost/bifrost/bifrost_compile.c')
-rw-r--r-- | src/panfrost/bifrost/bifrost_compile.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 6a9c56b6dad..8068825b826 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -262,16 +262,36 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr) comp_mask); } + /* We inline constants as we go. This tracks how many constants have + * been inlined, since we're limited to 64-bits of constants per + * instruction */ + + unsigned dest_bits = nir_dest_bit_size(instr->dest.dest); + unsigned constants_left = (64 / dest_bits); + unsigned constant_shift = 0; + /* Copy sources */ unsigned num_inputs = nir_op_infos[instr->op].num_inputs; assert(num_inputs <= ARRAY_SIZE(alu.src)); for (unsigned i = 0; i < num_inputs; ++i) { - alu.src[i] = bir_src_index(&instr->src[i].src); - + unsigned bits = nir_src_bit_size(instr->src[i].src); alu.src_types[i] = nir_op_infos[instr->op].input_types[i] - | nir_src_bit_size(instr->src[i].src); + | bits; + + /* Try to inline a constant */ + if (nir_src_is_const(instr->src[i].src) && constants_left && (dest_bits == bits)) { + alu.constant.u64 |= + (nir_src_as_uint(instr->src[i].src)) << constant_shift; + + alu.src[i] = BIR_INDEX_CONSTANT | constant_shift; + --constants_left; + constant_shift += dest_bits; + continue; + } + + alu.src[i] = bir_src_index(&instr->src[i].src); /* We assert scalarization above */ alu.swizzle[i][0] = instr->src[i].swizzle[0]; |