RFA: Small PATCH to add pow2p_hwi to hwint.h

Jakub Jelinek jakub@redhat.com
Thu Sep 8 15:25:00 GMT 2016


On Thu, Sep 08, 2016 at 08:53:26AM -0600, Jeff Law wrote:
> On 09/07/2016 11:56 PM, Jason Merrill wrote:
> > Various places in GCC use negate, bit-and and compare to test whether
> > an integer is a power of 2, but I think it would be clearer for this
> > test to be wrapped in a function.
> > 
> > OK for trunk?
> > 
> I think the canonical way we've written that is
> 
> exact_log2 (x) != -1

We have integer_pow2p which works on trees (and is actually implemented by
testing if popcnt is 1 on the wide-int).
Calling exact_log2 for such a test if you don't need the value is a waste of
compile time, ctz_hwi doesn't need to be computed.  And, exact_log2 is -1
even on 0, which is not pow2p_hwi.

I think having pow2p_hwi would be nice, if we really start using it where
appropriate.

	Jakub



More information about the Gcc-patches mailing list