This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

if (x > ((2^x)-1)) optimization


I was starting at the assembly from some of the Python source, and
came across this (simplified) comparison:

if (x > 2305843009213693951) {...}

This is the same as:

if (x > 0x1fffffffffffffff) {...}

This is equivalent to:

if (x >> 61) {...}

More generally, we can rewrite

if ( x > ((1 << z) -1)) { ...}

as

if ( x >> z ) { ... }

This does not appear to currently be a gcc optimization.  What is
involved in adding it?

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]