-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boolean (u1) type support #577
Comments
GLSL have int tmp1 = 233;
int tmp2 = tmp1 == 0;
int tmp3 = tmp2 ? xxx : yyy; I had to use |
Btw, do you think the name u1 is better? Since i1 seems like a signed integer, which means it's highest bit is used as a sign mark. However we only have one bit, and no place for value.. |
Agreed. |
|
Yeah, that was the reason why I initially picked |
Warning: The issue has been out-of-update for 50 days, marking |
Issue: #577 #6036 ### Brief Summary This PR adds `bool` as an alias to `ti.i32`. Specifically, - `x: bool` is equivalent to `x: i32` - `-> bool` is equivalent to `-> i32` - `bool(x)` is equivalent to `ti.cast(x, i32)`. This is a temporary solution while we work towards a standalone bool type. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…6742) Issue: taichi-dev#577 taichi-dev#6036 ### Brief Summary This PR adds `bool` as an alias to `ti.i32`. Specifically, - `x: bool` is equivalent to `x: i32` - `-> bool` is equivalent to `-> i32` - `bool(x)` is equivalent to `ti.cast(x, i32)`. This is a temporary solution while we work towards a standalone bool type. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Concisely describe the proposed feature
Currently, binary comparisons return type
ti.i32
. This is not only counter-intuitive but also inefficient in some cases. Also having native boolean types will allow us to do more compiler optimizations on Taichi IRs.Boolean types should be implemented as
ti.u1
, i.e., a single-bit integer.Note: implementing this feature is harder than it seems to me. You'll have to modify quite a few compiler components. For example, update the type-checker to let comparisons return
u1
instead ofi32
, and the codegens to emit correct types. Fortunately, as we are not running into any urgent need for this, we have plenty of time to implement this.Related issue: #504
The text was updated successfully, but these errors were encountered: