Skip to content

Commit

Permalink
[skip ci] enforce code format
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-gardener committed Aug 25, 2020
1 parent bbf9ed3 commit 84dc896
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
13 changes: 6 additions & 7 deletions taichi/analysis/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ class IRVerifier : public BasicStmtVisitor {
break;
}
}
TI_ASSERT_INFO(
found,
"IR broken: stmt {} cannot have operand {}."
" Please report this bug by opening an issue at"
" https://github.com/taichi-dev/taichi to help us improve."
" Thanks in advance!",
stmt->id, op->id);
TI_ASSERT_INFO(found,
"IR broken: stmt {} cannot have operand {}."
" Please report this bug by opening an issue at"
" https://github.com/taichi-dev/taichi to help us improve."
" Thanks in advance!",
stmt->id, op->id);
}
visible_stmts.back().insert(stmt);
}
Expand Down
48 changes: 23 additions & 25 deletions taichi/transforms/demote_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ class DemoteOperations : public BasicStmtVisitor {
auto lhs = stmt->lhs;
auto rhs = stmt->rhs;
if (stmt->op_type == BinaryOpType::floordiv) {
if (is_integral(rhs->element_type()) && is_integral(lhs->element_type())) {
if (is_integral(rhs->element_type()) &&
is_integral(lhs->element_type())) {
// @ti.func
// def ifloordiv(a, b):
// r = ti.raw_div(a, b)
// if (a < 0) != (b < 0) and a and b * r != a:
// r = r - 1
// return r
auto ret = Stmt::make<BinaryOpStmt>(
BinaryOpType::div, lhs, rhs);
auto ret = Stmt::make<BinaryOpStmt>(BinaryOpType::div, lhs, rhs);
auto zero = Stmt::make<ConstStmt>(LaneAttribute<TypedConstant>(0));
auto lhs_ltz = Stmt::make<BinaryOpStmt>(
BinaryOpType::cmp_lt, lhs, zero.get());
auto rhs_ltz = Stmt::make<BinaryOpStmt>(
BinaryOpType::cmp_lt, rhs, zero.get());
auto rhs_mul_ret = Stmt::make<BinaryOpStmt>(
BinaryOpType::mul, rhs, ret.get());
auto cond1 = Stmt::make<BinaryOpStmt>(
BinaryOpType::cmp_ne, lhs_ltz.get(), rhs_ltz.get());
auto cond2 = Stmt::make<BinaryOpStmt>(
BinaryOpType::cmp_eq, lhs, zero.get());
auto cond3 = Stmt::make<BinaryOpStmt>(
BinaryOpType::cmp_eq, rhs_mul_ret.get(), lhs);
auto cond12 = Stmt::make<BinaryOpStmt>(
BinaryOpType::bit_and, cond1.get(), cond2.get());
auto cond = Stmt::make<BinaryOpStmt>(
BinaryOpType::bit_and, cond12.get(), cond3.get());
auto real_ret = Stmt::make<BinaryOpStmt>(
BinaryOpType::add, ret.get(), cond.get());
auto lhs_ltz =
Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_lt, lhs, zero.get());
auto rhs_ltz =
Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_lt, rhs, zero.get());
auto rhs_mul_ret =
Stmt::make<BinaryOpStmt>(BinaryOpType::mul, rhs, ret.get());
auto cond1 = Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_ne,
lhs_ltz.get(), rhs_ltz.get());
auto cond2 =
Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_eq, lhs, zero.get());
auto cond3 = Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_eq,
rhs_mul_ret.get(), lhs);
auto cond12 = Stmt::make<BinaryOpStmt>(BinaryOpType::bit_and,
cond1.get(), cond2.get());
auto cond = Stmt::make<BinaryOpStmt>(BinaryOpType::bit_and,
cond12.get(), cond3.get());
auto real_ret =
Stmt::make<BinaryOpStmt>(BinaryOpType::add, ret.get(), cond.get());

modifier.insert_before(stmt, std::move(ret));
modifier.insert_before(stmt, std::move(zero));
Expand All @@ -65,10 +65,8 @@ class DemoteOperations : public BasicStmtVisitor {
// def ffloordiv(a, b):
// r = ti.raw_div(a, b)
// return ti.floor(r)
auto ret = Stmt::make<BinaryOpStmt>(
BinaryOpType::div, lhs, rhs);
auto floor = Stmt::make<UnaryOpStmt>(
UnaryOpType::floor, ret.get());
auto ret = Stmt::make<BinaryOpStmt>(BinaryOpType::div, lhs, rhs);
auto floor = Stmt::make<UnaryOpStmt>(UnaryOpType::floor, ret.get());
modifier.insert_before(stmt, std::move(ret));
modifier.insert_before(stmt, std::move(floor));
modifier.erase(stmt);
Expand Down

0 comments on commit 84dc896

Please sign in to comment.