import std.stdio;
struct Test
{
ulong l1 = 64;
ulong l2 = 0;
}
void main()
{
Test t;
ulong* l1Ptr = &t.l1;
writeln("l2 before:", t.l2);
asm pure nothrow @nogc
{
mov RAX, l1Ptr;
mov RBX, [RAX];
mov [RAX+8], RBX;
}
writeln("l2 after:", t.l2);
}
CMP = Compare
import std.stdio;
void main()
{
ulong t = 0;
ulong* tPtr = &t;
writeln("t before:", t);
asm pure nothrow @nogc
{
mov RBX, tPtr;
mov RCX, [RBX];
mov RDX, 0;
loop:
add RCX, 10;
inc RDX;
cmp RDX, 2;
jle loop;
mov [RBX], RCX;
}
writeln("t after:", t);
}
import std.stdio;
void main()
{
double[2] values = [15.4, 36.7];
const double[2] newValues = [40.0, 20.4];
const double[2] confidences = [1.0, 0.5];
double* valuesPtr = values.ptr;
const(double)* newValuesPtr = newValues.ptr;
const(double)* confidencesPtr = confidences.ptr;
asm pure nothrow @nogc
{
mov RSI, valuesPtr;
mov RDI, newValuesPtr;
mov RAX, confidencesPtr;
//Load confidences = c
movupd XMM1, [RAX];
//Load values = v0
movupd XMM2, [RSI];
//Load new values = v1
movupd XMM0, [RDI];
//v1 = (v0 * c) + v1 - (v1 * c) = (v0 * c) + (v1 * (1 - c))
//v0 * c
mulpd XMM2, XMM1;
//(v0 * c) + v1
addpd XMM2, XMM0;
//v1 * c
mulpd XMM0, XMM1;
//(v0 * c) + v1 - (v1 * c)
subpd XMM2, XMM0;
movupd [RSI], XMM2;
}
writeln(values);
}