: m_mod(mod), m_block(block), m_idx(0)
{
m_floatVecType = VectorType::get(Type::FloatTy, 4);
+
m_llvmFSqrt = 0;
m_llvmFAbs = 0;
+ m_llvmPow = 0;
}
llvm::Value * Instructions::add(llvm::Value *in1, llvm::Value *in2)
return in1;
}
+llvm::Value * Instructions::sub(llvm::Value *in1, llvm::Value *in2)
+{
+ BinaryOperator *res = BinaryOperator::create(Instruction::Sub, in1, in2,
+ name("sub"),
+ m_block);
+ return res;
+}
+
+llvm::Value * Instructions::callPow(llvm::Value *val1, llvm::Value *val2)
+{
+ if (!m_llvmPow) {
+ // predeclare the intrinsic
+ std::vector<const Type*> powArgs;
+ powArgs.push_back(Type::FloatTy);
+ powArgs.push_back(Type::FloatTy);
+ ParamAttrsList *powPal = 0;
+ FunctionType* powType = FunctionType::get(
+ /*Result=*/Type::FloatTy,
+ /*Params=*/powArgs,
+ /*isVarArg=*/false,
+ /*ParamAttrs=*/powPal);
+ m_llvmPow = new Function(
+ /*Type=*/powType,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Name=*/"llvm.pow.f32", m_mod);
+ m_llvmPow->setCallingConv(CallingConv::C);
+ }
+ std::vector<Value*> params;
+ params.push_back(val1);
+ params.push_back(val2);
+ CallInst *call = new CallInst(m_llvmPow, params.begin(), params.end(),
+ name("pow"),
+ m_block);
+ call->setCallingConv(CallingConv::C);
+ call->setTailCall(false);
+ return call;
+}
+
+llvm::Value * Instructions::pow(llvm::Value *in1, llvm::Value *in2)
+{
+ ExtractElementInst *x1 = new ExtractElementInst(in1, unsigned(0),
+ name("x1"),
+ m_block);
+ ExtractElementInst *x2 = new ExtractElementInst(in2, unsigned(0),
+ name("x2"),
+ m_block);
+ llvm::Value *val = callPow(x1, x2);
+ return vectorFromVals(val, val, val, val);
+}
+
+llvm::Value * Instructions::rcp(llvm::Value *in1)
+{
+ ExtractElementInst *x1 = new ExtractElementInst(in1, unsigned(0),
+ name("x1"),
+ m_block);
+ BinaryOperator *res = BinaryOperator::create(Instruction::FDiv,
+ ConstantFP::get(Type::FloatTy,
+ APFloat(1.f)),
+ x1,
+ name("rcp"),
+ m_block);
+ return vectorFromVals(res, res, res, res);
+}
+
llvm::Value *madd(llvm::Value *in1, llvm::Value *in2,
llvm::Value *in2);
llvm::Value *mul(llvm::Value *in1, llvm::Value *in2);
+ llvm::Value *pow(llvm::Value *in1, llvm::Value *in2);
+ llvm::Value *rcp(llvm::Value *in1);
llvm::Value *rsq(llvm::Value *in1);
+ llvm::Value *sub(llvm::Value *in1, llvm::Value *in2);
private:
const char *name(const char *prefix);
llvm::Value *callFSqrt(llvm::Value *val);
llvm::Value *callFAbs(llvm::Value *val);
+ llvm::Value *callPow(llvm::Value *val1, llvm::Value *val2);
llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
llvm::Value *z, llvm::Value *w=0);
char m_name[32];
llvm::BasicBlock *m_block;
int m_idx;
- llvm::Function *m_llvmFSqrt;
- llvm::Function *m_llvmFAbs;
llvm::VectorType *m_floatVecType;
+
+ llvm::Function *m_llvmFSqrt;
+ llvm::Function *m_llvmFAbs;
+ llvm::Function *m_llvmPow;
};
#endif
struct tgsi_full_instruction *fi)
{
llvm::Value *inputs[4];
+ printf("translate instr START\n");
for (int i = 0; i < inst->Instruction.NumSrcRegs; ++i) {
struct tgsi_full_src_register *src = &inst->FullSrcRegisters[i];
llvm::Value *val = 0;
val = storage->tempElement(src->SrcRegister.Index);
} else {
fprintf(stderr, "ERROR: not support llvm source\n");
+ printf("translate instr END\n");
return;
}
src->SrcRegister.SwizzleY != TGSI_SWIZZLE_Y ||
src->SrcRegister.SwizzleZ != TGSI_SWIZZLE_Z ||
src->SrcRegister.SwizzleW != TGSI_SWIZZLE_W) {
+ fprintf(stderr, "SWIZZLE is %d %d %d %d\n",
+ src->SrcRegister.SwizzleX, src->SrcRegister.SwizzleY,
+ src->SrcRegister.SwizzleZ, src->SrcRegister.SwizzleW);
int swizzle = src->SrcRegister.SwizzleX * 1000;
swizzle += src->SrcRegister.SwizzleY * 100;
swizzle += src->SrcRegister.SwizzleZ * 10;
return;
}
break;
- case TGSI_OPCODE_RCP:
+ case TGSI_OPCODE_RCP: {
+ out = instr->rcp(inputs[0]);
+ }
break;
case TGSI_OPCODE_RSQ: {
out = instr->rsq(inputs[0]);
out = instr->madd(inputs[0], inputs[1], inputs[2]);
}
break;
- case TGSI_OPCODE_SUB:
+ case TGSI_OPCODE_SUB: {
+ out = instr->sub(inputs[0], inputs[1]);
+ }
break;
case TGSI_OPCODE_LERP:
break;
break;
case TGSI_OPCODE_LOGBASE2:
break;
- case TGSI_OPCODE_POWER:
+ case TGSI_OPCODE_POWER: {
+ out = instr->pow(inputs[0], inputs[1]);
+ }
break;
case TGSI_OPCODE_CROSSPRODUCT:
break;
case TGSI_OPCODE_KIL:
break;
case TGSI_OPCODE_END:
+ printf("translate instr END\n");
return;
break;
default:
struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i];
if (dst->DstRegister.File == TGSI_FILE_OUTPUT) {
+ printf("--- storing to %d %p\n", dst->DstRegister.Index, out);
storage->store(dst->DstRegister.Index, out);
} else if (dst->DstRegister.File == TGSI_FILE_TEMPORARY) {
storage->setTempElement(dst->DstRegister.Index, out);
}
#endif
}
+ printf("translate instr END\n");
}