mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd::util: Add next_powerof2(u64) constexpr.
This commit is contained in:
parent
f77f36904e
commit
52831893da
1 changed files with 13 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue