3 ms·
I often boggle at people who claim that compilers are magic and outperform humans-- perhaps thats true for unimportant code that you'd pay no attention to, or w
by nullc 12y ago
I often boggle at people who claim that compilers are magic and outperform humans-- perhaps thats true for unimportant code that you'd pay no attention to, or with developers who aren't familiar with the underlying micro-architecture at all.
It's pretty usual for me to see a factor of 2 performance for the same algorithm implemented in the same manner when moving from SIMD intrensics (which almost directly map the underlying platform) to hand coded ASM.
Even non-SIMD code can result in some pretty stark changes.
A non-SIMD example from a crypto library I work on which isn't (yet) very well optimized for ARM, benchmarked on my novena (with GCC 4.9.1 -O3):
ecdsa_verify: min 1927us / avg 1928us / max 1929us
And a hand conversion of two hot inner functions (which are straight line multiple and add lattices, no control flow) into arm assembly:
ecdsa_verify: min 809us / avg 810us / max 811us
Again, same algorithm.
(The parallel change for x86_64 is still significant, but somewhat less extreme; in that case converting the same functions is only a 15% speedup overall, partially because the 64bit algorithm is different).
When thats a difference which results in 2x the amount of hardware (or 15% for that matter) for a big deployment; it can justify a LOT of optimization time.
(Or in my case, the performance of this code will have a material effect on the achievable scale and decentralization of the Bitcoin network.)
From a straight development time vs performance perspective I'd use even more hand written code; ... but there is a maintenance/auditing/eview/verification overhead too. And often the same code that you cannot tolerate being slow you also cannot tolerate being wrong.