evolvedmicrobe
evolvedmicrobe

Reputation: 2722

Flow Control with Mono.Simd SSE instructions

Does anyone how to do control flow with the Mono.Simd namespace. For example, break if all elements in a vector match some condition relative to another vector. e.g.

var y= Vector2d(1,2);
var x=Vector2d(3,4):
if(y<x)//compare less than, true for both???
//Do something…

I gather SSE has a movmskps instruction that is useful, and there are comparison functions, but they create bit masks which I am not sure how/how-best to utilize with C#.

Upvotes: 1

Views: 272

Answers (1)

Jester
Jester

Reputation: 58802

Mono provides a wrapper called ExtractByteMask that you can use for this purpose. Note that you should avoid flow control as much as possible.

var y = new Vector2d(1,2);
var x = new Vector2d(3,4);
if (VectorOperations.ExtractByteMask((Vector16sb)VectorOperations.CompareLessThan(y, x)) == 0xffff)
{
    Console.WriteLine("All components passed the comparison");
}

In case you are interested, here is a piece of the generated code:

1062:       66 0f c2 c1 01          cmpltpd %xmm1,%xmm0
1067:       66 0f d7 c0             pmovmskb %xmm0,%eax
106b:       3d ff ff 00 00          cmp    $0xffff,%eax
1070:       75 0c                   jne    107e <Sample_Main+0x5e>

Upvotes: 2

Related Questions