Issues using the in-line assembler
solidstate1991
laszloszeremi at outlook.com
Thu Apr 5 20:15:15 UTC 2018
On Thursday, 5 April 2018 at 04:48:02 UTC, Basile B. wrote:
> The "this" seems to be in R11, so you have to apply the asm
> syntax for accessing the members using
> <Type>.offsetof.<member>[R11], example:
>
> ```
> class Foo
> {
> double a = 123456;
> extern(D) double foo()
> {
> asm
> {
> naked;
> movq XMM0, Foo.a.offsetof[R11];
> ret;
> }
> }
> }
>
> void main()
> {
> import std.stdio;
> (new Foo).foo(0,0).writeln;
> }
> ```
>
> However i cant find any specification saying that R11 is "this".
> With a free function just pass the instance as param and
> replace R11 by the register where the instance is passed.
It seems that the compiler lets it through if I change it like
this:
asm @nogc{
naked;
movd XMM1, dword ptr sX[EBP];
pslldq XMM1, 4;
movss XMM1, dword ptr sY[EBP];
movq XMM0, xy;
paddd XMM0, XMM1; // [x,y] + [sX,sY]
movq XMM3, qword ptr xy0[EBP];
psubd XMM0, XMM3; // ([x,y] + [sX,sY] - [x_0,y_0])
movq XMM1, qword ptr ac[EBP];
movq XMM2, qword ptr bd[EBP];
pmuludq XMM1, XMM0; // [A,0,C,0] * ([x,y] + [sX,sY] - [x_0,y_0])
psrlq XMM1, 16; // ([A,0,C,0] * ([x,y] + [sX,sY] -
[x_0,y_0]))>>16
movups XMM4, XMM0;
psrldq XMM4, 4;
pslldq XMM0, 4;
por XMM4, XMM0;
pmuludq XMM2, XMM4; // [0,B,0,D] * ([x,y] + [sX,sY] - [x_0,y_0])
psrlq XMM2, 16; // ([0,B,0,D] * ([x,y] + [sX,sY] -
[x_0,y_0]))>>16
paddq XMM1, XMM2; // ([A,B,C,D] * ([x,y] + [sX,sY] -
[x_0,y_0]))>>16
punpckldq XMM3, XMM7;
paddq XMM1, XMM3; // ([A,B,C,D] * ([x,y] + [sX,sY] -
[x_0,y_0]))>>16 + [x_0,y_0]
movups XMM0, XMM1; // Convert 64 bit vectors into 32 bit ones
psrldq XMM0, 4;
por XMM0, XMM1;
ret ;
}
I wonder if I can return an int[2] in XMM0. I can do some
modifications to either move the result to the stack first, or
add an import to core.simd (which needs to be refactored
completely) and instead make the return type int4 on SIMD enabled
CPUs.
More information about the Digitalmars-d-learn
mailing list