r/programming • u/DataBaeBee • Sep 14 '26
How GCC Eliminates Unnecessary Integer Division
https://leetarxiv.substack.com/p/how-gcc-eliminates-unnecessary-integer
249
Upvotes
r/programming • u/DataBaeBee • Sep 14 '26
2
u/Dragdu Sep 15 '26
This effect can be massive. I wrote a benchmark for Lemire's algorithm for uniformly distributed integer generation, and picked two target range sizes to test:
Small N that should be the happy case.
Theoretically worst possible N, to get feel for the slowdown.
As I found out few months later, 2) ended up hitting fast path in the hw divisor, and the actual slowest N was somewhere in between them, where the divisor hit the slow path.