}
+/**
+ * @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];
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);
}
}
+/**
+ * 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;
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), "");
}
/* 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
}
}
{ 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
*/
LLVMValueRef res;
struct lp_type type4;
- boolean cond[4];
+ unsigned cond = 0;
unsigned chan;
int shift;
* 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