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

Benjamin Bellec b.bellec at gmail.com
Sat Jun 4 16:14:36 PDT 2011


Le 03/06/2011 01:40, Brian Paul a écrit :
> 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?

Yes it fix, but as Matt Turner said, it's not necessary to check this.
Btw we don't check that in the other functions.


Le 03/06/2011 06:09, Matt Turner a écrit :
> 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

My own tests (on a Core2) shows that it's less efficient to do that, at
least with -O2 optimization enabled. With -O0, it's equal.

So here is a v2 patch with a builtin GCC optimization which is the
fastest (thx Matt to point me to this solution).

Regards.

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


More information about the mesa-dev mailing list