by Digby » Oct 9, 2002 @ 5:49pm
If you're running on XScale you can use CLZ, then subtract the result from 31.
Otherwise, I'd probably perform a series of AND operations with mask and use a divide-and-conquer approach to find the set bit (test HIWORD/LOWORD, test HIBYTE/LOBYTE, test HINIBBLE/LONIBBLE, etc.). This will get you the result after 5 ANDs and 5 comparisons. It's not one line of code, but it's probably faster than the other methods suggested.