From c3c3137ab3a3d09c12eaa7140cb7ec760bdfe924 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 14 Dec 2019 12:13:09 +0000 Subject: BACKENDS: Move nextHigher2() into common/algorithm.h --- common/algorithm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'common') diff --git a/common/algorithm.h b/common/algorithm.h index 8384eb7089..1aac0376db 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -271,6 +271,22 @@ T gcd(T a, T b) { #pragma warning(pop) #endif +/** + * Get the next highest power of 2. + */ +template +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. * -- cgit v1.2.3