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
Notes: sideshowbarker 2024-07-19 07:52:30 +09:00

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
}