[LANGUAGE] Added cos/sin (#132)
This commit is contained in:
committed by
Philippe Tillet
parent
3169e4355c
commit
2824345065
@@ -844,6 +844,30 @@ void generator::visit_exp_inst(ir::exp_inst* x){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Code Generation for `cos`
|
||||
*/
|
||||
void generator::visit_cos_inst(ir::cos_inst* x){
|
||||
std::vector<llvm::Type*> tys = {f32_ty};
|
||||
FunctionType *fn_ty = FunctionType::get(f32_ty, tys, false);
|
||||
InlineAsm *cos = InlineAsm::get(fn_ty, "cos.approx.f32 $0, $0;", "=f,0", false);
|
||||
for(auto idx: idxs_.at(x)){
|
||||
vals_[x][idx] = call(cos, std::vector<llvm::Value*>{vals_[x->get_operand(0)][idx]});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Code Generation for `sin`
|
||||
*/
|
||||
void generator::visit_sin_inst(ir::sin_inst* x){
|
||||
std::vector<llvm::Type*> tys = {f32_ty};
|
||||
FunctionType *fn_ty = FunctionType::get(f32_ty, tys, false);
|
||||
InlineAsm *sin = InlineAsm::get(fn_ty, "sin.approx.f32 $0, $0;", "=f,0", false);
|
||||
for(auto idx: idxs_.at(x)){
|
||||
vals_[x][idx] = call(sin, std::vector<llvm::Value*>{vals_[x->get_operand(0)][idx]});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Code Generation for `log`
|
||||
*/
|
||||
|
@@ -337,6 +337,14 @@ value *builder::create_exp(value *arg){
|
||||
return insert(exp_inst::create(arg));
|
||||
}
|
||||
|
||||
value *builder::create_cos(value *arg){
|
||||
return insert(cos_inst::create(arg));
|
||||
}
|
||||
|
||||
value *builder::create_sin(value *arg){
|
||||
return insert(sin_inst::create(arg));
|
||||
}
|
||||
|
||||
value *builder::create_log(value *arg){
|
||||
return insert(log_inst::create(arg));
|
||||
}
|
||||
|
@@ -688,6 +688,14 @@ ir::value *dispatch::log(ir::value *x, ir::builder *builder) {
|
||||
return builder->create_log(x);
|
||||
}
|
||||
|
||||
ir::value *dispatch::cos(ir::value *x, ir::builder *builder) {
|
||||
return builder->create_cos(x);
|
||||
}
|
||||
|
||||
ir::value *dispatch::sin(ir::value *x, ir::builder *builder) {
|
||||
return builder->create_sin(x);
|
||||
}
|
||||
|
||||
ir::value *dispatch::sqrt(ir::value *x, ir::builder *builder) {
|
||||
return builder->create_sqrt(x);
|
||||
}
|
||||
|
@@ -781,6 +781,27 @@ instruction* exp_inst::create(value *val, const std::string& name, instruction *
|
||||
return new exp_inst(val, name, next);
|
||||
}
|
||||
|
||||
// cos
|
||||
cos_inst::cos_inst(value *val, const std::string &name, instruction *next)
|
||||
: builtin_inst(val->get_type(), INST_COS, 1, name, next) {
|
||||
set_operand(0, val);
|
||||
}
|
||||
|
||||
instruction* cos_inst::create(value *val, const std::string& name, instruction *next) {
|
||||
return new cos_inst(val, name, next);
|
||||
}
|
||||
|
||||
// sin
|
||||
sin_inst::sin_inst(value *val, const std::string &name, instruction *next)
|
||||
: builtin_inst(val->get_type(), INST_SIN, 1, name, next) {
|
||||
set_operand(0, val);
|
||||
}
|
||||
|
||||
instruction* sin_inst::create(value *val, const std::string& name, instruction *next) {
|
||||
return new sin_inst(val, name, next);
|
||||
}
|
||||
|
||||
|
||||
// log
|
||||
|
||||
log_inst::log_inst(value *val, const std::string &name, instruction *next)
|
||||
|
Reference in New Issue
Block a user