next_power_of_two

simc/event.hpp at shadowlands · simulationcraft/simc https://github.com/simulationcraft/simc/blob/shadowlands/engine/sim/event.hpp

// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
constexpr 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;
}

 

posted @ 2021-02-21 17:32  papering  阅读(140)  评论(0编辑  收藏  举报