digitalmars.D.learn - initialize float4 (core.simd)
- Bogdan (28/28) Sep 21 2019 I'm trying to understand how to use the `core.simd`
- Bogdan (19/19) Sep 21 2019 Here's a cleaned up version:
- Bogdan (2/12) Sep 21 2019 Not sure if it's correct though.
- Stefan Koch (7/19) Sep 21 2019 float4 x;
- Bogdan (5/26) Oct 06 2019 Thank you! That also seems to be working.
- NaN (3/31) Oct 06 2019 You should probably have a look at this...
- Bogdan (4/6) Oct 06 2019 Thanks, that looks quite useful.
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?
Sep 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.
Sep 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.
Sep 21 2019
On Saturday, 21 September 2019 at 13:42:09 UTC, Bogdan wrote:Well, this seems to be working:float4 x; float x1, x2, x3, x4; x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4;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.
Sep 21 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: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. :)Well, this seems to be working:float4 x; float x1, x2, x3, x4; x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4;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.
Oct 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
Oct 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-intrinsicsThanks, that looks quite useful. Also, it seems that I need to use either LDC or GDC instead of DMD. :)
Oct 06 2019