Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count trailing zeros in OpenCL

Tags:

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?

like image 461
user1111929 Avatar asked Mar 07 '26 01:03

user1111929


1 Answers

x & -x

leaves one least significant 1-bit. To get its position you can try something like:

32 - clz(x & -x)
like image 55
zch Avatar answered Mar 10 '26 14:03

zch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!