This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Division optimization problem

Hello everyone,
I implemented a Moving average routine in Keil C51.
And as I read else where that whenever I divide the number with 2^n the compiler uses shift operation, so that code is small and fast.
And Compiler did optimize it in this condition:

average =BINHI/64;  //BINHI, average is unsigned int.

However when BINHI is unsigned long instead of unsigned int the compiler uses actual division which is very costly in 8 bit.
So is there any way to divide unsigned long using shift operations only, if I make sure divisor is 2^n.

0