The intrinsic returns the number of leading zeros, not the bit number of
the first nonzero, so just flip it based on the mask size
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
inline unsigned char _BitScanReverse(unsigned long* Index, unsigned long Mask)
{
- *Index = __builtin_clz(Mask);
+ *Index = 63 - __builtin_clz(Mask);
return (Mask != 0);
}
inline unsigned char _BitScanReverse(unsigned int* Index, unsigned int Mask)
{
- *Index = __builtin_clz(Mask);
+ *Index = 31 - __builtin_clz(Mask);
return (Mask != 0);
}