Bitshift instead of div/mul, for powers of 2

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Bitshift instead of div/mul, for powers of 2

Post by Keya »

It would be great if the compiler could detect when an integer division instruction is using a power of 2, and implement the calculation via bitshift instead. Likewise for multiply. Thankyou for considering
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Bitshift instead of div/mul, for powers of 2

Post by wilbert »

The result is not always the same

Code: Select all

a.i = -3
b.i = a / 2
c.i = a >> 1

Debug a
Debug b
Debug c
b and c are not equal in this case.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Bitshift instead of div/mul, for powers of 2

Post by Keya »

The compiler can test first?
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Bitshift instead of div/mul, for powers of 2

Post by jack »

Keya, I understand your request but for people not fluent in english it might be misunderstood,
you asking for optimization involving multiply and divide when the right hand side of an expression is an integer power of 2
Post Reply