1

Why does the Visual Studio Compiler use mov esp,ebp ; pop ebp instead of using leave?

  • leave : 1 byte

  • MOV ESP, EBP / POP EBP : 3 bytes

1.png

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    @500-InternalServerError: The answers there focus on `enter` being slow. `leave` is only 3 uops on modern Intel CPUs, just one more than doing things separately, so it's more worth the tradeoff, especially with uop caches and/or single-uop `ret` (as opposed to `ret imm16`). And its 2 uops on some AMD CPUs. https://www.agner.org/optimize/. GCC *does* use `leave` (if ESP / RSP isn't already pointing at a saved EBP/RBP). Maybe that should go in an answer on the other question, though. – Peter Cordes May 06 '21 at 12:38

0 Answers0