user1111929
user1111929

Reputation: 6099

count trailing zeros in OpenCL

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

Answers (1)

zch
zch

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

Related Questions