Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline int CountTrailingZeroes(unsigned int x)
- {
- #if defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(__GNUC__)
- return __builtin_ctz(x);
- #elif defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(_MSC_VER)
- unsigned long ans;
- _BitScanForward(&ans, x);
- return ans;
- #else
- int i = 0;
- while (i < 32 && !(x & 1))
- {
- ++i;
- x >>= 1;
- }
- return i;
- #endif
- }
- inline int CountTrailingZeroes(unsigned long x)
- {
- #if defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(__GNUC__)
- return __builtin_ctzl(x);
- #elif defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(_MSC_VER)
- unsigned long ans;
- _BitScanForward(&ans, x);
- return ans;
- #else
- int i = 0;
- while (i < 64 && !(x & 1))
- {
- ++i;
- x >>= 1;
- }
- return i;
- #endif
- }
- inline int CountTrailingZeroes(unsigned long long x)
- {
- #if defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(__GNUC__)
- return __builtin_ctzll(x);
- #elif defined(DAEMON_USE_COMPILER_INTRINSICS) && defined(_MSC_VER)
- unsigned long ans;
- #ifdef _WIN64
- _BitScanForward64(&ans, x);
- #else
- bool nonzero = _BitScanForward(&ans, static_cast<unsigned long>(x));
- if (!nonzero)
- {
- _BitScanForward(&ans, x >> 32);
- }
- #endif
- return ans;
- #else
- int i = 0;
- while (i < 64 && !(x & 1))
- {
- ++i;
- x >>= 1;
- }
- return i;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement