Thread overview
Adding a float with all four elements of a float4
Apr 21, 2016
Straivers
Apr 21, 2016
Nicholas Wilson
Apr 21, 2016
Nicholas Wilson
Apr 21, 2016
Straivers
Apr 21, 2016
Marco Leise
April 21, 2016
Hi,

I want to make a utility wrapper around a core.simd.float4, and have been trying to make the following code work, but have been met with no success.

auto add(float rhs)
{
    return __simd(XMM.ADDPS, lhs, rhs);
}

Then I tried

auto add(float4 lhs, float rhs)
{
    float4 tmp = [rhs, rhs, rhs, rhs];
    return __simd(XMM.ADDPS, lhs, rhs);
}

When that didn't work, I turned to IASM and threw together this:

float4 add(float4 lhs, float rhs)
{
    float4 res;
    float4 rhs_tmp = [rhs, rhs, rhs, rhs];
    auto lhs_addr = &lhs;
    auto rhs_addr = &rhs_tmp;
    asm
    {
        mov RAX, lhs_addr;
        mov RBX, rhs_addr;
        movups XMM0, [RAX];
        movups XMM1, [RBX];

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

and it still didn't work. So, what am I doing wrong?
April 21, 2016
On Thursday, 21 April 2016 at 00:14:53 UTC, Straivers wrote:
> Hi,
>
> I want to make a utility wrapper around a core.simd.float4, and have been trying to make the following code work, but have been met with no success.
>
> [...]

you want to broadcast the rhs to a float4 and then adds them. Can you post the errors (if any) you get during compilation.
April 21, 2016
On Thursday, 21 April 2016 at 01:48:15 UTC, Nicholas Wilson wrote:
> On Thursday, 21 April 2016 at 00:14:53 UTC, Straivers wrote:
>> Hi,
>>
>> I want to make a utility wrapper around a core.simd.float4, and have been trying to make the following code work, but have been met with no success.
>>
>> [...]
>
> you want to broadcast the rhs to a float4 and then adds them. Can you post the errors (if any) you get during compilation.

Urgh, autocorrect. That should be addps them.
April 21, 2016
On Thursday, 21 April 2016 at 01:49:19 UTC, Nicholas Wilson wrote:
>>> [...]
>>
>> you want to broadcast the rhs to a float4 and then adds them. Can you post the errors (if any) you get during compilation.
>
> Urgh, autocorrect. That should be addps them.

I get a "Error: floating point constant expression expected instead of rhs"
April 21, 2016
Am Thu, 21 Apr 2016 00:14:53 +0000
schrieb Straivers <straivers98@gmail.com>:

> Hi,
> 
> I want to make a utility wrapper around a core.simd.float4, and have been trying to make the following code work, but have been met with no success.
> 
> auto add(float rhs)
> {
>      return __simd(XMM.ADDPS, lhs, rhs);
> }

It seems like your are duplicating std.simd: https://github.com/TurkeyMan/simd

-- 
Marco