Skip to content

Commit

Permalink
[opengl] Make the comparison result -1 for true (#1080)
Browse files Browse the repository at this point in the history
* [opengl] Make the comparison result -1 for true

* [skip ci] enforce code format

Co-authored-by: Taichi Gardener <[email protected]>
  • Loading branch information
archibate and taichi-gardener authored May 30, 2020
1 parent 9daa033 commit ca719c0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions taichi/backends/opengl/codegen_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,16 @@ class KernelGen : public IRVisitor {
if (is_opengl_binary_op_different_return_type(bin->op_type) ||
bin->element_type() != bin->lhs->element_type() ||
bin->element_type() != bin->rhs->element_type()) {
emit("{} {} = {}({} {} {});", dt_name, bin_name, dt_name, lhs_name,
binop, rhs_name);
if (is_comparison(bin->op_type)) {
// TODO(#577): Taichi uses -1 as true due to LLVM i1... See
// https://github.com/taichi-dev/taichi/blob/6989c0e21d437a9ffdc0151cee9d3aa2aaa2241d/taichi/codegen/codegen_llvm.cpp#L564
// This is a workaround to make OpenGL compatible with the behavior.
emit("{} {} = -{}({} {} {});", dt_name, bin_name, dt_name, lhs_name,
binop, rhs_name);
} else {
emit("{} {} = {}({} {} {});", dt_name, bin_name, dt_name, lhs_name,
binop, rhs_name);
}
} else {
emit("{} {} = {} {} {};", dt_name, bin_name, lhs_name, binop, rhs_name);
}
Expand Down

0 comments on commit ca719c0

Please sign in to comment.