Forum : ARM
Post Information | Post |
---|---|
October 15, 2013 - 7:33pm
|
I am using Rkit-Arm version 1.50.13.0109 & Ride 7.44.13.0109 I have a variable The below line of code requires 6400nS of execution time while running at a clock speed of 48Mhz. This is approximately 150 instruction cycles - very slow execution. The Assembly from the compiler is It appears that the compiler is not utilizing the processor long division LDIV function. I need this division to execute very fast. My question is how do I work with the compiler in C to take advantage of the processor LDIV instruction? Does anyone have experience on how to reduce execution to less then 1uS. |
Software support team. I have not solved my use of long division so I worked around the concern. I scaled the numbers by (2^15/20,000) so I could >> 15 which executes very fast (same as / 32768). For some reason the multiply is fast but the division is slow. The solution was to remove the division and shift right.
If anyone has a compiler directive to force the use of the LDIV instruction in the arm I would still like to know how to do this. It is possible I will not always have an easy work around.
Hi,
There is no ldiv instruction in Cortex-M cores.
ldiv() is a library function, as you observed.
Some Cortex cores, like the Cortex-M3, include sdiv and udiv instructions, which are probably used inside ldiv (or in place of it). But the Cortex-M0 does not provide these integer division instructions, so on this core the integer division must be performed by software. About 150 cycles is around what we can expect for that.
So your workaround is probably the best solution ... unless you can switch to a Cortex-M3-based device. ;)
(STM32F1...)
Best Regards,
Vincent
Vincent
Thank you for the clarification. I will note this for future choices of cores. Knowing the math and having control to scale the numbers allowing a shift does work well. Your support is much appreciated - thanks.