0

32bit call,function caller does the 'push',callee uses parameters by %ebp+offset. This is straight forward.

But in 64 bit,caller will first move parameters to 4 registers, then callee fetch them from registers and put into memory before use. I really feel here the usage of "shadow space"(https://en.wikipedia.org/wiki/X86_calling_conventions) via registers is redundant. We can directly use push so the parameters are in right memory location, why bother registers to store/restore them again?

What's the consideration behind this design? X64 restriction or limitation?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
  • 1
    Your problem is imaginary. The shadow space is useful to keep your program debuggable. The optimizer will not use it if it can avoid spilling the registers to memory. An optimized program does not have to be debuggable. – Hans Passant Sep 28 '16 at 10:53
  • ... and in many cases the x64 convention will be a great deal faster than the x86 convention, because you don't have to write the arguments to memory and then read them back. (I'm fairly sure the x64 convention was adopted because it is considered superior to the x86 one.) – Harry Johnston Sep 28 '16 at 22:28
  • 1
    Only debug builds actually spill the register args right away / at all. – Peter Cordes Jan 03 '22 at 19:31
  • I'm pretty sure there's an equivalent Q&A about x86-64 System V (non-Windows) and what's the point of register args if GCC's just going to spill them to memory at the top of the called function. But I can't find it now. [Why does clang produce inefficient asm with -O0 (for this simple floating point sum)?](https://stackoverflow.com/q/53366394) is related, maybe it's in the list of linked questions from that? Like [gcc argument register spilling on x86-64](https://stackoverflow.com/q/7201763) - still not exactly what I was thinking of, but close. – Peter Cordes Jan 03 '22 at 20:39
  • Does this answer your question? [gcc argument register spilling on x86-64](https://stackoverflow.com/questions/7201763/gcc-argument-register-spilling-on-x86-64) – Peter Cordes Jan 03 '22 at 20:39

0 Answers0