4 ms·
> The complete lack of push/pop instructions also shows a massive defect in the understanding of how the x86 architecture is supposed to be used. Push and pop
by pcwalton 8y ago
> The complete lack of push/pop instructions also shows a massive defect in the understanding of how the x86 architecture is supposed to be used.
Push and pop aren't that great because they mutate the stack pointer for each value you push or pop instead of mutating it once. Usually you want to push or pop more than one argument at a time, or reuse outgoing stack space for multiple function calls, and in that case it's often better to do the stack pointer manipulation once and then use mov to move the values into place.
That said, passing all arguments and return values via the stack is totally silly, is a significant performance hit, and is a bug they really should fix.
- userbinator 8y agoPush and pop aren't that great because they mutate the stack pointer for each value you push or pop instead of mutating it once. The push and pop instructions are specifically optimised; see the section titled "Stack Engine" here for a brief explanation: https://en.wikipedia.org/wiki/Stack_register https://en.wikipedia.org/wiki/Stack_register Not only does using mov with a base+displacement addressing mode not take advantage of the specialised stack hardware and also increases the code size, it also means extra effective-address calculations for the ALU. If you don't believe that, look at this: https://lists.llvm.org/pipermail/llvm-dev/2014-December/079945.html https://lists.llvm.org/pipermail/llvm-dev/2014-December/0799... When someone who works for Intel proposes changing LLVM to generate push instead of mov for calls, and even suggests push-pop pairs for memory-memory moves to save on register allocation (I've seen this trick before in handwritten Asm, but can't recall if ICC does it too --- it might), I think you had better listen to him, unless you believe it's some sort of a weird conspiracy to make other compilers worse so that Intel's looks better... but then again, ICC and MSVC (among others) use push too, and they're certainly not any slower for it.
- pcwalton 8y ago> If you don't believe that, look at this: The followups cite Agner's tables to show that push and pop are slower. Reg/mem move has reciprocal throughput 0.5 on Haswell, while pop has 1. It's a code size win, but not really a speed win.