3 ms·
The worst case integer divide times on newest Intel/AMD cpus are 15/18 for 64bit and 12/13 for 32-bit. Both do early out for easy values at around 10 cycles. I
by Tuna-Fish 4y ago
The worst case integer divide times on newest Intel/AMD cpus are 15/18 for 64bit and 12/13 for 32-bit. Both do early out for easy values at around 10 cycles.
Integer division is still on the slower side operations on the machines, but the advice to avoid division at all costs is outdated. In comparison, the FP divide instructions are in the ~13/14 cycles, it would be hard for you to shuffle data to that side and back and not be slower. (And no, they are not doing this internally -- both have separate integer divide units.)
- magicalhippo 4y agoThese things change over time, but at least a fair chunk of recent Intel CPUs had idiv handled by the floating-point unit. That is, it couldn't do an idiv and a fdiv in parallel.