diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-04-15 10:39:42 -0400 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2020-04-17 16:25:35 -0400 |
commit | d772bf01011fc41d14093892a46541dcb2b9b6db (patch) | |
tree | c8578bf59dcdf682eba207b734e9e2104b242872 /src/panfrost/bifrost | |
parent | aba7f09902f704819f0bc718a322793b265acd64 (diff) |
pan/bi: Try to reuse constants in ALU
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4615>
Diffstat (limited to 'src/panfrost/bifrost')
-rw-r--r-- | src/panfrost/bifrost/bifrost_compile.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index adddef794ef..9671a485c2a 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -483,9 +483,18 @@ bi_copy_src(bi_instruction *alu, nir_alu_instr *instr, unsigned i, unsigned to, /* 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; + uint64_t mask = (1ull << dest_bits) - 1; + uint64_t cons = nir_src_as_uint(instr->src[i].src); + + /* Try to reuse a constant */ + for (unsigned i = 0; i < (*constant_shift); i += dest_bits) { + if (((alu->constant.u64 >> i) & mask) == cons) { + alu->src[to] = BIR_INDEX_CONSTANT | i; + return; + } + } + alu->constant.u64 |= cons << *constant_shift; alu->src[to] = BIR_INDEX_CONSTANT | (*constant_shift); --(*constants_left); (*constant_shift) += dest_bits; |