/*!
* \brief Computes the next highest power of two
*
* This nice little algorithm is taken from
* http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
*/
static uint32_t round_next_power_two(uint32_t v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
v += (v == 0); // handle v == 0 edge case
return v;
}
eg: 127 return 128
257 return 512
//----------------------------------------------------------------------
static int is_power_of_two(uint32_t v)
{
return (v != 0) && ((v & (v - 1)) == 0);
}