From 9984ec67f2ee07c4c3295e787a3bb025f6c56def Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 5 Jul 2022 16:34:39 -0600 Subject: [PATCH] gallivm: simplify shuffling in emit_store_reg() The writemask can be implemented with just one llvm vector shuffle. Signed-off-by: Brian Paul Reviewed-by: Dave Airlie Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c index 425ee66..4e05b11 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c @@ -197,20 +197,18 @@ emit_store_reg(struct lp_build_nir_context *bld_base, LLVMValueRef cur = LLVMBuildLoad(gallivm->builder, reg_storage, ""); LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); - for (unsigned i = 0; i < 4; i++) { - if (writemask & (1 << i)) { - LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH] = { 0 }; - for (unsigned j = 0; j < 16; j++){ - if (j % 4 == i) - shuffles[j] = LLVMConstInt(i32t, 16 + j, 0); - else - shuffles[j] = LLVMConstInt(i32t, j, 0); - } - - cur = LLVMBuildShuffleVector(gallivm->builder, cur, dst[0], - LLVMConstVector(shuffles, 16), ""); + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + for (unsigned j = 0; j < 16; j++) { + unsigned comp = j % 4; + if (writemask & (1 << comp)) { + shuffles[j] = LLVMConstInt(i32t, 16 + j, 0); // new val + } else { + shuffles[j] = LLVMConstInt(i32t, j, 0); // cur val } } + cur = LLVMBuildShuffleVector(gallivm->builder, cur, dst[0], + LLVMConstVector(shuffles, 16), ""); + LLVMBuildStore(gallivm->builder, cur, reg_storage); } -- 2.7.4