m_llvmFSqrt = 0;
m_llvmFAbs = 0;
m_llvmPow = 0;
+ m_llvmFloor = 0;
}
llvm::Value * Instructions::add(llvm::Value *in1, llvm::Value *in2)
return vectorFromVals(val, val, val, val);
}
+llvm::Value * Instructions::callFloor(llvm::Value *val)
+{
+ if (!m_llvmFloor) {
+ // predeclare the intrinsic
+ std::vector<const Type*> floorArgs;
+ floorArgs.push_back(Type::FloatTy);
+ ParamAttrsList *floorPal = 0;
+ FunctionType* floorType = FunctionType::get(
+ /*Result=*/Type::FloatTy,
+ /*Params=*/floorArgs,
+ /*isVarArg=*/false,
+ /*ParamAttrs=*/floorPal);
+ m_llvmFloor = new Function(
+ /*Type=*/floorType,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Name=*/"floorf", m_mod);
+ m_llvmFloor->setCallingConv(CallingConv::C);
+ }
+ CallInst *call = new CallInst(m_llvmFloor, val,
+ name("floorf"),
+ m_block);
+ call->setCallingConv(CallingConv::C);
+ call->setTailCall(false);
+ return call;
+}
+
+llvm::Value * Instructions::floor(llvm::Value *in)
+{
+ ExtractElementInst *x = new ExtractElementInst(in, unsigned(0),
+ name("extractx"),
+ m_block);
+ ExtractElementInst *y = new ExtractElementInst(in, unsigned(1),
+ name("extracty"),
+ m_block);
+ ExtractElementInst *z = new ExtractElementInst(in, unsigned(2),
+ name("extractz"),
+ m_block);
+ ExtractElementInst *w = new ExtractElementInst(in, unsigned(3),
+ name("extractw"),
+ m_block);
+ return vectorFromVals(callFloor(x), callFloor(y),
+ callFloor(z), callFloor(w));
+}
+
+llvm::Value * Instructions::frc(llvm::Value *in)
+{
+ llvm::Value *flr = floor(in);
+ return sub(in, flr);
+}
+
llvm::Value *dph(llvm::Value *in1, llvm::Value *in2);
llvm::Value *dst(llvm::Value *in1, llvm::Value *in2);
llvm::Value *ex2(llvm::Value *in1);
+ llvm::Value *floor(llvm::Value *in1);
+ llvm::Value *frc(llvm::Value *in1);
llvm::Value *lit(llvm::Value *in1);
llvm::Value *madd(llvm::Value *in1, llvm::Value *in2,
llvm::Value *in2);
private:
const char *name(const char *prefix);
- llvm::Value *callFSqrt(llvm::Value *val);
llvm::Value *callFAbs(llvm::Value *val);
+ llvm::Value *callFloor(llvm::Value *val);
+ llvm::Value *callFSqrt(llvm::Value *val);
llvm::Value *callPow(llvm::Value *val1, llvm::Value *val2);
llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
llvm::Function *m_llvmFSqrt;
llvm::Function *m_llvmFAbs;
llvm::Function *m_llvmPow;
+ llvm::Function *m_llvmFloor;
};
#endif