Thread overview
initialize float4 (core.simd)
Sep 21, 2019
Bogdan
Sep 21, 2019
Bogdan
Sep 21, 2019
Bogdan
Sep 21, 2019
Stefan Koch
Oct 06, 2019
Bogdan
Oct 06, 2019
NaN
Oct 06, 2019
Bogdan
September 21, 2019
I'm trying to understand how to use the `core.simd` functionality, and I'm having trouble initializing a float4 vector.

Here's my example code:

```
import std.stdio;
import core.simd;

void main()
{
  float[4] values = [1.0f, 2.0f, 3.0f, 4.0f];
  float delta = 15.0f;

  writeln(doSimd(values, delta));

}

float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;
  float4 v_values = values;

  // ... do SIMD ...

  return [v_delta[0], v_delta[0],v_delta[0],v_delta[0]];
}
```

Compilation is failing with the following error:

```
source/app.d(16,21): Error: cannot implicitly convert expression values of type float[4] to __vector(float[4])
dmd failed with exit code 1.
```
How do you initialize a float4 with some useful data?


September 21, 2019
Here's a cleaned up version:

```
import std.stdio;
import core.simd;

void main()
{
  float[4] values = [1.0f, 2.0f, 3.0f, 4.0f];
  float delta = 15.0f;

  writeln(doSimd(values, delta));

}

float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;
  float4 v_values = values;

  v_values = __simd(XMM.ADDPS, v_values, v_delta);

  return [v_values[0], v_values[1],v_values[2],v_values[3]];
}
```

The problem is with initializing v_values.
September 21, 2019
Well, this seems to be working:

> float[4] doSimd(float[4] values, float delta)
> {
>   float4 v_delta = delta;
> 
>   float4 v_values = __simd(XMM.ADDPS,
>                            __simd(XMM.LODAPS, values[0]),
>                            v_delta);
> 
>   return [v_values[0], v_values[1],v_values[2],v_values[3]];
> }

Not sure if it's correct though.
September 21, 2019
On Saturday, 21 September 2019 at 13:42:09 UTC, Bogdan wrote:
> Well, this seems to be working:
>
>> float[4] doSimd(float[4] values, float delta)
>> {
>>   float4 v_delta = delta;
>> 
>>   float4 v_values = __simd(XMM.ADDPS,
>>                            __simd(XMM.LODAPS, values[0]),
>>                            v_delta);
>> 
>>   return [v_values[0], v_values[1],v_values[2],v_values[3]];
>> }
>
> Not sure if it's correct though.

float4 x;
float x1, x2, x3, x4;
x[0] = x1;
x[1] = x2;
x[2] = x3;
x[3] = x4;

October 06, 2019
On Saturday, 21 September 2019 at 14:31:15 UTC, Stefan Koch wrote:
> On Saturday, 21 September 2019 at 13:42:09 UTC, Bogdan wrote:
>> Well, this seems to be working:
>>
>>> float[4] doSimd(float[4] values, float delta)
>>> {
>>>   float4 v_delta = delta;
>>> 
>>>   float4 v_values = __simd(XMM.ADDPS,
>>>                            __simd(XMM.LODAPS, values[0]),
>>>                            v_delta);
>>> 
>>>   return [v_values[0], v_values[1],v_values[2],v_values[3]];
>>> }
>>
>> Not sure if it's correct though.
>
> float4 x;
> float x1, x2, x3, x4;
> x[0] = x1;
> x[1] = x2;
> x[2] = x3;
> x[3] = x4;

Thank you! That also seems to be working.
Turns out that using this method for drawing a rectangle is about twice as slow than a naive implementation, so I'm almost certainly doing something silly/wrong. :)
October 06, 2019
On Saturday, 21 September 2019 at 12:50:46 UTC, Bogdan wrote:
> I'm trying to understand how to use the `core.simd` functionality, and I'm having trouble initializing a float4 vector.
>
> Here's my example code:
>
> ```
> import std.stdio;
> import core.simd;
>
> void main()
> {
>   float[4] values = [1.0f, 2.0f, 3.0f, 4.0f];
>   float delta = 15.0f;
>
>   writeln(doSimd(values, delta));
>
> }
>
> float[4] doSimd(float[4] values, float delta)
> {
>   float4 v_delta = delta;
>   float4 v_values = values;
>
>   // ... do SIMD ...
>
>   return [v_delta[0], v_delta[0],v_delta[0],v_delta[0]];
> }
> ```
>
> Compilation is failing with the following error:
>
> ```
> source/app.d(16,21): Error: cannot implicitly convert expression values of type float[4] to __vector(float[4])
> dmd failed with exit code 1.
> ```
> How do you initialize a float4 with some useful data?

You should probably have a look at this...

https://github.com/AuburnSounds/intel-intrinsics


October 06, 2019
On Sunday, 6 October 2019 at 11:53:29 UTC, NaN wrote:
>
> You should probably have a look at this...
>
> https://github.com/AuburnSounds/intel-intrinsics

Thanks, that looks quite useful.
Also, it seems that I need to use either LDC or GDC instead of DMD. :)