[msbuild] Getting build error "Error initializing task XmlPeek: Not registered task...
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector4f.cs
index 94d75f456d7e425610fe1e34af880992b3e9b72e..db7143b9b4952b293cdef1282405e012f7df392a 100644 (file)
@@ -80,25 +80,52 @@ namespace Mono.Simd
         Abs (implemented as pand [7fffffff,...] )
         Comparison functions
         Mask extraction function
-        Setters
         vector x float ops
-        Single float constructor (expand it to the 4 positions)
                Replace Shuffle with less bug prone methods
 */
 
-       [StructLayout(LayoutKind.Sequential, Pack = 0, Size = 16)]
+       [StructLayout(LayoutKind.Explicit, Pack = 0, Size = 16)]
        public struct Vector4f
        {
-               private float x;
-               private float y;
-               private float z;
-               private float w;
+               [ FieldOffset(0) ]
+               internal float x;
+               [ FieldOffset(4) ]
+               internal float y;
+               [ FieldOffset(8) ]
+               internal float z;
+               [ FieldOffset(12) ]
+               internal float w;
 
                public float X { get { return x; } set { x = value; } }
                public float Y { get { return y; } set { y = value; } }
                public float Z { get { return z; } set { z = value; } }
                public float W { get { return w; } set { w = value; } }
 
+               public static Vector4f Pi 
+               {
+                       get { return new Vector4f ((float)System.Math.PI); }
+               }
+
+               public static Vector4f E 
+               {
+                       get { return new Vector4f ((float)System.Math.E); }
+               }
+
+               public  static Vector4f One 
+               {
+                       get { return new Vector4f (1); }
+               }
+
+               public  static Vector4f Zero 
+               {
+                       get { return new Vector4f (0); }
+               }
+
+               public  static Vector4f MinusOne 
+               {
+                       get { return new Vector4f (-1); }
+               }
+
                [System.Runtime.CompilerServices.IndexerName ("Component")]
                public unsafe float this [int index]
                {
@@ -125,6 +152,14 @@ namespace Mono.Simd
                        this.z = z;
                        this.w = w;
                }
+               
+               public Vector4f (float f)
+               {
+                       this.x = f;
+                       this.y = f;
+                       this.z = f;
+                       this.w = f;
+               }
 
                [Acceleration (AccelMode.SSE1)]
                public static unsafe Vector4f operator & (Vector4f v1, Vector4f v2)
@@ -187,230 +222,33 @@ namespace Mono.Simd
                }
 
                [Acceleration (AccelMode.SSE1)]
-               public static Vector4f operator / (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static bool operator ==(Vector4f v1, Vector4f v2)
-               {
-                       return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static bool operator !=(Vector4f v1, Vector4f v2)
+               public static Vector4f operator * (float scalar, Vector4f v)
                {
-                       return v1.x != v2.x || v1.y != v2.y || v1.z != v2.z || v1.w != v2.w;
+                       return new Vector4f (scalar * v.x, scalar * v.y, scalar * v.z, scalar * v.w);
                }
 
                [Acceleration (AccelMode.SSE1)]
-               public static unsafe Vector4f AndNot (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *a = (int*)&v1;
-                       int *b = (int*)&v2;
-                       int *c = (int*)&res;
-                       *c++ = ~*a++ & *b++;
-                       *c++ = ~*a++ & *b++;
-                       *c++ = ~*a++ & *b++;
-                       *c = ~*a & *b;
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f Sqrt (Vector4f v1)
-               {
-                       return new Vector4f ((float)System.Math.Sqrt ((float)v1.x),
-                                                               (float)System.Math.Sqrt ((float)v1.y),
-                                                               (float)System.Math.Sqrt ((float)v1.z),
-                                                               (float)System.Math.Sqrt ((float)v1.w));
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f InvSqrt (Vector4f v1)
-               {
-                       return new Vector4f ((float)(1.0 / System.Math.Sqrt ((float)v1.x)),
-                                                               (float)(1.0 / System.Math.Sqrt ((float)v1.y)),
-                                                               (float)(1.0 / System.Math.Sqrt ((float)v1.z)),
-                                                               (float)(1.0 / System.Math.Sqrt ((float)v1.w)));
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f Reciprocal (Vector4f v1)
-               {
-                       return new Vector4f (1.0f / v1.x, 1.0f / v1.y, 1.0f / v1.z, 1.0f / v1.w);
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f Max (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (System.Math.Max (v1.x, v2.x),
-                                                               System.Math.Max (v1.y, v2.y),
-                                                               System.Math.Max (v1.z, v2.z),
-                                                               System.Math.Max (v1.w, v2.w));
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f Min (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (System.Math.Min (v1.x, v2.x),
-                                                               System.Math.Min (v1.y, v2.y),
-                                                               System.Math.Min (v1.z, v2.z),
-                                                               System.Math.Min (v1.w, v2.w));
-               }
-
-               [Acceleration (AccelMode.SSE3)]
-               public static Vector4f HorizontalAdd (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (v1.x + v1.y, v1.z + v1.w, v2.x + v2.y, v2.z + v2.w);
-               }
-
-               [Acceleration (AccelMode.SSE3)]
-               public static Vector4f AddSub (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (v1.x - v2.x, v1.y + v2.y, v1.z - v2.z, v1.w + v2.w);
-               }
-
-               [Acceleration (AccelMode.SSE3)]
-               public static Vector4f HorizontalSub (Vector4f v1, Vector4f v2)
+               public static Vector4f operator * (Vector4f v, float scalar)
                {
-                       return new Vector4f (v1.x - v1.y, v1.z - v1.w, v2.x - v2.y, v2.z - v2.w);
+                       return new Vector4f (scalar * v.x, scalar * v.y, scalar * v.z, scalar * v.w);
                }
 
                [Acceleration (AccelMode.SSE1)]
-               public static Vector4f InterleaveHigh (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (v1.z, v2.z, v1.w, v2.w);
-               }
-
-               [Acceleration (AccelMode.SSE1)]
-               public static Vector4f InterleaveLow (Vector4f v1, Vector4f v2)
-               {
-                       return new Vector4f (v1.x, v2.x, v1.y, v2.y);
-               }
-
-               /*Same as a == b. */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareEqual (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x == v2.x ? -1 : 0;
-                       *c++ = v1.y == v2.y ? -1 : 0;
-                       *c++ = v1.z == v2.z ? -1 : 0;
-                       *c = v1.w == v2.w ? -1 : 0;
-                       return res;             }
-
-               /*Same as a < b. */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareLessThan (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x < v2.x ? -1 : 0;
-                       *c++ = v1.y < v2.y ? -1 : 0;
-                       *c++ = v1.z < v2.z ? -1 : 0;
-                       *c = v1.w < v2.w ? -1 : 0;
-                       return res;
-               }
-
-               /*Same as a <= b. */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareLessEqual (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x <= v2.x ? -1 : 0;
-                       *c++ = v1.y <= v2.y ? -1 : 0;
-                       *c++ = v1.z <= v2.z ? -1 : 0;
-                       *c = v1.w <= v2.w ? -1 : 0;
-                       return res;             }
-
-               /*Same float.IsNaN (a) || float.IsNaN (b). */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareUnordered (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = float.IsNaN (v1.x) || float.IsNaN (v2.x) ? -1 : 0;
-                       *c++ = float.IsNaN (v1.y) || float.IsNaN (v2.y) ? -1 : 0;
-                       *c++ = float.IsNaN (v1.z) || float.IsNaN (v2.z) ? -1 : 0;
-                       *c = float.IsNaN (v1.w) || float.IsNaN (v2.w) ? -1 : 0;
-                       return res;             }
-
-               /*Same as a != b. */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareNotEqual (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x != v2.x ? -1 : 0;
-                       *c++ = v1.y != v2.y ? -1 : 0;
-                       *c++ = v1.z != v2.z ? -1 : 0;
-                       *c = v1.w != v2.w ? -1 : 0;
-                       return res;
-               }
-
-               /*Same as !(a < b). */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareNotLessThan (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x < v2.x ? 0 : -1;
-                       *c++ = v1.y < v2.y ? 0 : -1;
-                       *c++ = v1.z < v2.z ? 0 : -1;
-                       *c = v1.w < v2.w ? 0 : -1;
-                       return res;
-               }
-
-               /*Same as !(a <= b). */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareNotLessEqual (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = v1.x <= v2.x ? 0 : -1;
-                       *c++ = v1.y <= v2.y ? 0 : -1;
-                       *c++ = v1.z <= v2.z ? 0 : -1;
-                       *c = v1.w <= v2.w ? 0 : -1;
-                       return res;
-               }
-
-               /*Same !float.IsNaN (a) && !float.IsNaN (b). */
-               [Acceleration (AccelMode.SSE1)]
-               public unsafe static Vector4f CompareOrdered (Vector4f v1, Vector4f v2)
-               {
-                       Vector4f res = new Vector4f ();
-                       int *c = (int*)&res;
-                       *c++ = !float.IsNaN (v1.x) && !float.IsNaN (v2.x) ? -1 : 0;
-                       *c++ = !float.IsNaN (v1.y) && !float.IsNaN (v2.y) ? -1 : 0;
-                       *c++ = !float.IsNaN (v1.z) && !float.IsNaN (v2.z) ? -1 : 0;
-                       *c = !float.IsNaN (v1.w) && !float.IsNaN (v2.w) ? -1 : 0;
-                       return res;             }
-
-               [Acceleration (AccelMode.SSE3)]
-               public static Vector4f DuplicateLow (Vector4f v1)
+               public static Vector4f operator / (Vector4f v1, Vector4f v2)
                {
-                       return new Vector4f (v1.x, v1.x, v1.z, v1.z);
+                       return new Vector4f (v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
                }
 
-               [Acceleration (AccelMode.SSE3)]
-               public static Vector4f DuplicateHigh (Vector4f v1)
+               [Acceleration (AccelMode.SSE2)]
+               public static bool operator ==(Vector4f v1, Vector4f v2)
                {
-                       return new Vector4f (v1.y, v1.y, v1.w, v1.w);
+                       return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
                }
 
-               /*
-               The sel argument must be a value combination of ShuffleSel flags.
-               */
                [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector4f Shuffle (Vector4f v1, ShuffleSel sel)
+               public static bool operator !=(Vector4f v1, Vector4f v2)
                {
-                       float *ptr = (float*)&v1;
-                       int idx = (int)sel;
-                       return new Vector4f (*(ptr + ((idx >> 0) & 0x3)),*(ptr + ((idx >> 2) & 0x3)),*(ptr + ((idx >> 4) & 0x3)),*(ptr + ((idx >> 6) & 0x3)));
+                       return v1.x != v2.x || v1.y != v2.y || v1.z != v2.z || v1.w != v2.w;
                }
 
                [Acceleration (AccelMode.SSE1)]
@@ -553,5 +391,10 @@ namespace Mono.Simd
                public static unsafe void PrefetchNonTemporal (Vector4f *res)
                {
                }
+               
+               public override string ToString()
+               {
+                       return "<" + x + ", " + y + ", " + z + ", " + w + ">"; 
+               }
        }
 }