LDC2 win64 calling convention

realhet real_het at hotmail.com
Thu Nov 29 15:10:41 UTC 2018


On Wednesday, 28 November 2018 at 21:58:16 UTC, kinke wrote:
> You're not using naked asm; this entails a prologue (spilling 
> the params to stack etc.). Additionally, LDC doesn't really 
> like accessing params and locals in DMD-style inline asm, see 
> https://github.com/ldc-developers/ldc/issues/2854.
>
> You can check the final asm trivially online, e.g., 
> https://run.dlang.io/is/e0c2Ly (click the ASM button). You'll 
> see that your params are in R8, RDX and RCX (reversed order as 
> mentioned earlier).

Hi again.

I just tried a new debugger: x64dbg. I really like it, it is not 
the bloatware I got used to nowadays.

It turns out that LDC2's parameter/register handling is really 
clever:

- Register saving/restoring: fully automatic. It analyzes my asm 
and saves/restores only those regs I overwrite.
- Parameters: Reversed Microsoft x64 calling convention, just as 
you said. Parameters in the registers will be 'spilled' onto the 
stack no matter if I'm using them by their names or by the 
register. Maybe this is not too clever but as I can use the 
params by their name from anywhere, it can make my code nicer.
- Must not use the "ret" instruction because it will take it 
literally and will skip the auto-generated exit code.

In conclusion: Maybe LDC2 generates a lot of extra code, but I 
always make longer asm routines, so it's not a problem for me at 
all while it helps me a lot.



More information about the Digitalmars-d-learn mailing list