We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all,
when I wrote a C code with division operation the compiler is generating some library calls.....when I tried to see the equivalent code for those function calls...I'm unable to reach there (may be because they arm library SW routines)...I cant use those SW routine calls...I can embed the equivalent code in my program( in assembly code). Form where I can get the Equivalent codes for division SW routines....I need codes for 32-bit/32-bit ,32-bit/16-bit & 16-bit/16-bit divisions....
Thanks in advance....
The original and best paper on all this is
Division by Invariant Integers using Multiplication
by Torbjorn Granlund and Peter L. Montgomery
see also
Improved division by invariant integers
Nice references, thanks!
If you're really desperate here's a routine which does unsigned division by a constant.d not equal to zero
Initialise dr and sh such that
Shift d left while zero to give dbig with top bit set and shwzcnt the shift count
recip = (2^64 - 1) / dbig, a long unsigned division yielding an unsigned integer
dr = recip + 1
sh = 31 - shwzcnt
n = r0 the number to be divided + the eventual result
dr = r1
sh = r2
tmp = r3
movs dr, dr
umullne tmp, dr, n, dr
subne n, n, dr
addne n, dr, n, lsr #1
mov n, n, lsr sh
mov pc, lr
This can be used with a run time divisor when it is going to be used a number of times. But I'd just write a C routine and copy the generated code for divides by constants..
In fact I've found a surprising improvement for the more troublesome unsigned integer divisions by constant compared to the usual method see
Labor of Division (Episode III): Faster Unsigned Division by Constants