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

2019-06-23 Thread Jeff Law
On 6/23/19 5:50 AM, Segher Boessenkool wrote: > On Sat, Jun 22, 2019 at 03:30:15PM -0600, Jeff Law wrote: >> On 6/22/19 12:44 PM, Segher Boessenkool wrote: >>> On Sat, Jun 22, 2019 at 09:46:52AM -0600, Jeff Law wrote: On 6/22/19 7:55 AM, Jason Duerstock wrote: > More generally, we can rewr

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

2019-06-23 Thread Segher Boessenkool
On Sat, Jun 22, 2019 at 03:30:15PM -0600, Jeff Law wrote: > On 6/22/19 12:44 PM, Segher Boessenkool wrote: > > On Sat, Jun 22, 2019 at 09:46:52AM -0600, Jeff Law wrote: > >> On 6/22/19 7:55 AM, Jason Duerstock wrote: > >>> More generally, we can rewrite > >>> > >>> if ( x > ((1 << z) -1)) { ...} >

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

2019-06-22 Thread Jeff Law
On 6/22/19 12:44 PM, Segher Boessenkool wrote: > On Sat, Jun 22, 2019 at 09:46:52AM -0600, Jeff Law wrote: >> On 6/22/19 7:55 AM, Jason Duerstock wrote: >>> More generally, we can rewrite >>> >>> if ( x > ((1 << z) -1)) { ...} >>> >>> as >>> >>> if ( x >> z ) { ... } >>> >>> This does not appear to

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

2019-06-22 Thread Segher Boessenkool
On Sat, Jun 22, 2019 at 09:46:52AM -0600, Jeff Law wrote: > On 6/22/19 7:55 AM, Jason Duerstock wrote: > > 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 > >

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

2019-06-22 Thread Jeff Law
On 6/22/19 7:55 AM, Jason Duerstock wrote: > 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 > 0x1fff) {...} > > This is equivalent to: > > if (x

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

2019-06-22 Thread Jason Duerstock
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 > 0x1fff) {...} This is equivalent to: if (x >> 61) {...} More generally, we can rewrite if ( x > ((1 << z) -