diff --git a/libretro-common/include/compat/intrinsics.h b/libretro-common/include/compat/intrinsics.h index 37fc291e74..ac490274e8 100644 --- a/libretro-common/include/compat/intrinsics.h +++ b/libretro-common/include/compat/intrinsics.h @@ -66,17 +66,31 @@ static INLINE int compat_ctz(unsigned x) _BitScanForward((unsigned long*)&r, x); return (int)r; #else -/* Only checks at nibble granularity, - * because that's what we need. */ - if (x & 0x000f) - return 0; - if (x & 0x00f0) - return 4; - if (x & 0x0f00) - return 8; - if (x & 0xf000) - return 12; - return 16; + int count = 0; + if (!(x & 0xffff)) + { + x >>= 16; + count |= 16; + } + if (!(x & 0xff)) + { + x >>= 8; + count |= 8; + } + if (!(x & 0xf)) + { + x >>= 4; + count |= 4; + } + if (!(x & 0x3)) + { + x >>= 2; + count |= 2; + } + if (!(x & 0x1)) + count |= 1; + + return count; #endif }