SSE asm with functions
Timon Gehr
timon.gehr at gmx.ch
Wed Jun 15 13:29:04 PDT 2011
Byron wrote:
> In the attached file xmm.d I have a function xnormal that takes a vector ( alias
float[4] ) an computes the
> unit vector. The SSE code seems to work fine, but it keeps returning [nan, nan,
nan, nan ] and the
> writeln prints the same. But if I change the return from r ( output vector ) to
v ( input vector ) it prints
> the correct normal vector, and returns the input vector. Is this my bug or a
compiler bug?
> DMD32 v2.053 OS X
>
> const(vector) xnormal( ref const(vector) v )
> {
> vector r;
> asm
> {
> mov EAX, v;
> movups XMM0, [EAX]; //load vector
> movaps XMM2, XMM0; // copy original data
>
> // find x^2 + y^2 + z^2 + w^2
> mulps XMM0, XMM0; // xx, yy, zz, ww
> movaps XMM1, XMM0; // copy, cause we will write into X0
> shufps XMM0, XMM1, 0x4e; // 0100 1110 zwxy
> addps XMM0, XMM1; // xyzw + zwxy
>
> movaps XMM1, XMM0; // copy, cause we will write into X0
> shufps XMM0, XMM1, 0x11; // 0001 0001 (y+w)(x+z)(y+w)(x+z)
> addps XMM0, XMM1; // (x+z)(y+w)(z+x)(w+y) + (y+w)(x+z)(y+w)(x+z)
> // (x+z+y+w)(y+w+x+z)(z+x+y+w)(w+y+x+z)
>
> rsqrtps XMM0, XMM0; // 1/sqrt(XMM0)
> mulps XMM2, XMM0; // x/sqrt(x^2+y^2+z^2+w^2) , ...
> movups r, XMM2;
> }
> writeln( "Result: ", r, "\t", v );
> return r;
> }
>
> I would like to use D for a thesis projects, but wont be able to if its still
this buggy.
>
> -Byron
> << xmm.d >>
It seems it is a backend bug in DMD as the same code works just fine with GDC.
(frontend version 2.052 though, this might need some further investigation).
Timon
More information about the Digitalmars-d
mailing list