gallivm: Add a lp_build_const_elem().
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 2 Jun 2010 15:00:40 +0000 (16:00 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 2 Jun 2010 15:00:40 +0000 (16:00 +0100)
src/gallium/auxiliary/gallivm/lp_bld_const.c
src/gallium/auxiliary/gallivm/lp_bld_const.h

index 031ce9d1a375390deebed743dee791d325f74227..e42ff31ac7aaf08204c8d70bfe42a9b35f41c665 100644 (file)
@@ -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
-lp_build_const_vec(struct lp_type type,
-                   double val)
+lp_build_const_elem(struct lp_type type,
+                    double val)
 {
    LLVMTypeRef elem_type = lp_build_elem_type(type);
-   LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
-   unsigned i;
-
-   assert(type.length <= LP_MAX_VECTOR_LENGTH);
+   LLVMValueRef elem;
 
    if(type.floating) {
-      elems[0] = LLVMConstReal(elem_type, val);
+      elem = LLVMConstReal(elem_type, val);
    }
    else {
       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 elems[0];
+   return elem;
+}
 
-   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);
+   }
 }
 
 
index 9ca2f0664ebe88f1bdf9607a403d2f227b0b4582..d46b9f882b0fa38ba8bc44aaa988337b7269a306 100644 (file)
@@ -84,6 +84,10 @@ LLVMValueRef
 lp_build_one(struct lp_type type);
 
 
+LLVMValueRef
+lp_build_const_elem(struct lp_type type,
+                    double val);
+
 LLVMValueRef
 lp_build_const_vec(struct lp_type type, double val);