Div and idiv (x86)

From Maths
Revision as of 17:17, 7 January 2018 by Alec (Talk | contribs) (Created page with "{{Stub page|grade=D|msg=Flesh out, include more than just caveats}} ==Caveats== Both of these instructions are notoriously slow. If we do {{M|a%b}} where {{M|0\le a<b}} and {{...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Stub grade: D
This page is a stub
This page is a stub, so it contains little or minimal information and is on a to-do list for being expanded.The message provided is:
Flesh out, include more than just caveats

Caveats

Both of these instructions are notoriously slow. If we do [ilmath]a%b[/ilmath] where [ilmath]0\le a<b[/ilmath] and [ilmath]b>0[/ilmath] then the result will be [ilmath]0[/ilmath] for the divisor and [ilmath]a[/ilmath] for the remainder. This is the trivial case, yet it's still really slow.

It is faster to do:

//for a,b unsigned integers
if(a < b) {
    return a;
}
return a % b;

and similarly in the signed case, if the "return a" happens 80% of the time (this is from memory on Sandy Bridge arch, confirmed on Haswell.

References

Template:To Categorise