mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +00:00
AK: Add count_trailing_zeroes_32()
Add count_trailing_zeroes_32() which is implemented with builtins if available, otherwise there's a generic fallback.
This commit is contained in:
parent
8137ef6252
commit
471db7ce0a
|
@ -84,3 +84,17 @@ template<typename T>
|
||||||
return value;
|
return value;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]] inline int count_trailing_zeroes_32(unsigned int val)
|
||||||
|
{
|
||||||
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
|
return __builtin_ctz(val);
|
||||||
|
#else
|
||||||
|
for (u8 i = 0; i < 32; ++i) {
|
||||||
|
if ((val >> i) & 1) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in a new issue