mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-19 07:52:30 +09:00
Author: https://github.com/nimelehin Commit: https://github.com/SerenityOS/serenity/commit/471db7ce0a0
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue