Commit 952d188c authored by Jose Fonseca's avatar Jose Fonseca

gallivm: Add a lp_build_const_elem().

parent 21a6bf86
...@@ -280,34 +280,45 @@ lp_build_one(struct lp_type type) ...@@ -280,34 +280,45 @@ lp_build_one(struct lp_type type)
/** /**
* Build constant-valued vector from a scalar value. * Build constant-valued element from a scalar value.
*/ */
LLVMValueRef LLVMValueRef
lp_build_const_vec(struct lp_type type, lp_build_const_elem(struct lp_type type,
double val) double val)
{ {
LLVMTypeRef elem_type = lp_build_elem_type(type); LLVMTypeRef elem_type = lp_build_elem_type(type);
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; LLVMValueRef elem;
unsigned i;
assert(type.length <= LP_MAX_VECTOR_LENGTH);
if(type.floating) { if(type.floating) {
elems[0] = LLVMConstReal(elem_type, val); elem = LLVMConstReal(elem_type, val);
} }
else { else {
double dscale = lp_const_scale(type); double dscale = lp_const_scale(type);
elems[0] = LLVMConstInt(elem_type, val*dscale + 0.5, 0); elem = LLVMConstInt(elem_type, val*dscale + 0.5, 0);
} }
if (type.length == 1) return elem;
return elems[0]; }
for(i = 1; i < type.length; ++i)
elems[i] = elems[0];
return LLVMConstVector(elems, type.length); /**
* Build constant-valued vector from a scalar value.
*/
LLVMValueRef
lp_build_const_vec(struct lp_type type,
double val)
{
if (type.length == 1) {
return lp_build_const_elem(type, val);
} else {
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
elems[0] = lp_build_const_elem(type, val);
for(i = 1; i < type.length; ++i)
elems[i] = elems[0];
return LLVMConstVector(elems, type.length);
}
} }
......
...@@ -84,6 +84,10 @@ LLVMValueRef ...@@ -84,6 +84,10 @@ LLVMValueRef
lp_build_one(struct lp_type type); lp_build_one(struct lp_type type);
LLVMValueRef
lp_build_const_elem(struct lp_type type,
double val);
LLVMValueRef LLVMValueRef
lp_build_const_vec(struct lp_type type, double val); lp_build_const_vec(struct lp_type type, double val);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment