Implement scs opcode
authorZack Rusin <zack@tungstengraphics.com>
Fri, 2 Nov 2007 16:05:00 +0000 (12:05 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Fri, 2 Nov 2007 16:05:00 +0000 (12:05 -0400)
src/mesa/pipe/llvm/gallivm.cpp
src/mesa/pipe/llvm/gallivm_builtins.cpp
src/mesa/pipe/llvm/instructions.cpp
src/mesa/pipe/llvm/instructions.h
src/mesa/pipe/llvm/llvm_builtins.c

index a737b56..7e91f8c 100644 (file)
@@ -502,7 +502,9 @@ translate_instruction(llvm::Module *module,
       out = instr->cmp(inputs[0], inputs[1], inputs[2]);
    }
       break;
-   case TGSI_OPCODE_SCS:
+   case TGSI_OPCODE_SCS: {
+      out = instr->scs(inputs[0]);
+   }
       break;
    case TGSI_OPCODE_TXB:
       break;
index b23af91..b066292 100644 (file)
@@ -114,6 +114,18 @@ Function* func_cosf = new Function(
   /*Name=*/"cosf", mod); // (external, no body)
 func_cosf->setCallingConv(CallingConv::C);
 
+Function* func_scs = new Function(
+  /*Type=*/FuncTy_5,
+  /*Linkage=*/GlobalValue::ExternalLinkage,
+  /*Name=*/"scs", mod); 
+func_scs->setCallingConv(CallingConv::C);
+
+Function* func_sinf = new Function(
+  /*Type=*/FuncTy_12,
+  /*Linkage=*/GlobalValue::ExternalLinkage,
+  /*Name=*/"sinf", mod); // (external, no body)
+func_sinf->setCallingConv(CallingConv::C);
+
 // Global Variable Declarations
 
 
@@ -394,6 +406,28 @@ gvar_array__str1->setInitializer(const_array_14);
   
 }
 
+// Function: scs (func_scs)
+{
+  Function::arg_iterator args = func_scs->arg_begin();
+  Value* packed_val_55 = args++;
+  packed_val_55->setName("val");
+  
+  BasicBlock* label_entry_56 = new BasicBlock("entry",func_scs,0);
+  
+  // Block entry (label_entry_56)
+  ExtractElementInst* float_tmp2 = new ExtractElementInst(packed_val_55, const_int32_18, "tmp2", label_entry_56);
+  CallInst* float_call_57 = new CallInst(func_cosf, float_tmp2, "call", label_entry_56);
+  float_call_57->setCallingConv(CallingConv::C);
+  float_call_57->setTailCall(true);
+  InsertElementInst* packed_tmp5 = new InsertElementInst(const_packed_34, float_call_57, const_int32_18, "tmp5", label_entry_56);
+  CallInst* float_call7 = new CallInst(func_sinf, float_tmp2, "call7", label_entry_56);
+  float_call7->setCallingConv(CallingConv::C);
+  float_call7->setTailCall(true);
+  InsertElementInst* packed_tmp9 = new InsertElementInst(packed_tmp5, float_call7, const_int32_22, "tmp9", label_entry_56);
+  new ReturnInst(packed_tmp9, label_entry_56);
+  
+}
+
 return mod;
 
 }
index 8e74ab3..c4a1b2d 100644 (file)
@@ -864,4 +864,15 @@ llvm::Value * Instructions::cos(llvm::Value *in)
 #endif
 }
 
+llvm::Value * Instructions::scs(llvm::Value *in)
+{
+   llvm::Function *func = m_mod->getFunction("scs");
+   assert(func);
+
+   CallInst *call = m_builder.CreateCall(func, in, name("scsres"));
+   call->setTailCall(false);
+   return call;
+}
+
 #endif //MESA_LLVM
+
index d33f61a..95c845e 100644 (file)
@@ -92,6 +92,7 @@ public:
    llvm::Value *pow(llvm::Value *in1, llvm::Value *in2);
    llvm::Value *rcp(llvm::Value *in);
    llvm::Value *rsq(llvm::Value *in);
+   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 *slt(llvm::Value *in1, llvm::Value *in2);
index a570e0e..ca15995 100644 (file)
@@ -71,6 +71,7 @@ inline float4 cmp(float4 tmp0, float4 tmp1, float4 tmp2)
 }
 
 extern float cosf(float  val);
+extern float sinf(float  val);
 
 inline float4 vcos(float4 val)
 {
@@ -83,3 +84,12 @@ inline float4 vcos(float4 val)
    printf("VEC OUT  is %f %f %f %f\n", result.x, result.y, result.z, result.w);
    return result;
 }
+
+inline float4 scs(float4 val)
+{
+   float4 result;
+   float tmp = val.x;
+   result.x = cosf(tmp);
+   result.y = sinf(tmp);
+   return result;
+}