From b30c718a576921d0306eb033b14d68f21f6ac6d7 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 12 Apr 2022 20:44:20 -0400 Subject: [PATCH] agx: Add helper to emit combines ...in such a way that subsequent extracts will be optimized. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 8f28382460c..fcd2d7f5cc7 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -82,6 +82,36 @@ agx_emit_extract(agx_builder *b, agx_index vec, unsigned channel) return agx_p_extract(b, vec, channel); } +static void +agx_cache_combine(agx_builder *b, agx_index dst, + agx_index s0, agx_index s1, agx_index s2, agx_index s3) +{ + /* Lifetime of a hash table entry has to be at least as long as the table */ + agx_index *channels = ralloc_array(b->shader, agx_index, 4); + + channels[0] = s0; + channels[1] = s1; + channels[2] = s2; + channels[3] = s3; + + _mesa_hash_table_u64_insert(b->shader->allocated_vec, agx_index_to_key(dst), + channels); +} + +/* + * Combine multiple scalars into a vector destination. This corresponds to + * p_combine, lowered to moves (a shuffle in general) after register allocation. + * + * To optimize vector extractions, we record the individual channels + */ +static agx_instr * +agx_emit_combine_to(agx_builder *b, agx_index dst, + agx_index s0, agx_index s1, agx_index s2, agx_index s3) +{ + agx_cache_combine(b, dst, s0, s1, s2, s3); + return agx_p_combine_to(b, dst, s0, s1, s2, s3); +} + static void agx_block_add_successor(agx_block *block, agx_block *successor) {