From 6ed726b8fc6210a41fe325591e1428d19f419108 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 2 Sep 2010 11:32:09 +0100 Subject: gallivm: Pass condition masks as an unsigned bitmask. Much more convenient than boolean arrays. --- src/gallium/auxiliary/gallivm/lp_bld_logic.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/gallium/auxiliary/gallivm/lp_bld_logic.c') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c index 7d7db3b0d9..db25981491 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c @@ -482,24 +482,30 @@ lp_build_select(struct lp_build_context *bld, } +/** + * Return mask ? a : b; + * + * mask is a TGSI_WRITEMASK_xxx. + */ LLVMValueRef lp_build_select_aos(struct lp_build_context *bld, + unsigned mask, LLVMValueRef a, - LLVMValueRef b, - const boolean cond[4]) + LLVMValueRef b) { const struct lp_type type = bld->type; const unsigned n = type.length; unsigned i, j; + assert((mask & ~0xf) == 0); assert(lp_check_value(type, a)); assert(lp_check_value(type, b)); if(a == b) return a; - if(cond[0] && cond[1] && cond[2] && cond[3]) + if((mask & 0xf) == 0xf) return a; - if(!cond[0] && !cond[1] && !cond[2] && !cond[3]) + if((mask & 0xf) == 0x0) return b; if(a == bld->undef || b == bld->undef) return bld->undef; @@ -522,7 +528,9 @@ lp_build_select_aos(struct lp_build_context *bld, for(j = 0; j < n; j += 4) for(i = 0; i < 4; ++i) - shuffles[j + i] = LLVMConstInt(elem_type, (cond[i] ? 0 : n) + j + i, 0); + shuffles[j + i] = LLVMConstInt(elem_type, + (mask & (1 << i) ? 0 : n) + j + i, + 0); return LLVMBuildShuffleVector(bld->builder, a, b, LLVMConstVector(shuffles, n), ""); } @@ -531,16 +539,17 @@ lp_build_select_aos(struct lp_build_context *bld, /* XXX: Unfortunately select of vectors do not work */ /* Use a select */ LLVMTypeRef elem_type = LLVMInt1Type(); - LLVMValueRef cond[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef cond_vec[LP_MAX_VECTOR_LENGTH]; for(j = 0; j < n; j += 4) for(i = 0; i < 4; ++i) - cond[j + i] = LLVMConstInt(elem_type, cond[i] ? 1 : 0, 0); + cond_vec[j + i] = LLVMConstInt(elem_type, + mask & (1 << i) ? 1 : 0, 0); - return LLVMBuildSelect(bld->builder, LLVMConstVector(cond, n), a, b, ""); + return LLVMBuildSelect(bld->builder, LLVMConstVector(cond_vec, n), a, b, ""); #else - LLVMValueRef mask = lp_build_const_mask_aos(type, cond); - return lp_build_select(bld, mask, a, b); + LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask); + return lp_build_select(bld, mask_vec, a, b); #endif } } -- cgit v1.2.3