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

Benjamin Bellec b.bellec at gmail.com
Thu Jun 2 14:18:34 PDT 2011


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]".

Regards.

Benjamin Bellec
-------------- next part --------------
A non-text attachment was scrubbed...
Name: faster-util_next_power_of_two-function.patch
Type: text/x-diff
Size: 1231 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110602/3f2e1b83/attachment.patch>


More information about the mesa-dev mailing list