From 7abe3364b2c463fd3e96c2bc9d07aaa91bcfbc2c Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 17 Oct 2007 13:34:25 -0400 Subject: Implement dot4 opcode --- src/mesa/pipe/llvm/instructions.cpp | 27 +++++++++++++++++++++++++++ src/mesa/pipe/llvm/instructions.h | 1 + src/mesa/pipe/llvm/llvmtgsi.cpp | 12 +++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/llvm/instructions.cpp b/src/mesa/pipe/llvm/instructions.cpp index 31729d0..9e3b989 100644 --- a/src/mesa/pipe/llvm/instructions.cpp +++ b/src/mesa/pipe/llvm/instructions.cpp @@ -226,3 +226,30 @@ llvm::Value * Instructions::rcp(llvm::Value *in1) return vectorFromVals(res, res, res, res); } +llvm::Value * Instructions::dp4(llvm::Value *in1, llvm::Value *in2) +{ + Value *mulRes = mul(in1, in2); + ExtractElementInst *x = new ExtractElementInst(mulRes, unsigned(0), + name("extractx"), + m_block); + ExtractElementInst *y = new ExtractElementInst(mulRes, unsigned(1), + name("extracty"), + m_block); + ExtractElementInst *z = new ExtractElementInst(mulRes, unsigned(2), + name("extractz"), + m_block); + ExtractElementInst *w = new ExtractElementInst(mulRes, unsigned(3), + name("extractw"), + m_block); + BinaryOperator *xy = BinaryOperator::create(Instruction::Add, x, y, + name("xy"), + m_block); + BinaryOperator *xyz = BinaryOperator::create(Instruction::Add, xy, z, + name("xyz"), + m_block); + BinaryOperator *dot4 = BinaryOperator::create(Instruction::Add, xyz, w, + name("dot4"), + m_block); + return vectorFromVals(dot4, dot4, dot4, dot4); +} + diff --git a/src/mesa/pipe/llvm/instructions.h b/src/mesa/pipe/llvm/instructions.h index 18b5f91..c35cdb7 100644 --- a/src/mesa/pipe/llvm/instructions.h +++ b/src/mesa/pipe/llvm/instructions.h @@ -16,6 +16,7 @@ public: llvm::Value *add(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 *lit(llvm::Value *in1); llvm::Value *madd(llvm::Value *in1, llvm::Value *in2, llvm::Value *in2); diff --git a/src/mesa/pipe/llvm/llvmtgsi.cpp b/src/mesa/pipe/llvm/llvmtgsi.cpp index 45114ab..45bc96c 100644 --- a/src/mesa/pipe/llvm/llvmtgsi.cpp +++ b/src/mesa/pipe/llvm/llvmtgsi.cpp @@ -205,7 +205,9 @@ translate_instruction(llvm::Module *module, out = instr->dp3(inputs[0], inputs[1]); } break; - case TGSI_OPCODE_DP4: + case TGSI_OPCODE_DP4: { + out = instr->dp4(inputs[0], inputs[1]); + } break; case TGSI_OPCODE_DST: break; @@ -767,6 +769,10 @@ ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens) std::cout << "Creating llvm " <addModuleProvider(mp); } ga_llvm->module = mod; - fprintf(stderr, "DUMPX \n"); - //tgsi_dump(tokens, TGSI_DUMP_VERBOSE); - tgsi_dump(tokens, 0); - fprintf(stderr, "DUMPEND \n"); Function *func = mod->getFunction("run_vertex_shader"); std::cout << "run_vertex_shader = "<