Bug 1821362 - Add a generic CountTrailingZeroes function that lowers to the right intrinsic based the type its called with. r=sergesanspaille

Differential Revision: https://phabricator.services.mozilla.com/D173314
This commit is contained in:
Paul Adenot 2023-05-17 15:47:05 +00:00
Родитель 256aab271f
Коммит 63452a9038
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -453,6 +453,19 @@ inline T Clamp(const T aValue, const T aMin, const T aMax) {
return aValue;
}
template <typename T>
inline uint_fast8_t CountTrailingZeroes(T aValue) {
static_assert(sizeof(T) <= 8);
static_assert(std::is_integral_v<T>);
// This casts to 32-bits
if constexpr (sizeof(T) <= 4) {
return CountTrailingZeroes32(aValue);
}
// This doesn't
if constexpr (sizeof(T) == 8) {
return CountTrailingZeroes64(aValue);
}
}
} /* namespace mozilla */
#endif /* mozilla_MathAlgorithms_h */