I love the __ffs and __clz functions. Ideal for quickly getting important information out of a bit mask. The trouble is, I often have my bit masks as unsigned ints. I see that the arguments to these two functions are int, and I can observe with the following code that converting an unsigned int that would overflow the signed int format will result in a negative number, which converted back to unsigned int results in the original number, implying that the bit string is not in fact being altered by conversion to signed int.
if (threadIdx.x == 0 && blockIdx.x == 0) {
unsigned int uTH = 0xfffffff0;
int iTH = uTH;
unsigned int nTH = iTH;
printf("Unsigned = %11u Signed = %11d Recovered = %11u\n", uTH, iTH, nTH);
}
(Result: Unsigned = 4294967280 Signed = -16 Recovered = 4294967280)
Is that correct, that I can safely feed my unsigned int bit masks to __ffs and __clz and trust that the original bit strings are being interpreted?
Thanks!