Without subtracting one pow2 value would be rounded up to next pow2
which is not correct behaviour for the function.
_mesa_next_pow_two_32(uint32_t x)
{
#ifdef __GNUC__
- return 1 << (__builtin_clz(x) ^ 31);
+ x--;
+ return 1 << ((__builtin_clz(x) ^ 31) + 1);
#else
x--;
x |= x >> 1;
_mesa_next_pow_two_64(uint64_t x)
{
#ifdef __GNUC__
+ x--;
if (sizeof(x) == sizeof(long))
- return 1 << (__builtin_clzl(x) ^ 63);
+ return 1 << ((__builtin_clzl(x) ^ 63) + 1);
else
- return 1 << (__builtin_clzll(x) ^ 63);
+ return 1 << ((__builtin_clzll(x) ^ 63) + 1);
#else
x--;
x |= x >> 1;