[Mesa-dev] [PATCH 1/2] util: Add util_is_power_of_two_minus_one

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Fri Jun 14 22:04:00 UTC 2019


> Except it would have to be util_is_power_of_two_or_zero because
> util_is_power_of_two(0xffffffff + 1) is false. :)

Corner cases, corner cases!

> Is there actually a 2/2 for this?  We usually wouldn't land something
> like this without a caller.

The 1/2 on there was accidentally, sorry. The use is in
https://lists.freedesktop.org/archives/mesa-dev/2019-June/220201.html,
but I figure you didn't need to get neck deep into Mali :)

It's just for an assert(), so I can get rid of it if this little patch
is too much to bikeshed ;) Just thought I'd try.

> This will return true for v == 0.  Is that the desired behavior?  I
> mean, that is 2**0 - 1, but it is not "all ones in binary."  I think the
> result may surprise people wanting to use this to detect a mask.  This
> is also how we ended up with util_is_power_of_two_nonzero and
> util_is_power_of_two_or_zero.

Hm. I'm not sure *is* the desired behaviour. In my case, (v == 0) is
special-cased anyway (see linked patch). Maybe not landing this is
easier to just avoid the can of worms.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190614/1b227a12/attachment.sig>


More information about the mesa-dev mailing list