Cleanup constant vector handling a bit.
authorZack Rusin <zack@tungstengraphics.com>
Mon, 29 Oct 2007 17:42:58 +0000 (13:42 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Tue, 30 Oct 2007 09:15:06 +0000 (05:15 -0400)
src/mesa/pipe/llvm/instructions.cpp
src/mesa/pipe/llvm/instructions.h
src/mesa/pipe/llvm/storage.cpp

index 2eac0edbc4d61838bd4e4d919529e4e262fa56b7..3c68b764aa58b1caebe8e3cbbc6dc413176b1ef2 100644 (file)
@@ -466,12 +466,8 @@ llvm::Value * Instructions::lg2(llvm::Value *in)
    ExtractElementInst *w = new ExtractElementInst(in, unsigned(3),
                                                   name("extractw"),
                                                   m_block);
-   llvm::Value *const_vec = vectorFromVals(
-      ConstantFP::get(Type::FloatTy, APFloat(1.442695f)),
-      ConstantFP::get(Type::FloatTy, APFloat(1.442695f)),
-      ConstantFP::get(Type::FloatTy, APFloat(1.442695f)),
-      ConstantFP::get(Type::FloatTy, APFloat(1.442695f))
-      );
+   llvm::Value *const_vec = constVector(1.442695f, 1.442695f,
+                                        1.442695f, 1.442695f);
    return mul(vectorFromVals(callFLog(x), callFLog(y),
                              callFLog(z), callFLog(w)), const_vec);
 }
@@ -1016,14 +1012,7 @@ llvm::Value * Instructions::lerp(llvm::Value *in1, llvm::Value *in2,
                                  llvm::Value *in3)
 {
    llvm::Value *m = mul(in1, in2);
-   llvm::Value *vec1 = vectorFromVals(ConstantFP::get(Type::FloatTy,
-                                                      APFloat(1.f)),
-                                      ConstantFP::get(Type::FloatTy,
-                                                      APFloat(1.f)),
-                                      ConstantFP::get(Type::FloatTy,
-                                                      APFloat(1.f)),
-                                      ConstantFP::get(Type::FloatTy,
-                                                      APFloat(1.f)));
+   llvm::Value *vec1 = constVector(1.f, 1.f, 1.f, 1.f);
    llvm::Value *s = sub(vec1, in1);
    return add(m, mul(s, in3));
 }
@@ -1170,4 +1159,15 @@ llvm::Function * Instructions::findFunction(int label)
    return func;
 }
 
+llvm::Value * Instructions::constVector(float x, float y, float z, float w)
+{
+   std::vector<Constant*> vec(4);
+   vec[0] = ConstantFP::get(Type::FloatTy, APFloat(x));
+   vec[1] = ConstantFP::get(Type::FloatTy, APFloat(y));
+   vec[2] = ConstantFP::get(Type::FloatTy, APFloat(z));
+   vec[3] = ConstantFP::get(Type::FloatTy, APFloat(w));
+   return ConstantVector::get(m_floatVecType, vec);
+}
+
 #endif //MESA_LLVM
+
index 8a1aed31815ba07a79eddab19dbce5cb4417cdb5..b7b5129694795d8f11c9f5df3bd8bf5494db2ad6 100644 (file)
@@ -107,6 +107,8 @@ private:
    llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
                                llvm::Value *z, llvm::Value *w=0);
 
+   llvm::Value *constVector(float x, float y, float z, float w);
+
    llvm::Function *declarePrintf();
    llvm::Function *declareFunc(int label);
 
index 6ed243d9f3fcc7cdfce2a4a4beea1100798d5427..1715bd4de43ec7ab6de6635f9b76db42c4c6d227 100644 (file)
@@ -68,24 +68,12 @@ Storage::Storage(llvm::BasicBlock *block, llvm::Value *out,
 llvm::Constant *Storage::shuffleMask(int vec)
 {
    if (!m_extSwizzleVec) {
-      Constant *const_vec = Constant::getNullValue(m_floatVecType);
-      InsertElementInst *res = new InsertElementInst(const_vec,
-                                                     ConstantFP::get(Type::FloatTy, APFloat(0.f)),
-                                                     unsigned(0),
-                                                     name("extswx"), m_block);
-      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(1.f)),
-                                  unsigned(1),
-                                  name("extswy"),
-                                  m_block);
-      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(0.f)),
-                                  unsigned(2),
-                                  name("extswz"),
-                                  m_block);
-      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(1.f)),
-                                  unsigned(3),
-                                  name("extsww"),
-                                  m_block);
-      m_extSwizzleVec = res;
+      std::vector<Constant*> elems;
+      elems.push_back(ConstantFP::get(Type::FloatTy, APFloat(0.f)));
+      elems.push_back(ConstantFP::get(Type::FloatTy, APFloat(1.f)));
+      elems.push_back(ConstantFP::get(Type::FloatTy, APFloat(0.f)));
+      elems.push_back(ConstantFP::get(Type::FloatTy, APFloat(1.f)));
+      m_extSwizzleVec = ConstantVector::get(m_floatVecType, elems);
    }
 
    if (m_intVecs.find(vec) != m_intVecs.end()) {