| 120 | // returns the smallest multiple of p greater than or equal to x |
| 121 | template <typename T> |
| 122 | constexpr T AlignToMultiple(T x, T p) { |
| 123 | static_assert(std::numeric_limits<T>::is_integer, "Unsigned integer required."); |
| 124 | static_assert(std::is_unsigned<T>::value, "Unsigned integer required."); |
| 125 | return ((x + p - 1) / p) * p; |
| 126 | } |
| 127 | |
| 128 | // Returns the 0-based index of the LSB. An input mask of 0 yields -1 |
| 129 | static inline int LeastSignificantBit(uint32_t mask) { return u_ffs(static_cast<int>(mask)) - 1; } |