0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 22:48:56 +02:00

ircd::util: Add next_powerof2(u64) constexpr.

This commit is contained in:
Jason Volk 2020-05-07 21:31:02 -07:00
parent f77f36904e
commit 52831893da

View file

@ -258,6 +258,19 @@ is_powerof2(const long long v)
return v && !(v & (v - 1LL));
}
constexpr uint64_t
next_powerof2(uint64_t v)
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v |= v >> 32;
return ++v;
}
template<class T>
T
minmax(T ret,