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

Brian Paul brianp at vmware.com
Thu Jun 2 16:40:06 PDT 2011


On 06/02/2011 03:18 PM, Benjamin Bellec wrote:
> It's me again, with a new minor optimization for the
> util_next_power_of_two() function.
>
> This patch implements a faster algorithm, still taken from Wikipedia (
> http://en.wikipedia.org/wiki/Power_of_two#Algorithm_to_round_up_to_power_of_two
> ).
> But especially, I added the most common values used by this function. I
> noted that ETQW, TA Spring and ExtremeTuxRacer call often "good" values.
> I can think that most OpenGL apps uses also these values.
>
> I have benchmarked this. With -O2 optimization, this new function is
> twice faster than the former. Without GCC optimization the difference is
> even bigger.
>
> There is no piglit regressions.
>
> But there is an issue, during compilation there is an error (-Wall)
> "warning: right shift count>= width of type [enabled by default]".

I'd like to avoid the warning if at all possible.  If you replace (val 
 >> 32) with (val >> (sizeof(unsigned) * 4)) does that silence it?

-Brian



More information about the mesa-dev mailing list