two mains
Vladimir Panteleev
vladimir at thecybershadow.net
Sun Jan 27 05:34:50 PST 2013
On Saturday, 26 January 2013 at 20:42:27 UTC, Tyro[17] wrote:
> So why do we need to mov RBP, RSP in [2] but not in [1]? I'm
> thinking this is because RBP contains the address of args but
> not sure.
The x64 calling convention passes the first few arguments via
registers. I think it's most likely that the function prolog is
allocating stack space to save the value of whatever registers
(RDI/RDX?) which contain the string[] parameter, so that it could
reuse those registers in the code of the function - but the
assignment seems to have been optimized out, yet the stack
allocation wasn't.
FWIW, on Windows x64, DMD generates slightly different code,
presumably because it's using the Microsoft x64 calling
convention instead of the System V one. There is no stack
allocation when compiled with -O, however without -O, DMD adds a
"mov [RBP+10h], RCX" instruction. I assume it makes use of the
32-byte "shadow space" to "spill" ECX:
http://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions
More information about the Digitalmars-d-learn
mailing list