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; naked;
// RDX - source length.
// RCX - source data.
// RDI - target length.
// RSI - target data.
// RDI and RSI should be preserved. // RDI and RSI should be preserved.
mov RAX, RDI; mov RAX, RDI;
mov R8, RSI; mov R8, RSI;
}
// Set the registers for movsb/movsq. // 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.
mov RDI, RSI; mov RDI, RSI;
mov RSI, RCX; mov RSI, RCX;
}
asm pure nothrow @nogc
{
cmp RDX, 0x08; cmp RDX, 0x08;
jc aligned_8; jc aligned_8;
test EDI, 0x07; test EDI, 0x07;
@ -54,7 +67,7 @@ pure nothrow @system @nogc
and EDX, 0x07; and EDX, 0x07;
jz end; jz end;
// Write remaining bytes. // Write the remaining bytes.
mov RCX, RDX; mov RCX, RDX;
rep; rep;
movsb; movsb;