forked from mirrors/gecko-dev
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:
parent
cbf71085fb
commit
31157559f1
1 changed files with 13 additions and 0 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue