diff options
author | Zack Rusin <zack@pixel.(none)> | 2008-03-01 09:50:41 -0500 |
---|---|---|
committer | Zack Rusin <zack@tungstengraphics.com> | 2008-03-01 15:28:00 -0500 |
commit | a9c40f833ead8459788b86603c7f2b94632b1109 (patch) | |
tree | 5ee93b8bd49ff289f4b9fdf90dbcec8ac05e24d5 /src | |
parent | 17f543fc4529ca4ce7f73a840ed0fb50d1fec925 (diff) |
refactor code calling builtins and implement dp4
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/auxiliary/gallivm/instructionssoa.cpp | 116 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/instructionssoa.h | 12 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/soabuiltins.c | 14 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/tgsitollvm.cpp | 1 |
4 files changed, 116 insertions, 27 deletions
diff --git a/src/gallium/auxiliary/gallivm/instructionssoa.cpp b/src/gallium/auxiliary/gallivm/instructionssoa.cpp index 3fcfce8ce0..89d513afd0 100644 --- a/src/gallium/auxiliary/gallivm/instructionssoa.cpp +++ b/src/gallium/auxiliary/gallivm/instructionssoa.cpp @@ -144,6 +144,7 @@ std::vector<llvm::Value*> InstructionsSoa::extractVector(llvm::Value *vector) void InstructionsSoa::createFunctionMap() { m_functionsMap[TGSI_OPCODE_DP3] = "dp3"; + m_functionsMap[TGSI_OPCODE_DP4] = "dp4"; } llvm::Function * InstructionsSoa::function(int op) @@ -182,45 +183,42 @@ std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> i const std::vector<llvm::Value*> in2) { llvm::Function *func = function(TGSI_OPCODE_DP3); - std::vector<Value*> params; + return callBuiltin(func, in1, in2); +} + +llvm::Value * InstructionsSoa::allocaTemp() +{ + VectorType *vector = VectorType::get(Type::FloatTy, 4); + ArrayType *vecArray = ArrayType::get(vector, 4); + AllocaInst *alloca = new AllocaInst(vecArray, name("tmpRes"), + m_builder.GetInsertBlock()); - llvm::Value *tmp = allocaTemp(); std::vector<Value*> indices; indices.push_back(m_storage->constantInt(0)); indices.push_back(m_storage->constantInt(0)); - GetElementPtrInst *getElem = new GetElementPtrInst(tmp, + GetElementPtrInst *getElem = new GetElementPtrInst(alloca, indices.begin(), indices.end(), name("allocaPtr"), m_builder.GetInsertBlock()); - params.push_back(getElem); - params.push_back(in1[0]); - params.push_back(in1[1]); - params.push_back(in1[2]); - params.push_back(in1[3]); - params.push_back(in2[0]); - params.push_back(in2[1]); - params.push_back(in2[2]); - params.push_back(in2[3]); - CallInst *call = m_builder.CreateCall(func, params.begin(), params.end()); - call->setCallingConv(CallingConv::C); - call->setTailCall(false); + return getElem; +} - indices = std::vector<Value*>(); - indices.push_back(m_storage->constantInt(0)); - GetElementPtrInst *xElemPtr = new GetElementPtrInst(getElem, +std::vector<llvm::Value*> InstructionsSoa::allocaToResult(llvm::Value *allocaPtr) +{ + GetElementPtrInst *xElemPtr = new GetElementPtrInst(allocaPtr, m_storage->constantInt(0), name("xPtr"), m_builder.GetInsertBlock()); - GetElementPtrInst *yElemPtr = new GetElementPtrInst(getElem, + GetElementPtrInst *yElemPtr = new GetElementPtrInst(allocaPtr, m_storage->constantInt(1), name("yPtr"), m_builder.GetInsertBlock()); - GetElementPtrInst *zElemPtr = new GetElementPtrInst(getElem, + GetElementPtrInst *zElemPtr = new GetElementPtrInst(allocaPtr, m_storage->constantInt(2), name("zPtr"), m_builder.GetInsertBlock()); - GetElementPtrInst *wElemPtr = new GetElementPtrInst(getElem, + GetElementPtrInst *wElemPtr = new GetElementPtrInst(allocaPtr, m_storage->constantInt(3), name("wPtr"), m_builder.GetInsertBlock()); @@ -234,11 +232,75 @@ std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> i return res; } -llvm::Value * InstructionsSoa::allocaTemp() +std::vector<llvm::Value*> InstructionsSoa::dp4(const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2) { - VectorType *vector = VectorType::get(Type::FloatTy, 4); - ArrayType *vecArray = ArrayType::get(vector, 4); - AllocaInst *alloca = new AllocaInst(vecArray, name("tmpRes"), - m_builder.GetInsertBlock()); - return alloca; + llvm::Function *func = function(TGSI_OPCODE_DP4); + return callBuiltin(func, in1, in2); +} + +std::vector<Value*> InstructionsSoa::callBuiltin(llvm::Function *func, const std::vector<llvm::Value*> in1) +{ + std::vector<Value*> params; + + llvm::Value *allocaPtr = allocaTemp(); + params.push_back(allocaPtr); + params.push_back(in1[0]); + params.push_back(in1[1]); + params.push_back(in1[2]); + params.push_back(in1[3]); + CallInst *call = m_builder.CreateCall(func, params.begin(), params.end()); + call->setCallingConv(CallingConv::C); + call->setTailCall(false); + + return allocaToResult(allocaPtr); +} + +std::vector<Value*> InstructionsSoa::callBuiltin(llvm::Function *func, const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2) +{ + std::vector<Value*> params; + + llvm::Value *allocaPtr = allocaTemp(); + params.push_back(allocaPtr); + params.push_back(in1[0]); + params.push_back(in1[1]); + params.push_back(in1[2]); + params.push_back(in1[3]); + params.push_back(in2[0]); + params.push_back(in2[1]); + params.push_back(in2[2]); + params.push_back(in2[3]); + CallInst *call = m_builder.CreateCall(func, params.begin(), params.end()); + call->setCallingConv(CallingConv::C); + call->setTailCall(false); + + return allocaToResult(allocaPtr); +} + +std::vector<Value*> InstructionsSoa::callBuiltin(llvm::Function *func, const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2, + const std::vector<llvm::Value*> in3) +{ + std::vector<Value*> params; + + llvm::Value *allocaPtr = allocaTemp(); + params.push_back(allocaPtr); + params.push_back(in1[0]); + params.push_back(in1[1]); + params.push_back(in1[2]); + params.push_back(in1[3]); + params.push_back(in2[0]); + params.push_back(in2[1]); + params.push_back(in2[2]); + params.push_back(in2[3]); + params.push_back(in3[0]); + params.push_back(in3[1]); + params.push_back(in3[2]); + params.push_back(in3[3]); + CallInst *call = m_builder.CreateCall(func, params.begin(), params.end()); + call->setCallingConv(CallingConv::C); + call->setTailCall(false); + + return allocaToResult(allocaPtr); } diff --git a/src/gallium/auxiliary/gallivm/instructionssoa.h b/src/gallium/auxiliary/gallivm/instructionssoa.h index 5c26687150..3ef51dcaff 100644 --- a/src/gallium/auxiliary/gallivm/instructionssoa.h +++ b/src/gallium/auxiliary/gallivm/instructionssoa.h @@ -52,6 +52,8 @@ public: const std::vector<llvm::Value*> in2); std::vector<llvm::Value*> dp3(const std::vector<llvm::Value*> in1, const std::vector<llvm::Value*> in2); + std::vector<llvm::Value*> dp4(const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2); std::vector<llvm::Value*> madd(const std::vector<llvm::Value*> in1, const std::vector<llvm::Value*> in2, const std::vector<llvm::Value*> in3); @@ -69,6 +71,16 @@ private: llvm::Function *function(int); llvm::Module *currentModule() const; llvm::Value *allocaTemp(); + std::vector<llvm::Value*> allocaToResult(llvm::Value *allocaPtr); + std::vector<llvm::Value*> callBuiltin(llvm::Function *func, + const std::vector<llvm::Value*> in1); + std::vector<llvm::Value*> callBuiltin(llvm::Function *func, + const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2); + std::vector<llvm::Value*> callBuiltin(llvm::Function *func, + const std::vector<llvm::Value*> in1, + const std::vector<llvm::Value*> in2, + const std::vector<llvm::Value*> in3); private: llvm::LLVMFoldingBuilder m_builder; StorageSoa *m_storage; diff --git a/src/gallium/auxiliary/gallivm/soabuiltins.c b/src/gallium/auxiliary/gallivm/soabuiltins.c index 0b428a750f..24c14e1b69 100644 --- a/src/gallium/auxiliary/gallivm/soabuiltins.c +++ b/src/gallium/auxiliary/gallivm/soabuiltins.c @@ -46,6 +46,20 @@ void dp3(float4 *res, res[3] = dot; } + +void dp4(float4 *res, + float4 tmp0x, float4 tmp0y, float4 tmp0z, float4 tmp0w, + float4 tmp1x, float4 tmp1y, float4 tmp1z, float4 tmp1w) +{ + float4 dot = (tmp0x * tmp1x) + (tmp0y * tmp1y) + + (tmp0z * tmp1z) + (tmp0w * tmp1w); + + res[0] = dot; + res[1] = dot; + res[2] = dot; + res[3] = dot; +} + #if 0 void yo(float4 *out, float4 *in) { diff --git a/src/gallium/auxiliary/gallivm/tgsitollvm.cpp b/src/gallium/auxiliary/gallivm/tgsitollvm.cpp index a52ee26434..3f65865a5a 100644 --- a/src/gallium/auxiliary/gallivm/tgsitollvm.cpp +++ b/src/gallium/auxiliary/gallivm/tgsitollvm.cpp @@ -751,6 +751,7 @@ translate_instructionir(llvm::Module *module, } break; case TGSI_OPCODE_DP4: { + out = instr->dp4(inputs[0], inputs[1]); } break; case TGSI_OPCODE_DST: { |