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

Ian Romanick idr at freedesktop.org
Sun Jun 5 10:34:38 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/02/2011 04:40 PM, Brian Paul wrote:
> 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?

It will because it will evaluate to val >> 16, which is not what's wanted.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3rvi4ACgkQX1gOwKyEAw/MIACeKRGD0qTbeJUS61+jI60Isd0c
reEAn0wGrU8eucE50RL3tV4+4Ul8kT7D
=z1BM
-----END PGP SIGNATURE-----


More information about the mesa-dev mailing list