Bitshift instead of div/mul, for powers of 2
Bitshift instead of div/mul, for powers of 2
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
Re: Bitshift instead of div/mul, for powers of 2
The result is not always the same
b and c are not equal in this case.
Code: Select all
a.i = -3
b.i = a / 2
c.i = a >> 1
Debug a
Debug b
Debug c
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Bitshift instead of div/mul, for powers of 2
The compiler can test first?
Re: Bitshift instead of div/mul, for powers of 2
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
you asking for optimization involving multiply and divide when the right hand side of an expression is an integer power of 2