From 04864559e23b511ad853c7c1dc0acccce73fa629 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 31 Jul 2017 04:23:21 +0200 Subject: [PATCH] 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). --- source/tanya/memory/arch/x86_64.d | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/source/tanya/memory/arch/x86_64.d b/source/tanya/memory/arch/x86_64.d index bd5f5a1..0c3b86f 100644 --- a/source/tanya/memory/arch/x86_64.d +++ b/source/tanya/memory/arch/x86_64.d @@ -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;