Esempio n. 1
0
        //        A small overview of SIMD in .NET/C# / Habr
        //https://habr.com/en/post/467689/

        static unsafe void SimdAdd(byte[] a)
        {
            int simdLength     = Vector256 <byte> .Count;
            int lastIndex      = a.Length - (a.Length % simdLength);
            Vector256 <byte> v = new Vector256 <byte>();
            int i;

            fixed(byte *ptrA = a)
            {
                for (i = 0; i < lastIndex; i += simdLength)
                {
                    var vv = Avx.LoadVector256(ptrA + i);
                    v = Avx2.Add(v, vv);

                    var inu = Avx2.ConvertToVector128Int32(ptrA + i);
                    var uma = Avx2.ConvertToVector256Int32(ptrA + i);
                }
            }

            var neko   = v.ToScalar();
            int result = 0;
            var temp   = stackalloc byte[simdLength];

            Avx.Store(temp, v);
            for (int j = 0; j < simdLength; j++)
            {
                result += temp[j];
            }
            for (; i < a.Length; i++)
            {
                result += a[i];
            }
        }
Esempio n. 2
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            SByte[] values = new SByte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSByte();
            }

            Vector256<SByte> value = Vector256.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], values[11], values[12], values[13], values[14], values[15], values[16], values[17], values[18], values[19], values[20], values[21], values[22], values[23], values[24], values[25], values[26], values[27], values[28], values[29], values[30], values[31]);

            SByte result = value.ToScalar();
            ValidateResult(result, values);
        }
Esempio n. 3
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int16[] values = new Int16[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt16();
            }

            Vector256 <Int16> value = Vector256.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], values[11], values[12], values[13], values[14], values[15]);

            Int16 result = value.ToScalar();

            ValidateResult(result, values);
        }
Esempio n. 4
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Single[] values = new Single[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSingle();
            }

            Vector256 <Single> value = Vector256.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            Single result = value.ToScalar();

            ValidateResult(result, values);
        }
Esempio n. 5
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int64[] values = new Int64[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt64();
            }

            Vector256 <Int64> value = Vector256.Create(values[0], values[1], values[2], values[3]);

            Int64 result = value.ToScalar();

            ValidateResult(result, values);
        }
Esempio n. 6
0
 public static Vector256 <double> ToScalarVector256(Vector256 <double> vector)
 {
     return(Vector256.CreateScalar(vector.ToScalar()));
 }
Esempio n. 7
0
 public static ulong Add4UInt64(this Vector256 <ulong> v)
 {
     v = Avx2.Add(v, Avx2.Permute4x64(v, 0b11_10_11_10));
     v = Avx2.Add(v, Avx2.ShiftRightLogical128BitLane(v, 8));
     return(v.ToScalar());
 }