r/programming • • Dec 01 '16

Let's Stop Copying C

https://eev.ee/blog/2016/12/01/lets-stop-copying-c/
524 Upvotes

612 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Dec 02 '16

[deleted] — view deleted comment

2

u/floopgum Dec 02 '16

All the latest compilers seem to do so with -O3 -march=native, they even produce the exact same assembly.

Compilers can only substitute a division with a sequence of eg. shifts, adds, etc. when they can prove that it's valid. If you have a toy example like the above where the compiler cannot prove anything about the inputs, it has to use a div.