An analysis on https://ridiculousfish.com/blog/posts/benchmarking-libdivide-m1-avx512.html finds that the new Apple CPU has spent a lot of resources making integer division massively faster.
This is a surprising thing to do. In my experience, integer division is not really used, except in cases of dividing by a compile time constant, which can be replaced with a shift or multiply.
It was even more surprising in the discussion on https://news.ycombinator.com/item?id=27133804 where someone said
When I've been micro-optimizing performance-critical code, integer division shows up as a hot spot regularly.
Now I'm really curious: just what are people doing, that makes integer division a bottleneck? I'm trying to think where it could be used. Cases I've seen:
Floating-point emulation. But these days the only CPUs without hardware floating-point are tiny microcontrollers that also wouldn't have hardware integer division anyway.
Hash tables with the number of buckets a prime number for a little bit of extra randomness. But it's long been known that this is not the best way to do things; if you don't trust your hash function to provide enough randomness, get a better hash function.
Early 3D like the PlayStation 1 using fixed point coordinates. But everyone nowadays does floating-point 3D.
So what exactly is all this integer division being used for?
/
with a variable when it could have avoided it. And since it's "better" to make everything a variable according to some people, it's not always visible as a compile-time constant. – Annabelleannabergitelong double
in ARM64 C is 128-bit quad precision, for which there's also no hardware support AFAIK, so that needs to be done in software too. – Neslund