SSE strangeness with Functions
<p>I've been playing around with D's inline assembler and SSE, but found something I don't understand. When I try to add two float4 vectors immediately after declaration, the calculation is correct. If I put the calculation in a separate function, I get a series of <code>nan</code>s.</p>

<pre class="lang-d prettyprint-override"><code>//function contents identical to code section in unittest
float4 add(float4 lhs, float4 rhs)
{
    float4 res;
    auto lhs_addr = &amp;lhs;
    auto rhs_addr = &amp;rhs;
    asm
    {
        mov RAX, lhs_addr;
        mov RBX, rhs_addr;
        movups XMM0, [RAX];
        movups XMM1, [RBX];

        addps XMM0, XMM1;
        movups res, XMM0;
    }
    return res;
}

unittest
{
    float4 lhs = {1, 2, 3, 4};
    float4 rhs = {4, 3, 2, 1};

    println(add(lhs, rhs)); //float4(nan, nan, nan, nan)

    //identical code starts here
    float4 res;
    auto lhs_addr = &amp;lhs;
    auto rhs_addr = &amp;rhs;
    asm
    {
        mov RAX, lhs_addr;
        mov RBX, rhs_addr;
        movups XMM0, [RAX];
        movups XMM1, [RBX];

        addps XMM0, XMM1;
        movups res, XMM0;
    } //end identical code
    println(res); //float4(5, 5, 5, 5)
}
</code></pre>

<p>The assembly is functionally identical (as far as I can tell) to <a href="http://neilkemp.us/src/sse_tutorial/sse_tutorial.html" rel="nofollow">this link</a>.</p>

<p>Edit: I'm using a custom float4 struct (for now, its just an array) because I want to be able to have an add function like <code>float4 add(float4 lhs, float rhs)</code>. For the moment, that results in a compiler error like this:</p>

<blockquote>
  <p>Error: floating point constant expression expected instead of rhs</p>
</blockquote>

<p>Note: I'm using DMD 2.071.0</p>