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

Code for integer division on Cortex-A8?

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....

Parents Reply Children
  • 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