diff options
author | José Fonseca <[email protected]> | 2010-09-02 11:32:09 +0100 |
---|---|---|
committer | José Fonseca <[email protected]> | 2010-09-05 10:17:51 +0100 |
commit | 6ed726b8fc6210a41fe325591e1428d19f419108 (patch) | |
tree | a8f6a8d64f8a43d4d4095783e16e57e62512ed99 | |
parent | 079763f74648fef051ee5b8f7d730f7fc1ba27d5 (diff) |
gallivm: Pass condition masks as an unsigned bitmask.
Much more convenient than boolean arrays.
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_const.c | 15 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_const.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_logic.c | 29 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_logic.h | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_swizzle.c | 15 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c | 5 |
6 files changed, 42 insertions, 28 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c index e42ff31ac7a..dd839c0bea5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -382,9 +382,12 @@ lp_build_const_aos(struct lp_type type, } +/** + * @param mask TGSI_WRITEMASK_xxx + */ LLVMValueRef lp_build_const_mask_aos(struct lp_type type, - const boolean cond[4]) + unsigned mask) { LLVMTypeRef elem_type = LLVMIntType(type.width); LLVMValueRef masks[LP_MAX_VECTOR_LENGTH]; @@ -392,9 +395,13 @@ lp_build_const_mask_aos(struct lp_type type, assert(type.length <= LP_MAX_VECTOR_LENGTH); - for(j = 0; j < type.length; j += 4) - for(i = 0; i < 4; ++i) - masks[j + i] = LLVMConstInt(elem_type, cond[i] ? ~0 : 0, 0); + for (j = 0; j < type.length; j += 4) { + for( i = 0; i < 4; ++i) { + masks[j + i] = LLVMConstInt(elem_type, + mask & (1 << i) ? ~0ULL : 0, + 1); + } + } return LLVMConstVector(masks, type.length); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 7ee8fff1407..6b1fc590c17 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -104,7 +104,7 @@ lp_build_const_aos(struct lp_type type, LLVMValueRef lp_build_const_mask_aos(struct lp_type type, - const boolean cond[4]); + unsigned mask); static INLINE LLVMValueRef diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c index 7d7db3b0d92..db259814914 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 } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h index 4e7b4c9938e..111daad9712 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h @@ -77,9 +77,9 @@ lp_build_select(struct lp_build_context *bld, LLVMValueRef lp_build_select_aos(struct lp_build_context *bld, + unsigned mask, LLVMValueRef a, - LLVMValueRef b, - const boolean cond[4]); + LLVMValueRef b); LLVMValueRef diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c index 20cf96ca669..fced983396c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c @@ -139,13 +139,10 @@ lp_build_broadcast_aos(struct lp_build_context *bld, { 1, -2}, {-1, -2} }; - boolean cond[4]; unsigned i; - memset(cond, 0, sizeof cond); - cond[channel] = 1; - - a = LLVMBuildAnd(bld->builder, a, lp_build_const_mask_aos(type, cond), ""); + a = LLVMBuildAnd(bld->builder, a, + lp_build_const_mask_aos(type, 1 << channel), ""); /* * Build a type where each element is an integer that cover the four @@ -282,7 +279,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld, */ LLVMValueRef res; struct lp_type type4; - boolean cond[4]; + unsigned cond = 0; unsigned chan; int shift; @@ -290,9 +287,11 @@ lp_build_swizzle_aos(struct lp_build_context *bld, * Start with a mixture of 1 and 0. */ for (chan = 0; chan < 4; ++chan) { - cond[chan] = swizzles[chan] == PIPE_SWIZZLE_ONE ? TRUE : FALSE; + if (swizzles[chan] == PIPE_SWIZZLE_ONE) { + cond |= 1 << chan; + } } - res = lp_build_select_aos(bld, bld->one, bld->zero, cond); + res = lp_build_select_aos(bld, cond, bld->one, bld->zero); /* * Build a type where each element is an integer that cover the four diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c index 09e98330571..e49d353b749 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c @@ -205,9 +205,8 @@ lp_build_blend_swizzle(struct lp_build_blend_aos_context *bld, } if (rgb != alpha) { - boolean cond[4] = {0, 0, 0, 0}; - cond[alpha_swizzle] = 1; - swizzled_rgb = lp_build_select_aos(&bld->base, alpha, swizzled_rgb, cond); + swizzled_rgb = lp_build_select_aos(&bld->base, 1 << alpha_swizzle, + alpha, swizzled_rgb); } return swizzled_rgb; |