3 ms·
Honestly, it's hard to read this article and not question the author's mental state or intelligence. He literally presents x86 and ARM assembly dumps where shi
by devit 6y ago
Honestly, it's hard to read this article and not question the author's mental state or intelligence.
He literally presents x86 and ARM assembly dumps where shift right generates one instruction, and divide generates that same instruction plus several others.
Then, he feels the need to run an unnecessary benchmark (most likely screwing it up somehow) and concludes there is no difference!
But how can there possibly be no performance difference, in general, between the CPU running an ALU instruction and running that same instruction plus several other ALU instructions?!?
It's almost unbelievable.
As to how he screwed up the benchmark, my guesses are that either he failed to inline the function (and the CPU is really bad), or failed to prevent the optimizer from optimizing the whole loop, or didn't run enough iterations, or perhaps he ran the benchmark on a different VM than what produced the assembly (or maybe somehow the CPU can extract instruction level parallelism in this microbenchmark, but obviously that doesn't generalize to arbitrary code).
- brianyu8 6y agoWhile I think that there is merit to your argument, I feel like it could have been presented without questioning the author's intelligence or mental state.
- ken 6y agoThe "asrs" mnemonics are the same, but the opcodes use different addressing modes. The 4th instruction in the longer sequence is a register-to-register move, which might be a simple register rename. It's not obvious to me that the shorter sequence is necessarily faster than the longer one. OK, the "adds" is probably slower, and introduces a register dependency. But the whole exercise here is to test and see, not trust that some simple operation performs like how it looks. Indeed, if you discount the "bx lr" (that's just the return, right?), the 1-instruction version takes 3ns, and the 4-instruction version takes 4ns. Clearly, 4 times as many instructions is not taking anywhere near 4 times as long to execute.