Merge pull request #4453 from lambdageek/bug-49721
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector2l.cs
index e36a8c3492b46f3aa0e071c90853919f843f7397..a08d06d14e357628c7023d96d62f28c277d7e865 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-using System;\r
-using System.Runtime.InteropServices;\r
-\r
-namespace Mono.Simd\r
-{\r
-       [StructLayout(LayoutKind.Sequential, Pack = 0, Size = 16)]\r
-       public struct Vector2l\r
-       {\r
-               private long x;\r
-               private long y;\r
-\r
-               public long X { get { return x; } set { x = value; } }\r
-               public long Y { get { return y; } set { y = value; } }\r
-\r
-               public Vector2l (long x, long y)\r
-               {\r
-                       this.x = x;\r
-                       this.y = y;\r
+using System;
+using System.Runtime.InteropServices;
+
+namespace Mono.Simd
+{
+       [Obsolete ("Use the types in the System.Numerics.Vectors namespace")]
+       [StructLayout(LayoutKind.Explicit, Pack = 0, Size = 16)]
+       public struct Vector2l
+       {
+               [ FieldOffset(0) ]
+               internal long x;
+               [ FieldOffset(8) ]
+               internal long y;
+
+               public long X { get { return x; } set { x = value; } }
+               public long Y { get { return y; } set { y = value; } }
+
+               public static Vector2l One
+               {
+                       get { return new Vector2l (1); }
+               }
+
+               public static Vector2l Zero
+               {
+                       get { return new Vector2l (0); }
+               }
+
+               public static Vector2l MinusOne
+               {
+                       get { return new Vector2l (-1); }
+               }
+
+               [System.Runtime.CompilerServices.IndexerName ("Component")]
+               public unsafe long this [int index]
+               {
+                       get {
+                               if ((index | 0x1) != 0x1) //index < 0 || index > 1
+                                       throw new ArgumentOutOfRangeException ("index");
+                               fixed (long *v = &x) {
+                                       return * (v + index);
+                               }
+                       }
+                       set {
+                               if ( (index | 0x1) != 0x1) //index < 0 || index > 1
+                                       throw new ArgumentOutOfRangeException ("index");
+                               fixed (long *v = &x) {
+                                       * (v + index) = value;
+                               }
+                       }
+               }
+
+               public Vector2l (long x, long y)
+               {
+                       this.x = x;
+                       this.y = y;
+               }
+
+               public Vector2l (long l)
+               {
+                       this.x = l;
+                       this.y = l;
                }
 
-               //PADDQ
-               public static Vector2l operator + (Vector2l v1, Vector2l v2)\r
-               {\r
-                       return new Vector2l (v1.x + v2.x, v1.y + v2.y);\r
+               [Acceleration (AccelMode.SSE2)]
+               public static Vector2l operator + (Vector2l v1, Vector2l v2)
+               {
+                       return new Vector2l (v1.x + v2.x, v1.y + v2.y);
                }
 
-               //PSUBQ
-               public static Vector2l operator - (Vector2l v1, Vector2l v2)\r
-               {\r
-                       return new Vector2l (v1.x - v2.x, v1.y - v2.y);\r
+               [Acceleration (AccelMode.SSE2)]
+               public static Vector2l operator - (Vector2l v1, Vector2l v2)
+               {
+                       return new Vector2l (v1.x - v2.x, v1.y - v2.y);
                }
 
-               public static unsafe Vector2l operator << (Vector2l v1, int amount)\r
-               {\r
-                       return new Vector2l (v1.x << amount, v1.y << amount);\r
+               [Acceleration (AccelMode.SSE2)]
+               public static unsafe Vector2l operator << (Vector2l v1, int amount)
+               {
+                       return new Vector2l (v1.x << amount, v1.y << amount);
                }
 
-               public static Vector2l operator & (Vector2l v1, Vector2l v2)\r
-               {\r
-                       return new Vector2l (v1.x & v2.x, v1.y & v2.y);\r
+               [Acceleration (AccelMode.SSE2)]
+               public static Vector2l operator & (Vector2l v1, Vector2l v2)
+               {
+                       return new Vector2l (v1.x & v2.x, v1.y & v2.y);
                }
 
-               public static Vector2l operator | (Vector2l v1, Vector2l v2)\r
-               {\r
-                       return new Vector2l (v1.x | v2.x, v1.y | v2.y);\r
-               }\r
-\r
-               public static Vector2l operator ^ (Vector2l v1, Vector2l v2)\r
-               {\r
-                       return new Vector2l (v1.x ^ v2.x, v1.y ^ v2.y);\r
-               }\r
+               [Acceleration (AccelMode.SSE2)]
+               public static Vector2l operator | (Vector2l v1, Vector2l v2)
+               {
+                       return new Vector2l (v1.x | v2.x, v1.y | v2.y);
+               }
 
-               public static Vector2l UnpackLow (Vector2l v1, Vector2l v2)
+               [Acceleration (AccelMode.SSE2)]
+               public static Vector2l operator ^ (Vector2l v1, Vector2l v2)
                {
-                       return new Vector2l (v1.x, v2.x);
+                       return new Vector2l (v1.x ^ v2.x, v1.y ^ v2.y);
                }
 
-               public static Vector2l UnpackHigh (Vector2l v1, Vector2l v2)
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe explicit operator Vector2d (Vector2l v)
                {
-                       return new Vector2l (v1.y, v2.y);
+                       Vector2d* p = (Vector2d*)&v;
+                       return *p;
                }
 
-               public static unsafe Vector2l ShiftRightLogic (Vector2l v1, int amount)\r
-               {\r
-                       Vector2l res = new Vector2l ();
-                       long *a = &v1.x;
-                       long *b = &res.x;
-                       for (int i = 0; i < 4; ++i)
-                               *b++ = (long)((ulong)(*a++) >> amount);
-                       return res;\r
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe explicit operator Vector4f (Vector2l v)
+               {
+                       Vector4f* p = (Vector4f*)&v;
+                       return *p;
                }
 
-               public static unsafe long ExtractByteMask (Vector2l va) {
-                       int res = 0;
-                       byte *a = (byte*)&va;
-                       for (int i = 0; i < 16; ++i)
-                               res |= (*a++ & 0x80) >> 7 << i;
-                       return res;
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe explicit operator Vector2ul (Vector2l v)
+               {
+                       Vector2ul* p = (Vector2ul*)&v;
+                       return *p;
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe explicit operator Vector4i (Vector2l v)
+               {
+                       Vector4i* p = (Vector4i*)&v;
+                       return *p;
                }
 
-               /*Requires SSE 4.1*/
-               public static Vector2l CompareEqual (Vector2l v1, Vector2l v2)
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe explicit operator Vector4ui (Vector2l v)
                {
-                       return new Vector2l ((long)(v1.x ==  v2.x ? -1 : 0), (long)(v1.y ==  v2.y ? -1 : 0));
+                       Vector4ui* p = (Vector4ui*)&v;
+                       return *p;
                }
 
-               /*Requires SSE 4.1*/
-               public static Vector2l CompareGreaterThan (Vector2l v1, Vector2l v2)
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe explicit operator Vector8s (Vector2l v)
                {
-                       return new Vector2l ((long)(v1.x > v2.x ? -1 : 0), (long)(v1.y >  v2.y ? -1 : 0));
+                       Vector8s* p = (Vector8s*)&v;
+                       return *p;
                }
 
-               public static unsafe explicit operator Vector4f (Vector2l v1)\r
-               {\r
-                       Vector4f* p = (Vector4f*)&v1;\r
-                       return *p;\r
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe explicit operator Vector8us (Vector2l v)
+               {
+                       Vector8us* p = (Vector8us*)&v;
+                       return *p;
                }
 
-               [CLSCompliant(false)]\r
-               public static unsafe explicit operator Vector8us (Vector2l v1)\r
-               {\r
-                       Vector8us* p = (Vector8us*)&v1;\r
-                       return *p;\r
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe explicit operator Vector16sb (Vector2l v)
+               {
+                       Vector16sb* p = (Vector16sb*)&v;
+                       return *p;
                }
 
-               [CLSCompliant(false)]\r
-               public static unsafe explicit operator Vector16b (Vector2l v1)\r
-               {\r
-                       Vector16b* p = (Vector16b*)&v1;\r
-                       return *p;\r
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe explicit operator Vector16b (Vector2l v)
+               {
+                       Vector16b* p = (Vector16b*)&v;
+                       return *p;
                }
 
-               public static Vector2l LoadAligned (ref Vector2l v)\r
-               {\r
-                       return v;\r
-               }\r
-\r
-               public static void StoreAligned (ref Vector2l res, Vector2l val)\r
-               {\r
-                       res = val;\r
+               [Acceleration (AccelMode.SSE1)]
+               public static Vector2l LoadAligned (ref Vector2l v)
+               {
+                       return v;
                }
 
-               [CLSCompliant(false)]\r
-               public static unsafe Vector2l LoadAligned (Vector2l *v)\r
-               {\r
-                       return *v;\r
-               }\r
-\r
-               [CLSCompliant(false)]\r
-               public static unsafe void StoreAligned (Vector2l *res, Vector2l val)\r
-               {\r
-                       *res = val;\r
+               [Acceleration (AccelMode.SSE1)]
+               public static void StoreAligned (ref Vector2l res, Vector2l val)
+               {
+                       res = val;
+               }
+
+               [CLSCompliant(false)]
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe Vector2l LoadAligned (Vector2l *v)
+               {
+                       return *v;
+               }
+
+               [CLSCompliant(false)]
+               [Acceleration (AccelMode.SSE1)]
+               public static unsafe void StoreAligned (Vector2l *res, Vector2l val)
+               {
+                       *res = val;
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static void PrefetchTemporalAllCacheLevels (ref Vector2l res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static void PrefetchTemporal1stLevelCache (ref Vector2l res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static void PrefetchTemporal2ndLevelCache (ref Vector2l res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static void PrefetchNonTemporal (ref Vector2l res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe void PrefetchTemporalAllCacheLevels (Vector2l *res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe void PrefetchTemporal1stLevelCache (Vector2l *res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe void PrefetchTemporal2ndLevelCache (Vector2l *res)
+               {
+               }
+
+               [Acceleration (AccelMode.SSE1)]
+               [CLSCompliant(false)]
+               public static unsafe void PrefetchNonTemporal (Vector2l *res)
+               {
+               }
+               
+               public override string ToString()
+               {
+                       return "<" + x + ", " + y + ">"; 
                }
-       }\r
-}\r
+       }
+}