BACKENDS: Move nextHigher2() into common/algorithm.h

This commit is contained in:
Cameron Cawley 2019-12-14 12:13:09 +00:00 committed by Filippos Karapetis
parent 97b4ee93f1
commit c3c3137ab3
3 changed files with 22 additions and 29 deletions

View file

@ -271,6 +271,22 @@ T gcd(T a, T b) {
#pragma warning(pop)
#endif
/**
* Get the next highest power of 2.
*/
template<class T>
T nextHigher2(T v) {
if (v == 0)
return 1;
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return ++v;
}
/**
* Replacement algorithm for iterables.
*