Reputation: 6099
OpenCL has a builtin function clz() to count the number of leading zeros of a long
, int
, etc. but nothing similar seems to be present for counting the number of trailing zeros. I've not been able to find any way to do this, other than just manually re-implementing of course. What is the proper way to do this?
Upvotes: 3
Views: 1056
Reputation: 15278
x & -x
leaves one least significant 1-bit. To get its position you can try something like:
32 - clz(x & -x)
Upvotes: 7