Implement cross product and abs opcode
authorZack Rusin <zack@tungstengraphics.com>
Tue, 23 Oct 2007 11:11:39 +0000 (07:11 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Wed, 24 Oct 2007 15:21:05 +0000 (11:21 -0400)
src/mesa/pipe/llvm/instructions.cpp
src/mesa/pipe/llvm/instructions.h
src/mesa/pipe/llvm/llvmtgsi.cpp

index 1c42a37c742b347deb5ace10761f53339297326a..78d26587247c63b1fd6ed6d1e0be1909f4b4ac9c 100644 (file)
@@ -657,6 +657,61 @@ llvm::Value * Instructions::slt(llvm::Value *in1, llvm::Value *in2)
    return vectorFromVals(x, y, z, w);
 }
 
+llvm::Value * Instructions::cross(llvm::Value *in1, llvm::Value *in2)
+{
+   ExtractElementInst *x1 = new ExtractElementInst(in1, unsigned(0),
+                                                   name("x1"),
+                                                   m_block);
+   ExtractElementInst *y1 = new ExtractElementInst(in1, unsigned(1),
+                                                   name("y1"),
+                                                   m_block);
+   ExtractElementInst *z1 = new ExtractElementInst(in1, unsigned(2),
+                                                   name("z1"),
+                                                   m_block);
+
+   ExtractElementInst *x2 = new ExtractElementInst(in2, unsigned(0),
+                                                   name("x2"),
+                                                   m_block);
+   ExtractElementInst *y2 = new ExtractElementInst(in2, unsigned(1),
+                                                   name("y2"),
+                                                   m_block);
+   ExtractElementInst *z2 = new ExtractElementInst(in2, unsigned(2),
+                                                   name("z2"),
+                                                   m_block);
+   Value *y1z2 = mul(y1, z2);
+   Value *z1y2 = mul(z1, y2);
+
+   Value *z1x2 = mul(z1, x2);
+   Value *x1z2 = mul(x1, z2);
+
+   Value *x1y2 = mul(x1, y2);
+   Value *y1x2 = mul(y1, x2);
+
+   return vectorFromVals(sub(y1z2, z1y2), sub(z1x2, x1z2), sub(x1y2, y1x2));
+}
+
+
+llvm::Value * Instructions::abs(llvm::Value *in)
+{
+   ExtractElementInst *x = new ExtractElementInst(in, unsigned(0),
+                                                  name("extractx"),
+                                                  m_block);
+   ExtractElementInst *y = new ExtractElementInst(in, unsigned(1),
+                                                  name("extracty"),
+                                                  m_block);
+   ExtractElementInst *z = new ExtractElementInst(in, unsigned(2),
+                                                  name("extractz"),
+                                                  m_block);
+   ExtractElementInst *w = new ExtractElementInst(in, unsigned(3),
+                                                  name("extractw"),
+                                                  m_block);
+   Value *xabs  = callFAbs(x);
+   Value *yabs  = callFAbs(y);
+   Value *zabs  = callFAbs(z);
+   Value *wabs  = callFAbs(w);
+   return vectorFromVals(xabs, yabs, zabs, wabs);
+}
+
 /*
 typedef __attribute__(( ocu_vector_type(4) )) float float4;
 
@@ -832,3 +887,5 @@ Constant* const_packed_14 = ConstantVector::get(VectorTy_2, const_packed_14_elem
    return func_lit;
 }
 
+
+
index 557ae3730baa8f10b8db2ef6e8cae0c28df6e0f7..f7bc4a5839ff254b9853505cf494f1929869bff3 100644 (file)
@@ -15,7 +15,9 @@ class Instructions
 public:
    Instructions(llvm::Module *mod, llvm::Function *func, llvm::BasicBlock *block);
 
+   llvm::Value *abs(llvm::Value *in1);
    llvm::Value *add(llvm::Value *in1, llvm::Value *in2);
+   llvm::Value *cross(llvm::Value *in1, llvm::Value *in2);
    llvm::Value *dp3(llvm::Value *in1, llvm::Value *in2);
    llvm::Value *dp4(llvm::Value *in1, llvm::Value *in2);
    llvm::Value *dph(llvm::Value *in1, llvm::Value *in2);
index 69d54bf9af241b8cddc9e443ef6a373e1bc7b739..8983f162972c396b0486575405879fd8fa1f468c 100644 (file)
@@ -306,11 +306,15 @@ translate_instruction(llvm::Module *module,
       out = instr->pow(inputs[0], inputs[1]);
    }
       break;
-   case TGSI_OPCODE_CROSSPRODUCT:
+   case TGSI_OPCODE_CROSSPRODUCT: {
+      out = instr->cross(inputs[0], inputs[1]);
+   }
       break;
    case TGSI_OPCODE_MULTIPLYMATRIX:
       break;
-   case TGSI_OPCODE_ABS:
+   case TGSI_OPCODE_ABS: {
+      out = instr->abs(inputs[0]);
+   }
       break;
    case TGSI_OPCODE_RCC:
       break;