Page 1 of 1
Bitshift instead of div/mul, for powers of 2
Posted: Mon Jan 25, 2016 5:52 pm
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
Re: Bitshift instead of div/mul, for powers of 2
Posted: Mon Jan 25, 2016 6:01 pm
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.
Re: Bitshift instead of div/mul, for powers of 2
Posted: Mon Jan 25, 2016 6:23 pm
by Keya
The compiler can test first?
Re: Bitshift instead of div/mul, for powers of 2
Posted: Mon Jan 25, 2016 7:11 pm
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