gallivm: added lp_build_sum_vector()

This commit is contained in:
Brian Paul 2010-03-11 16:26:12 -07:00
parent c72a3b4f2f
commit 0b3bb6318e
2 changed files with 35 additions and 0 deletions

View file

@ -232,6 +232,37 @@ lp_build_add(struct lp_build_context *bld,
}
/** Return the sum of the elements of a */
LLVMValueRef
lp_build_sum_vector(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
LLVMValueRef index, res;
int i;
if (a == bld->zero)
return bld->zero;
if (a == bld->undef)
return bld->undef;
assert(type.length > 1);
assert(!bld->type.norm);
index = LLVMConstInt(LLVMInt32Type(), 0, 0);
res = LLVMBuildExtractElement(bld->builder, a, index, "");
for (i = 1; i < type.length; i++) {
index = LLVMConstInt(LLVMInt32Type(), i, 0);
res = LLVMBuildAdd(bld->builder, res,
LLVMBuildExtractElement(bld->builder, a, index, ""),
"");
}
return res;
}
/**
* Generate a - b
*/

View file

@ -56,6 +56,10 @@ lp_build_add(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b);
LLVMValueRef
lp_build_sum_vector(struct lp_build_context *bld,
LLVMValueRef a);
LLVMValueRef
lp_build_sub(struct lp_build_context *bld,
LLVMValueRef a,