[Mesa-dev] [PATCH] faster util_next_power_of_two() function

Matt Turner mattst88 at gmail.com
Thu Jun 2 21:09:02 PDT 2011


On Thu, Jun 2, 2011 at 5:18 PM, Benjamin Bellec <b.bellec at gmail.com> wrote:
> But there is an issue, during compilation there is an error (-Wall)
> "warning: right shift count >= width of type [enabled by default]".

This doesn't make any sense since I don't think the unsigned int type
is ever 8 bytes:

> + if (sizeof(unsigned) == 8)
> +            val = (val >> 32) | val;

Also, if you want to check if the value is already a power-of-two,
instead of a case statement for every POT (including 0), just do the
standard is-power-of-two check:

(x & (x - 1)) == 0

(Scroll up a little on the page you cited)

Matt


More information about the mesa-dev mailing list