Respect how Windows passes arrays on x86_64

tanya.memory.arch.x86_64:
Linux passes the array length and the data pointer in separate registers.
Windows passes a pointer to the whole array instead (pointer to the
array length practically).
This commit is contained in:
Eugen Wissner 2017-07-31 04:23:21 +02:00
parent 40e43c1465
commit 04864559e2

View File

@ -22,19 +22,32 @@ pure nothrow @system @nogc
{
naked;
// RDX - source length.
// RCX - source data.
// RDI - target length.
// RSI - target data.
// RDI and RSI should be preserved.
mov RAX, RDI;
mov R8, RSI;
}
// Set the registers for movsb/movsq.
version (Windows) asm pure nothrow @nogc
{
// RDX - source.
// RCX - target.
mov RDI, [ RCX + 8 ];
mov RSI, [ RDX + 8 ];
mov RDX, [ RDX ];
}
else asm pure nothrow @nogc
{
// RDX - source length.
// RCX - source data.
// RDI - target length
// RSI - target data.
// Set the registers for movsb/movsq.
mov RDI, RSI;
mov RSI, RCX;
}
asm pure nothrow @nogc
{
cmp RDX, 0x08;
jc aligned_8;
test EDI, 0x07;
@ -54,7 +67,7 @@ pure nothrow @system @nogc
and EDX, 0x07;
jz end;
// Write remaining bytes.
// Write the remaining bytes.
mov RCX, RDX;
rep;
movsb;