Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add Win64 CAS code
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaka committed Jan 6, 2015
1 parent d1bd72b commit 90426b1
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions src/core/atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ else version( AsmX86_32 )
}
else static if( T.sizeof == long.sizeof && has64BitCAS )
{

//////////////////////////////////////////////////////////////////
// 8 Byte CAS on a 32-Bit Processor
//////////////////////////////////////////////////////////////////
Expand All @@ -309,7 +310,9 @@ else version( AsmX86_32 )
setz AL;
pop EBX;
pop EDI;

}

}
else
{
Expand Down Expand Up @@ -774,26 +777,57 @@ else version( AsmX86_64 )
}
else static if( T.sizeof == long.sizeof*2 && has128BitCAS)
{


//////////////////////////////////////////////////////////////////
// 16 Byte CAS on a 64-Bit Processor
//////////////////////////////////////////////////////////////////
version(Win64){
//Windows 64 calling convention uses different registers.
//DMD appears to reverse the register order.
asm pure nothrow @nogc
{
push RDI;
push RBX;
mov R9, writeThis;
mov R10, ifThis;
mov R11, here;

mov RDI, R9;
mov RBX, [RDI];
mov RCX, 8[RDI];

mov RDI, R10;
mov RAX, [RDI];
mov RDX, 8[RDI];

mov RDI, R11;
lock;
cmpxchg16b [RDI];
setz AL;
pop RBX;
pop RDI;
}

}else{

asm pure nothrow @nogc
{
push RDI;
push RBX;
lea RDI, writeThis;
mov RBX, [RDI];
mov RCX, 8[RDI];
lea RDI, ifThis;
mov RAX, [RDI];
mov RDX, 8[RDI];
mov RDI, here;
lock; // lock always needed to make this op atomic
cmpxchg16b [RDI];
setz AL;
pop RBX;
pop RDI;
asm pure nothrow @nogc
{
push RDI;
push RBX;
lea RDI, writeThis;
mov RBX, [RDI];
mov RCX, 8[RDI];
lea RDI, ifThis;
mov RAX, [RDI];
mov RDX, 8[RDI];
mov RDI, here;
lock; // lock always needed to make this op atomic
cmpxchg16b [RDI];
setz AL;
pop RBX;
pop RDI;
}
}
}
else
Expand Down Expand Up @@ -1253,7 +1287,7 @@ version( unittest )
while(!cas(&a, DoubleValue(1,2), DoubleValue(3,4))){}
assert(a.value1 == 3 && a.value2 ==4);

DoubleValue b = atomicLoad(a);
align(16) DoubleValue b = atomicLoad(a);
assert(b.value1 == 3 && b.value2 ==4);
}

Expand Down

0 comments on commit 90426b1

Please sign in to comment.