Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The division algorithm naturally needs both a quotient and remainder. The process is like <a href="http://en.wikipedia.org/wiki/Long_division" rel="nofollow">long division</a>. The savings by not returning the remainder are minimal and only involve register <code>mov</code> operations. Also, having multiple variants of the <code>division</code> will blow away cache effects and you could actually make a system slower over-all.</p> <p>Here is some <strong>libgcc</strong> source.</p> <ul> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/config/arm/bpabi.c;hb=HEAD" rel="nofollow">bpapi.c</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/config/arm/bpabi.S;hb=HEAD" rel="nofollow">bpapi.S</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/config/arm/bpabi-v6m.S;hb=HEAD" rel="nofollow">bpapi-6m.S</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/divmod.c;hb=HEAD" rel="nofollow">divmod.c</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/udivmod.c;hb=HEAD" rel="nofollow">udivmod.c</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/udivmodsi4.c;hb=HEAD" rel="nofollow">udivmodsi4.c</a></li> <li><a href="http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcc2.c;hb=HEAD" rel="nofollow">libgcc2.c</a>, containing the main division algorithm.</li> </ul> <p>If you have profiled and determined that a major portion of you time is spent in the division routine, it might make sense to remove the remainder from being returned, but it still has to be calculated. It is probably better to examine your requirements.</p> <p>If you really need to make division faster, you can special case based on data profiling. Sacrifice precision, not strictly conform to 'C' rules, and use a table of inverses and shifts. These will give better results than <em>not returning the remainder</em>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload