summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2007-10-23 07:11:39 -0400
committerZack Rusin <zack@tungstengraphics.com>2007-10-24 11:21:05 -0400
commitba823b3ded1b6ec47b8a0e26ed08a229fe1a9140 (patch)
tree29bd5193e10add738748976d56fc499a3fe5fd17
parent1248b9776bfeec1f61962604b21212d2cf336283 (diff)
Implement cross product and abs opcode
-rw-r--r--src/mesa/pipe/llvm/instructions.cpp57
-rw-r--r--src/mesa/pipe/llvm/instructions.h2
-rw-r--r--src/mesa/pipe/llvm/llvmtgsi.cpp8
3 files changed, 65 insertions, 2 deletions
diff --git a/src/mesa/pipe/llvm/instructions.cpp b/src/mesa/pipe/llvm/instructions.cpp
index 1c42a37c74..78d2658724 100644
--- a/src/mesa/pipe/llvm/instructions.cpp
+++ b/src/mesa/pipe/llvm/instructions.cpp
@@ -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;
}
+
+
diff --git a/src/mesa/pipe/llvm/instructions.h b/src/mesa/pipe/llvm/instructions.h
index 557ae3730b..f7bc4a5839 100644
--- a/src/mesa/pipe/llvm/instructions.h
+++ b/src/mesa/pipe/llvm/instructions.h
@@ -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);
diff --git a/src/mesa/pipe/llvm/llvmtgsi.cpp b/src/mesa/pipe/llvm/llvmtgsi.cpp
index 69d54bf9af..8983f16297 100644
--- a/src/mesa/pipe/llvm/llvmtgsi.cpp
+++ b/src/mesa/pipe/llvm/llvmtgsi.cpp
@@ -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;