1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 02:30:46 +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:
nimelehin 2020-03-23 17:31:37 +03:00 committed by Andreas Kling
parent 8137ef6252
commit 471db7ce0a

View File

@ -84,3 +84,17 @@ template<typename T>
return value;
#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
}