From a248ff0b5bf655546de7cae09aca677ca82a284a Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Fri, 21 Jan 2022 13:08:28 +0100 Subject: [PATCH] broadcom/compiler: support 8-bit loads via ldunifa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This generalizes the support we added for 16-bit to also handle 8-bit loads via ldunifa. The story is the same: we align the address to 32-bit downwards and we skip any bytes that are not of interest. Reviewed-by: Alejandro PiƱeiro Part-of: --- src/broadcom/compiler/nir_to_vir.c | 44 ++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index 11b5871994e..97804ccb844 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -3094,27 +3094,43 @@ ntq_emit_load_ubo_unifa(struct v3d_compile *c, nir_intrinsic_instr *instr) ntq_store_dest(c, &instr->dest, i, vir_MOV(c, data)); i++; } else { - assert(bit_size == 16); - assert(value_skips <= 1); - struct qreg tmp; + assert((bit_size == 16 && value_skips <= 1) || + (bit_size == 8 && value_skips <= 3)); - if (value_skips == 0) { - tmp = vir_AND(c, vir_MOV(c, data), - vir_uniform_ui(c, 0xffff)); - ntq_store_dest(c, &instr->dest, i, vir_MOV(c, tmp)); - i++; - } else { - value_skips--; + /* If we have any values to skip, shift to the first + * valid value in the ldunifa result. + */ + if (value_skips > 0) { + data = vir_SHR(c, data, + vir_uniform_ui(c, bit_size * + value_skips)); } - assert(value_skips == 0); + /* Check how many valid components we have discounting + * read components to skip. + */ + uint32_t valid_count = (32 / bit_size) - value_skips; + assert((bit_size == 16 && valid_count <= 2) || + (bit_size == 8 && valid_count <= 4)); + assert(valid_count > 0); - if (i < num_components) { - tmp = vir_SHR(c, data, vir_uniform_ui(c, 16)); + /* Process the valid components */ + do { + struct qreg tmp; + uint32_t mask = (1 << bit_size) - 1; + tmp = vir_AND(c, vir_MOV(c, data), + vir_uniform_ui(c, mask)); ntq_store_dest(c, &instr->dest, i, vir_MOV(c, tmp)); i++; - } + valid_count--; + + /* Shift to next component */ + if (i < num_components && valid_count > 0) { + data = vir_SHR(c, data, + vir_uniform_ui(c, bit_size)); + } + } while (i < num_components && valid_count > 0); } }