X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=util.cpp;h=ac6a218098873953d25036605d728ed98257ec70;hb=9e219b96e914b2e5709ba3c3345afdc3cf13a78d;hp=372064b28948238c1c30815f7cb9cdb82087128f;hpb=5b6ab865efa692b25590f302c111b30680fbacdd;p=movit diff --git a/util.cpp b/util.cpp index 372064b..ac6a218 100644 --- a/util.cpp +++ b/util.cpp @@ -220,4 +220,17 @@ unsigned div_round_up(unsigned a, unsigned b) return (a + b - 1) / b; } +// Algorithm from http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2. +unsigned next_power_of_two(unsigned v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + } // namespace movit