From a2debc2704b9126d92d947c0407a0fbd709ab932 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Fri, 2 Nov 2007 12:09:23 -0400 Subject: Implement sin opcode. Seems to have similar rounding border problems as cos. --- src/mesa/pipe/llvm/gallivm.cpp | 4 +++- src/mesa/pipe/llvm/gallivm_builtins.cpp | 27 +++++++++++++++++++++++++++ src/mesa/pipe/llvm/instructions.cpp | 10 ++++++++++ src/mesa/pipe/llvm/instructions.h | 1 + src/mesa/pipe/llvm/llvm_builtins.c | 13 +++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mesa/pipe/llvm/gallivm.cpp b/src/mesa/pipe/llvm/gallivm.cpp index 7e91f8c556..bd8bfac208 100644 --- a/src/mesa/pipe/llvm/gallivm.cpp +++ b/src/mesa/pipe/llvm/gallivm.cpp @@ -452,7 +452,9 @@ translate_instruction(llvm::Module *module, out = instr->sgt(inputs[0], inputs[1]); } break; - case TGSI_OPCODE_SIN: + case TGSI_OPCODE_SIN: { + out = instr->sin(inputs[0]); + } break; case TGSI_OPCODE_SLE: break; diff --git a/src/mesa/pipe/llvm/gallivm_builtins.cpp b/src/mesa/pipe/llvm/gallivm_builtins.cpp index b06629265a..da1e6ae1de 100644 --- a/src/mesa/pipe/llvm/gallivm_builtins.cpp +++ b/src/mesa/pipe/llvm/gallivm_builtins.cpp @@ -126,6 +126,12 @@ Function* func_sinf = new Function( /*Name=*/"sinf", mod); // (external, no body) func_sinf->setCallingConv(CallingConv::C); +Function* func_vsin = new Function( + /*Type=*/FuncTy_5, + /*Linkage=*/GlobalValue::ExternalLinkage, + /*Name=*/"vsin", mod); +func_vsin->setCallingConv(CallingConv::C); + // Global Variable Declarations @@ -428,6 +434,27 @@ gvar_array__str1->setInitializer(const_array_14); } +// Function: vsin (func_vsin) +{ + Function::arg_iterator args = func_vsin->arg_begin(); + Value* packed_val_59 = args++; + packed_val_59->setName("val"); + + BasicBlock* label_entry_60 = new BasicBlock("entry",func_vsin,0); + + // Block entry (label_entry_60) + ExtractElementInst* float_tmp2_61 = new ExtractElementInst(packed_val_59, const_int32_18, "tmp2", label_entry_60); + CallInst* float_call_62 = new CallInst(func_sinf, float_tmp2_61, "call", label_entry_60); + float_call_62->setCallingConv(CallingConv::C); + float_call_62->setTailCall(true); + InsertElementInst* packed_tmp6 = new InsertElementInst(const_packed_34, float_call_62, const_int32_18, "tmp6", label_entry_60); + InsertElementInst* packed_tmp9_63 = new InsertElementInst(packed_tmp6, float_call_62, const_int32_22, "tmp9", label_entry_60); + InsertElementInst* packed_tmp12_64 = new InsertElementInst(packed_tmp9_63, float_call_62, const_int32_24, "tmp12", label_entry_60); + InsertElementInst* packed_tmp15_65 = new InsertElementInst(packed_tmp12_64, float_call_62, const_int32_23, "tmp15", label_entry_60); + new ReturnInst(packed_tmp15_65, label_entry_60); + +} + return mod; } diff --git a/src/mesa/pipe/llvm/instructions.cpp b/src/mesa/pipe/llvm/instructions.cpp index c4a1b2d5c1..232dd9cd5d 100644 --- a/src/mesa/pipe/llvm/instructions.cpp +++ b/src/mesa/pipe/llvm/instructions.cpp @@ -874,5 +874,15 @@ llvm::Value * Instructions::scs(llvm::Value *in) return call; } + +llvm::Value * Instructions::sin(llvm::Value *in) +{ + llvm::Function *func = m_mod->getFunction("vsin"); + assert(func); + + CallInst *call = m_builder.CreateCall(func, in, name("sinres")); + call->setTailCall(false); + return call; +} #endif //MESA_LLVM diff --git a/src/mesa/pipe/llvm/instructions.h b/src/mesa/pipe/llvm/instructions.h index 95c845e862..e9bfc9d740 100644 --- a/src/mesa/pipe/llvm/instructions.h +++ b/src/mesa/pipe/llvm/instructions.h @@ -95,6 +95,7 @@ public: llvm::Value *scs(llvm::Value *in); llvm::Value *sge(llvm::Value *in1, llvm::Value *in2); llvm::Value *sgt(llvm::Value *in1, llvm::Value *in2); + llvm::Value *sin(llvm::Value *in); llvm::Value *slt(llvm::Value *in1, llvm::Value *in2); llvm::Value *sub(llvm::Value *in1, llvm::Value *in2); llvm::Value *trunc(llvm::Value *in); diff --git a/src/mesa/pipe/llvm/llvm_builtins.c b/src/mesa/pipe/llvm/llvm_builtins.c index ca15995557..517aa2e84b 100644 --- a/src/mesa/pipe/llvm/llvm_builtins.c +++ b/src/mesa/pipe/llvm/llvm_builtins.c @@ -93,3 +93,16 @@ inline float4 scs(float4 val) result.y = sinf(tmp); return result; } + + +inline float4 vsin(float4 val) +{ + float4 result; + float tmp = val.x; + float res = sinf(tmp); + result.x = res; + result.y = res; + result.z = res; + result.w = res; + return result; +} -- cgit v1.2.3