Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector8us.cs
index 35cf414ecdbc9cbd2a1ff7b6d6974b4e93558e79..0aa16ee49a89960db5497cb37705b346163f3f4b 100644 (file)
@@ -29,11 +29,28 @@ using System.Runtime.InteropServices;
 
 namespace Mono.Simd
 {
-       [StructLayout(LayoutKind.Sequential, Pack = 0, Size = 16)]
+       [Obsolete ("Use the types in the System.Numerics.Vectors namespace")]
+       [StructLayout(LayoutKind.Explicit, Pack = 0, Size = 16)]
        [CLSCompliant(false)]
        public struct Vector8us
        {
-               private ushort v0, v1, v2, v3, v4, v5, v6, v7;
+               [ FieldOffset(0) ]
+               internal ushort v0;
+               [ FieldOffset(2) ]
+               internal ushort v1;
+               [ FieldOffset(4) ]
+               internal ushort v2;
+               [ FieldOffset(6) ]
+               internal ushort v3;
+               [ FieldOffset(8) ]
+               internal ushort v4;
+               [ FieldOffset(10) ]
+               internal ushort v5;
+               [ FieldOffset(12) ]
+               internal ushort v6;
+               [ FieldOffset(14) ]
+               internal ushort v7;
+
                public Vector8us (ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7)
                {
                        this.v0 = v0;
@@ -45,6 +62,18 @@ namespace Mono.Simd
                        this.v6 = v6;
                        this.v7 = v7;
                }
+               
+               public Vector8us (ushort us)
+               {
+                       this.v0 = us;
+                       this.v1 = us;
+                       this.v2 = us;
+                       this.v3 = us;
+                       this.v4 = us;
+                       this.v5 = us;
+                       this.v6 = us;
+                       this.v7 = us;
+               }
 
                public ushort V0 { get { return v0; } set { v0 = value; } }
                public ushort V1 { get { return v1; } set { v1 = value; } }
@@ -55,6 +84,16 @@ namespace Mono.Simd
                public ushort V6 { get { return v6; } set { v6 = value; } }
                public ushort V7 { get { return v7; } set { v7 = value; } }
 
+               public static Vector8us Identity
+               {
+                       get { return  new Vector8us (1); }
+               }
+
+               public static Vector8us Zero
+               {
+                       get { return  new Vector8us (0); }
+               }
+
                [System.Runtime.CompilerServices.IndexerName ("Component")]
                public unsafe ushort this [int index]
                {
@@ -200,150 +239,6 @@ namespace Mono.Simd
                        return false;
                }
 
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us UnpackLow (Vector8us va, Vector8us vb)
-               {
-                       return new Vector8us (va.v0, vb.v0, va.v1, vb.v1, va.v2, vb.v2, va.v3, vb.v3);
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us UnpackHigh (Vector8us va, Vector8us vb)
-               {
-                       return new Vector8us (va.v4, vb.v4, va.v5, vb.v5, va.v6, vb.v6, va.v7, vb.v7);
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us ArithmeticRightShift (Vector8us va, int amount)
-               {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *b++ = (ushort)((short)(*a++) >> amount);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us AddWithSaturation (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) System.Math.Min (*a++ + *b++, ushort.MaxValue);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us SubtractWithSaturation (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) System.Math.Max (*a++ - *b++, 0);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us Average (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) ((*a++ + *b++ + 1) >> 1);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE41)]
-               public static unsafe Vector8us Max (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) System.Math.Max (*a++, *b++);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE41)]
-               public static unsafe Vector8us Min (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) System.Math.Min (*a++, *b++);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us ShuffleHigh (Vector8us va, ShuffleSel sel)
-               {
-                       ushort *ptr = ((ushort*)&va) + 4;
-                       int idx = (int)sel;
-                       return new Vector8us (va.v0, va.v1, va.v2, va.v3, *(ptr + ((idx >> 0) & 0x3)), *(ptr + ((idx >> 2) & 0x3)), *(ptr + ((idx >> 4) & 0x3)), *(ptr + ((idx >> 6) & 0x3)));
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us ShuffleLow (Vector8us va, ShuffleSel sel)
-               {
-                       ushort *ptr = ((ushort*)&va);
-                       int idx = (int)sel;
-                       return new Vector8us (*(ptr + ((idx >> 0) & 0x3)), *(ptr + ((idx >> 2) & 0x3)), *(ptr + ((idx >> 4) & 0x3)), *(ptr + ((idx >> 6) & 0x3)), va.v4, va.v5, va.v6, va.v7);
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us CompareEqual (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort) (*a++ == *b++ ? -1 : 0);
-                       return res;
-               }
-
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector8us MultiplyStoreHigh (Vector8us va, Vector8us vb) {
-                       Vector8us res = new Vector8us ();
-                       ushort *a = &va.v0;
-                       ushort *b = &vb.v0;
-                       ushort *c = &res.v0;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (ushort)((uint)*a++ * (uint)*b++ >> 16);
-                       return res;
-               }
-
-               /*This function performs a packuswb, which treats the source as a signed value */
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector16b SignedPackWithUnsignedSaturation (Vector8us va, Vector8us vb) {
-                       Vector16b res = new Vector16b ();
-                       short *a = (short*)&va;
-                       short *b = (short*)&vb;
-                       byte *c = (byte*)&res;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (byte)System.Math.Max (0, System.Math.Min ((int)*a++, byte.MaxValue));
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (byte)System.Math.Max (0, System.Math.Min ((int)*b++, byte.MaxValue));
-                       return res;
-               }
-
-               /*This function performs a packsswb, which treats the source as a signed value */
-               [Acceleration (AccelMode.SSE2)]
-               public static unsafe Vector16sb SignedPackWithSignedSaturation (Vector8us va, Vector8us vb) {
-                       Vector16sb res = new Vector16sb ();
-                       short *a = (short*)&va;
-                       short *b = (short*)&vb;
-                       sbyte *c = (sbyte*)&res;
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (sbyte)System.Math.Max (System.Math.Min ((int)*a++, sbyte.MaxValue), sbyte.MinValue);
-                       for (int i = 0; i < 8; ++i)
-                               *c++ = (sbyte)System.Math.Max (System.Math.Min ((int)*b++, sbyte.MaxValue), sbyte.MinValue);
-                       return res;
-               }
-
                [Acceleration (AccelMode.SSE1)]
                public static unsafe explicit operator Vector2d (Vector8us v)
                {
@@ -479,5 +374,11 @@ namespace Mono.Simd
                public static unsafe void PrefetchNonTemporal (Vector8us *res)
                {
                }
+               
+               public override string ToString()
+               {
+                       return "<" + v0 + ", " + v1 + ", " + v2 + ", " + v3 + ", " +
+                                       v4 + ", " + v5 + ", " + v6 + ", " + v7 + ">"; 
+               }
        }
 }