Why is this C++ code faster than my hand-written assembly for testing the Collatz conjecture? – 2017

Why is this C++ code faster than my hand-written assembly for testing the Collatz conjecture?

If you think a 64-bit DIV instruction is a good way to divide by two, then no wonder the compiler’s asm output beat your hand-written code, even with -O0 (compile fast, no extra optimization).

See Agner Fog’s Optimizing Assembly guide to learn how to write efficient asm. He also has instruction tables and a microarch guide for specific details for specific CPUs.

Related posts:

Leave a Reply