Div and idiv (x86)
From Maths
(Redirected from Idiv (x86))
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.