static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float, int> floatTable = new TestTable <float, int>(new float[4] { 1, float.NaN, float.PositiveInfinity, float.NegativeInfinity }, new int[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); var vf2 = Sse.StaticCast <float, int>(vf1); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == y)) { Console.WriteLine("SSE StaticCast failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { float.NaN, float.NaN, float.NaN, float.NaN })) { var vf1 = Sse.SetScalar(3); Unsafe.Write(floatTable.outArrayPtr, vf1); if (!floatTable.CheckResult((x) => (x[0] == 3) && (BitConverter.SingleToInt32Bits(x[1]) == 0) && (BitConverter.SingleToInt32Bits(x[2]) == 0) && (BitConverter.SingleToInt32Bits(x[3]) == 0))) { Console.WriteLine("SSE SetScalar failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); var vf2 = Sse.Sqrt(vf1); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y) => { var expected = MathF.Sqrt(x); return((expected == y) || (float.IsNaN(expected) && float.IsNaN(y))); })) { Console.WriteLine("SSE Sqrt failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4])) { var vf = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); Sse.Store((float *)(floatTable.outArrayPtr), vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y))) { Console.WriteLine("SSE Store failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <double> doubleTable = new TestTable <double>(new double[2] { double.NaN, double.NaN, })) { var vf1 = Sse2.SetScalarVector128(3); Unsafe.Write(doubleTable.outArrayPtr, vf1); if (!doubleTable.CheckResult((x) => (x[0] == 3) && (BitConverter.DoubleToInt64Bits(x[1]) == 0))) { Console.WriteLine("SSE2 SetScalarVector128 failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Sse.LoadHigh(vf1, (float *)(floatTable.inArray2Ptr)); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y, z) => z[0] == x[0] && z[1] == x[1] && z[2] == y[0] && z[3] == y[1])) { Console.WriteLine("SSE LoadHigh failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 3 }, new float[4])) { var vf = Sse.LoadScalarVector128((float *)(floatTable.inArrayPtr)); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x[0]) == BitConverter.SingleToInt32Bits(y[0]) && BitConverter.SingleToInt32Bits(y[1]) == 0 && BitConverter.SingleToInt32Bits(y[2]) == 0 && BitConverter.SingleToInt32Bits(y[3]) == 0)) { Console.WriteLine("SSE LoadScalarVector128 failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 3 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.MinScalar(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => (z[0] == MathF.Min(x[0], y[0])) && (z[1] == x[1]) && (z[2] == x[2]) && (z[3] == x[3]))) { Console.WriteLine("SSE MinScalar failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 3 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.CompareNotGreaterThanOrEqualScalar(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => (BitConverter.SingleToInt32Bits(z[0]) == (!(x[0] >= y[0]) ? -1 : 0)) && (z[1] == x[1]) && (z[2] == x[2]) && (z[3] == x[3]))) { Console.WriteLine("SSE CompareNotGreaterThanOrEqualScalar failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <double> doubleTable = new TestTable <double>(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) { var vf1 = Unsafe.Read <Vector128 <double> >(doubleTable.inArray1Ptr); var vf2 = Sse2.LoadHigh(vf1, (double *)(doubleTable.inArray2Ptr)); Unsafe.Write(doubleTable.outArrayPtr, vf2); if (!doubleTable.CheckResult((x, y, z) => z[0] == x[0] && z[1] == y[0])) { Console.WriteLine("SSE2 LoadHigh failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4])) using (TestTable <double> doubleTable = new TestTable <double>(new double[2] { -11, 7 }, new double[2])) { var vd0 = Unsafe.Read <Vector128 <double> >(doubleTable.inArrayPtr); var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); var vf2 = Sse2.ConvertScalarToVector128Single(vf1, vd0); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y) => (y[0] == -11) && (y[1] == x[1]) && (y[2] == x[2]) && (y[3] == x[3]))) { Console.WriteLine("SSE ConvertScalarToVector128Single failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { float.NaN, float.NaN, float.NaN, float.NaN })) { var vf1 = Sse.SetVector128(1, -5, 100, 0); Unsafe.Write(floatTable.outArrayPtr, vf1); if (!floatTable.CheckResult((x) => (x[0] == 0) && (x[1] == 100) && (x[2] == -5) && (x[3] == 1))) { Console.WriteLine("SSE SetVector128 failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <int> intTable = new TestTable <int>(new int[4] { 1, -5, 7, 19 }, new int[4])) { var vf1 = Unsafe.Read <Vector128 <int> >(intTable.inArrayPtr); var vf2 = Sse2.ConvertScalarToVector128Int32(5); Unsafe.Write(intTable.outArrayPtr, vf2); if (!intTable.CheckResult((x, y) => (y[0] == 5) && (y[1] == 0) && (y[2] == 0) && (y[3] == 0))) { Console.WriteLine("SSE2 ConvertScalarToVector128Int32 failed on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4])) { var vf = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); Sse.StoreHigh((float *)(floatTable.outArrayPtr), vf); if (!floatTable.CheckResult((x, y) => y[0] == x[2] && y[1] == x[3] && y[2] == 0 && y[3] == 0)) { Console.WriteLine("SSE StoreHigh failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 1, -5, 100, 0, 1, 2, 3, 4 }, new float[4])) { var vf = Avx.BroadcastScalarToVector128((float *)(floatTable.inArrayPtr)); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y))) { Console.WriteLine("AVX BroadcastScalarToVector128 failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8])) using (TestTable <double> doubleTable = new TestTable <double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) { var vf1 = Unsafe.Read <Vector256 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector256 <float> >(floatTable.inArray2Ptr); var vf3 = Avx.UnpackLow(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((left, right, result) => (left[0] == result[0]) && (right[0] == result[1]) && (left[1] == result[2]) && (right[1] == result[3]) && (left[4] == result[4]) && (right[4] == result[5]) && (left[5] == result[6]) && (right[5] == result[7]))) { Console.WriteLine("Avx UnpackLow failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } var vd1 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray1Ptr); var vd2 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray2Ptr); var vd3 = Avx.UnpackLow(vd1, vd2); Unsafe.Write(doubleTable.outArrayPtr, vd3); if (!doubleTable.CheckResult((left, right, result) => (left[0] == result[0]) && (right[0] == result[1]) && (left[2] == result[2]) && (right[2] == result[3]))) { Console.WriteLine("Avx UnpackLow failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <double> doubleTable = new TestTable <double>(new double[2] { 1, -5 }, new double[2])) { var vf = Unsafe.Read <Vector128 <double> >(doubleTable.inArrayPtr); Sse2.StoreLow((double *)(doubleTable.outArrayPtr), vf); if (!doubleTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x[0]) == BitConverter.DoubleToInt64Bits(y[0]) && BitConverter.DoubleToInt64Bits(y[1]) == 0)) { Console.WriteLine("Sse2 StoreLow failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, float.NaN }, new float[4] { 22, -1, -50, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.CompareUnordered(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => BitConverter.SingleToInt32Bits(z) == ((float.IsNaN(x) || float.IsNaN(y)) ? -1 : 0))) { Console.WriteLine("SSE CompareUnordered failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.Subtract(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => x - y == z)) { Console.WriteLine("SSE Subtract failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.Add(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE Add failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf3 = (Vector128 <float>) typeof(Sse).GetMethod(nameof(Sse.Add), new Type[] { vf1.GetType(), vf2.GetType() }).Invoke(null, new object[] { vf1, vf2 }); Unsafe.Write(floatTable.outArrayPtr, vf3); if (!floatTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE Add failed via reflection on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <byte> byteTable = new TestTable <byte>(new byte[16] { 255, 2, 0, 80, 0, 7, 0, 1, 2, 7, 80, 0, 123, 127, 5, 255 }, new byte[16] { 255, 0, 255, 0, 255, 0, 255, 0, 0, 255, 0, 255, 0, 255, 0, 255 }, new byte[16])) { Unsafe.Write(byteTable.outArrayPtr, Sse2.SetZeroVector128 <byte>()); var vf1 = Unsafe.Read <Vector128 <byte> >(byteTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <byte> >(byteTable.inArray2Ptr); Sse2.MaskMove(vf1, vf2, (byte *)(byteTable.outArrayPtr)); if (!byteTable.CheckResult((left, right, result) => result == (((right & 128) != 0) ? left : 0))) { Console.WriteLine("SSE MaskMove failed on byte:"); foreach (var item in byteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <sbyte> sbyteTable = new TestTable <sbyte>(new sbyte[16] { -1, 2, 0, 6, 0, 7, 111, 1, 2, 55, 80, 0, 11, 127, 5, -9 }, new sbyte[16] { -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, -1 }, new sbyte[16])) { Unsafe.Write(sbyteTable.outArrayPtr, Sse2.SetZeroVector128 <sbyte>()); var vf1 = Unsafe.Read <Vector128 <sbyte> >(sbyteTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <sbyte> >(sbyteTable.inArray2Ptr); Sse2.MaskMove(vf1, vf2, (sbyte *)(sbyteTable.outArrayPtr)); if (!sbyteTable.CheckResult((left, right, result) => result == (((right & -128) != 0) ? left : 0))) { Console.WriteLine("SSE MaskMove failed on sbyte:"); foreach (var item in sbyteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8])) using (TestTable <double> doubleTable = new TestTable <double>(new double[4] { 1, -5, 100, 0 }, new double[4])) { var vf1 = Unsafe.Read <Vector256 <float> >(floatTable.inArrayPtr); var vf2 = Avx.Sqrt(vf1); Unsafe.Write(floatTable.outArrayPtr, vf2); var vd1 = Unsafe.Read <Vector256 <double> >(doubleTable.inArrayPtr); var vd2 = Avx.Sqrt(vd1); Unsafe.Write(doubleTable.outArrayPtr, vd2); if (!floatTable.CheckResult((x, y) => { var expected = MathF.Sqrt(x); return((expected == y) || (float.IsNaN(expected) && float.IsNaN(y))); })) { Console.WriteLine("Avx Sqrt failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!doubleTable.CheckResult((x, y) => { var expected = Math.Sqrt(x); return((expected == y) || (double.IsNaN(expected) && double.IsNaN(y))); })) { Console.WriteLine("Avx Sqrt failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float, int> floatTable = new TestTable <float, int>(new float[4] { 1, float.NaN, float.PositiveInfinity, float.NegativeInfinity }, new int[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); var vf2 = Sse.StaticCast <float, int>(vf1); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == y)) { Console.WriteLine("SSE StaticCast failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } // the successful path is the one that catches the exception, so that does nothing, // it is the fall-through path that's the error path try { var v = Sse.StaticCast <float, Num>(vf1); Unsafe.Write(floatTable.outArrayPtr, v); Console.WriteLine("SSE StaticCast failed on target type test:"); testResult = Fail; } catch (System.NotSupportedException) { } // the successful path is the one that catches the exception, so that does nothing, // it is the fall-through path that's the error path try { var v = TestSrcType(); Unsafe.Write(floatTable.outArrayPtr, v); Console.WriteLine("SSE StaticCast failed on source type test:"); testResult = Fail; } catch (System.NotSupportedException) { } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8])) using (TestTable <double> doubleTable = new TestTable <double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) { var vf1 = Unsafe.Read <Vector256 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector256 <float> >(floatTable.inArray2Ptr); var vf3 = Avx.Add(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); var vd1 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray1Ptr); var vd2 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray2Ptr); var vd3 = Avx.Add(vd1, vd2); Unsafe.Write(doubleTable.outArrayPtr, vd3); if (!floatTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX Add failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!doubleTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX Add failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse2.IsSupported) { using (TestTable <long> longTable = new TestTable <long>(new long[2] { 1, -5 }, new long[2])) { if (Environment.Is64BitProcess) { var vd = Sse2.ConvertScalarToVector128Int64((long)-5); Unsafe.Write(longTable.outArrayPtr, vd); if (!longTable.CheckResult((x, y) => (y[0] == -5) && (y[1] == 0))) { Console.WriteLine("SSE2 ConvertScalarToVector128Int32 failed on long:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } else { try { var vd = Sse2.ConvertScalarToVector128Int64(-5l); testResult = Fail; Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.ConvertScalarToVector128Int64)} failed: expected PlatformNotSupportedException exception."); } catch (PlatformNotSupportedException) { } catch (Exception ex) { testResult = Fail; Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.ConvertScalarToVector128Int64)}-{ex} failed: expected PlatformNotSupportedException exception."); } } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; using (TestTable <ulong> ulongTable = new TestTable <ulong>(new ulong[2], new ulong[2])) { if (Sse2.X64.IsSupported) { var vd = Sse2.X64.ConvertScalarToVector128UInt64(0xffffffff01ul); Unsafe.Write(ulongTable.outArrayPtr, vd); if (!ulongTable.CheckResult((x, y) => (y[0] == 0xffffffff01ul) && (y[1] == 0))) { Console.WriteLine("SSE2.X64 ConvertScalarToVector128Single failed on ulong:"); foreach (var item in ulongTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } else { try { var vd = Sse2.X64.ConvertScalarToVector128UInt64((ulong)5); testResult = Fail; Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.X64.ConvertScalarToVector128UInt64)} failed: expected PlatformNotSupportedException exception."); } catch (PlatformNotSupportedException) { } catch (Exception ex) { testResult = Fail; Console.WriteLine($"{nameof(Sse2)}.{nameof(Sse2.X64.ConvertScalarToVector128UInt64)}-{ex} failed: expected PlatformNotSupportedException exception."); } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Sse.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArrayPtr); var vf2 = Sse.ReciprocalScalar(vf1); Unsafe.Write(floatTable.outArrayPtr, vf2); if (!floatTable.CheckResult((x, y) => { var expected = 1 / x[0]; return(((Math.Abs(expected - y[0]) <= 0.0003662109375f) || // |Relative Error| <= 1.5 * 2^-12 (float.IsNaN(expected) && float.IsNaN(y[0])) || (float.IsNegativeInfinity(expected) && float.IsNegativeInfinity(y[0])) || (float.IsPositiveInfinity(expected) && float.IsPositiveInfinity(y[0]))) && (y[1] == x[1]) && (y[2] == x[2]) && (y[3] == x[3])); })) { Console.WriteLine("SSE ReciprocalScalar failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx2.IsSupported) { Four = 4; Eight = 8; invalid = 15; for (int i = 0; i < N; i++) { floatSourceTable[i] = (float)i * 10.0f; doubleSourceTable[i] = (double)i * 10.0; intSourceTable[i] = i * 10; longSourceTable[i] = i * 10; } Vector256 <int> indexi; Vector256 <long> indexl; Vector128 <int> indexi128; fixed(int *iptr = intIndexTable) fixed(long *lptr = longIndexTable) fixed(int *i128ptr = vector128intIndexTable) { indexi = Avx.LoadVector256(iptr); indexl = Avx.LoadVector256(lptr); indexi128 = Sse2.LoadVector128(i128ptr); } Vector256 <int> maski; Vector256 <uint> maskui; Vector256 <long> maskl; Vector256 <ulong> maskul; Vector256 <float> maskf; Vector256 <double> maskd; fixed(int *iptr = intMaskTable) fixed(long *lptr = longMaskTable) { maski = Avx.LoadVector256(iptr); maskl = Avx.LoadVector256(lptr); maskui = maski.AsUInt32(); maskul = maskl.AsUInt64(); maskf = maski.AsSingle(); maskd = maskl.AsDouble(); } Vector256 <int> sourcei = Vector256 <int> .Zero; Vector256 <uint> sourceui = Vector256 <uint> .Zero; Vector256 <long> sourcel = Vector256 <long> .Zero; Vector256 <ulong> sourceul = Vector256 <ulong> .Zero; Vector256 <float> sourcef = Vector256 <float> .Zero; Vector256 <double> sourced = Vector256 <double> .Zero; // public static unsafe Vector256<float> GatherMaskVector256(Vector256<float> source, float* baseAddress, Vector256<int> index, Vector256<float> mask, byte scale) using (TestTable <float, int> floatTable = new TestTable <float, int>(floatSourceTable, new float[8])) { var vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, 4); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <float>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <float>), typeof(float *), typeof(Vector256 <int>), typeof(Vector256 <float>), typeof(byte) }). Invoke(null, new object[] { sourcef, Pointer.Box(floatTable.inArrayPtr, typeof(float *)), indexi, maskf, (byte)4 }); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on float with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, Four); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on float with non-const scale (IMM):"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on float with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector128<int> index, Vector256<double> mask, byte scale) using (TestTable <double, int> doubletTable = new TestTable <double, int>(doubleSourceTable, new double[4])) { var vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, 8); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on double:"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vd = (Vector256 <double>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <double>), typeof(double *), typeof(Vector128 <int>), typeof(Vector256 <double>), typeof(byte) }). Invoke(null, new object[] { sourced, Pointer.Box(doubletTable.inArrayPtr, typeof(double *)), indexi128, maskd, (byte)8 }); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on double:"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, Eight); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on double with non-const scale (IMM):"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<int> GatherMaskVector256(Vector256<int> source, int* baseAddress, Vector256<int> index, Vector256<int> mask, byte scale) using (TestTable <int, int> intTable = new TestTable <int, int>(intSourceTable, new int[8])) { var vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, 4); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <int>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <int>), typeof(int *), typeof(Vector256 <int>), typeof(Vector256 <int>), typeof(byte) }). Invoke(null, new object[] { sourcei, Pointer.Box(intTable.inArrayPtr, typeof(int *)), indexi, maski, (byte)4 }); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on int with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, Four); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on int with non-const scale (IMM):"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on int with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<uint> GatherMaskVector256(Vector256<uint> source, uint* baseAddress, Vector256<int> index, Vector256<uint> mask, byte scale) using (TestTable <int, int> intTable = new TestTable <int, int>(intSourceTable, new int[8])) { var vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, 4); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on uint:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <uint>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <uint>), typeof(uint *), typeof(Vector256 <int>), typeof(Vector256 <uint>), typeof(byte) }). Invoke(null, new object[] { sourceui, Pointer.Box(intTable.inArrayPtr, typeof(uint *)), indexi, maskui, (byte)4 }); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on uint:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, Four); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y, intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with non-const scale (IMM):"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector128<int> index, Vector256<long> mask, byte scale) using (TestTable <long, int> longTable = new TestTable <long, int>(longSourceTable, new long[4])) { var vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, 8); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on long:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <long>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <long>), typeof(long *), typeof(Vector128 <int>), typeof(Vector256 <long>), typeof(byte) }). Invoke(null, new object[] { sourcel, Pointer.Box(longTable.inArrayPtr, typeof(long *)), indexi128, maskl, (byte)8 }); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on long:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, Eight); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on long with non-const scale (IMM):"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector128<int> index, Vector256<ulong> mask, byte scale) using (TestTable <long, int> longTable = new TestTable <long, int>(longSourceTable, new long[4])) { var vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, 8); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <ulong>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <ulong>), typeof(ulong *), typeof(Vector128 <int>), typeof(Vector256 <ulong>), typeof(byte) }). Invoke(null, new object[] { sourceul, Pointer.Box(longTable.inArrayPtr, typeof(ulong *)), indexi128, maskul, (byte)8 }); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on ulong:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, Eight); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with non-const scale (IMM):"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid non-const scale (IMM)"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector256<long> index, Vector256<long> mask, byte scale) using (TestTable <long, long> longTable = new TestTable <long, long>(longSourceTable, new long[4])) { var vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, 8); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on long with Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <long>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <long>), typeof(long *), typeof(Vector256 <long>), typeof(Vector256 <long>), typeof(byte) }). Invoke(null, new object[] { sourcel, Pointer.Box(longTable.inArrayPtr, typeof(long *)), indexl, maskl, (byte)8 }); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on long with Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, Eight); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on long with non-const scale (IMM) and Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector256<long> index, Vector256<ulong> mask, byte scale) using (TestTable <long, long> longTable = new TestTable <long, long>(longSourceTable, new long[4])) { var vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, 8); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vf = (Vector256 <ulong>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <ulong>), typeof(ulong *), typeof(Vector256 <long>), typeof(Vector256 <ulong>), typeof(byte) }). Invoke(null, new object[] { sourceul, Pointer.Box(longTable.inArrayPtr, typeof(ulong *)), indexl, maskul, (byte)8 }); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on ulong with Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, Eight); Unsafe.Write(longTable.outArrayPtr, vf); if (!longTable.CheckResult((x, y) => x == y, longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with non-const scale (IMM) and Vector256 long index:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } // public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector256<long> index, Vector256<double> mask, byte scale) using (TestTable <double, long> doubletTable = new TestTable <double, long>(doubleSourceTable, new double[4])) { var vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, 8); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on double with Vector256 long index:"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } vd = (Vector256 <double>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <double>), typeof(double *), typeof(Vector256 <long>), typeof(Vector256 <double>), typeof(byte) }). Invoke(null, new object[] { sourced, Pointer.Box(doubletTable.inArrayPtr, typeof(double *)), indexl, maskd, (byte)8 }); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on double with Vector256 long index:"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, 3); Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, Eight); Unsafe.Write(doubletTable.outArrayPtr, vd); if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable)) { Console.WriteLine("AVX2 GatherMaskVector256 failed on double with non-const scale (IMM) and Vector256 long index:"); foreach (var item in doubletTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } try { vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, invalid); Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid non-const scale (IMM) and Vector256 long index"); testResult = Fail; } catch (System.ArgumentOutOfRangeException) { // success } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8])) using (TestTable <double> doubleTable = new TestTable <double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) { var vf1 = Unsafe.Read <Vector256 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector256 <float> >(floatTable.inArray2Ptr); var vf3 = Avx.Add(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); var vd1 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray1Ptr); var vd2 = Unsafe.Read <Vector256 <double> >(doubleTable.inArray2Ptr); var vd3 = Avx.Add(vd1, vd2); Unsafe.Write(doubleTable.outArrayPtr, vd3); if (!floatTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX Add failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!doubleTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX Add failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } if (Avx2.IsSupported) { using (TestTable <int> intTable = new TestTable <int>(new int[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new int[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new int[8])) using (TestTable <long> longTable = new TestTable <long>(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) using (TestTable <uint> uintTable = new TestTable <uint>(new uint[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new uint[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new uint[8])) using (TestTable <ulong> ulongTable = new TestTable <ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) using (TestTable <short> shortTable = new TestTable <short>(new short[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new short[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new short[16])) using (TestTable <ushort> ushortTable = new TestTable <ushort>(new ushort[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[16])) using (TestTable <sbyte> sbyteTable = new TestTable <sbyte>(new sbyte[32] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[32] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[32])) using (TestTable <byte> byteTable = new TestTable <byte>(new byte[32] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[32] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[32])) { var vi1 = Unsafe.Read <Vector256 <int> >(intTable.inArray1Ptr); var vi2 = Unsafe.Read <Vector256 <int> >(intTable.inArray2Ptr); var vi3 = Avx2.Add(vi1, vi2); Unsafe.Write(intTable.outArrayPtr, vi3); var vl1 = Unsafe.Read <Vector256 <long> >(longTable.inArray1Ptr); var vl2 = Unsafe.Read <Vector256 <long> >(longTable.inArray2Ptr); var vl3 = Avx2.Add(vl1, vl2); Unsafe.Write(longTable.outArrayPtr, vl3); var vui1 = Unsafe.Read <Vector256 <uint> >(uintTable.inArray1Ptr); var vui2 = Unsafe.Read <Vector256 <uint> >(uintTable.inArray2Ptr); var vui3 = Avx2.Add(vui1, vui2); Unsafe.Write(uintTable.outArrayPtr, vui3); var vul1 = Unsafe.Read <Vector256 <ulong> >(ulongTable.inArray1Ptr); var vul2 = Unsafe.Read <Vector256 <ulong> >(ulongTable.inArray2Ptr); var vul3 = Avx2.Add(vul1, vul2); Unsafe.Write(ulongTable.outArrayPtr, vul3); var vs1 = Unsafe.Read <Vector256 <short> >(shortTable.inArray1Ptr); var vs2 = Unsafe.Read <Vector256 <short> >(shortTable.inArray2Ptr); var vs3 = Avx2.Add(vs1, vs2); Unsafe.Write(shortTable.outArrayPtr, vs3); var vus1 = Unsafe.Read <Vector256 <ushort> >(ushortTable.inArray1Ptr); var vus2 = Unsafe.Read <Vector256 <ushort> >(ushortTable.inArray2Ptr); var vus3 = Avx2.Add(vus1, vus2); Unsafe.Write(ushortTable.outArrayPtr, vus3); var vsb1 = Unsafe.Read <Vector256 <sbyte> >(sbyteTable.inArray1Ptr); var vsb2 = Unsafe.Read <Vector256 <sbyte> >(sbyteTable.inArray2Ptr); var vsb3 = Avx2.Add(vsb1, vsb2); Unsafe.Write(sbyteTable.outArrayPtr, vsb3); var vb1 = Unsafe.Read <Vector256 <byte> >(byteTable.inArray1Ptr); var vb2 = Unsafe.Read <Vector256 <byte> >(byteTable.inArray2Ptr); var vb3 = Avx2.Add(vb1, vb2); Unsafe.Write(byteTable.outArrayPtr, vb3); if (!intTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!longTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on long:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!uintTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on uint:"); foreach (var item in uintTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!ulongTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on ulong:"); foreach (var item in ulongTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!shortTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on short:"); foreach (var item in shortTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!ushortTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on ushort:"); foreach (var item in ushortTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on sbyte:"); foreach (var item in sbyteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!byteTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("AVX2 Add failed on byte:"); foreach (var item in byteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } if (Sse2.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) using (TestTable <double> doubleTable = new TestTable <double>(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) using (TestTable <int> intTable = new TestTable <int>(new int[4] { 1, -5, 100, 0 }, new int[4] { 22, -1, -50, 0 }, new int[4])) using (TestTable <long> longTable = new TestTable <long>(new long[2] { 1, -5 }, new long[2] { 22, -1 }, new long[2])) using (TestTable <uint> uintTable = new TestTable <uint>(new uint[4] { 1, 5, 100, 0 }, new uint[4] { 22, 1, 50, 0 }, new uint[4])) using (TestTable <ulong> ulongTable = new TestTable <ulong>(new ulong[2] { 1, 5 }, new ulong[2] { 22, 1 }, new ulong[2])) using (TestTable <short> shortTable = new TestTable <short>(new short[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new short[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new short[8])) using (TestTable <ushort> ushortTable = new TestTable <ushort>(new ushort[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[8])) using (TestTable <sbyte> sbyteTable = new TestTable <sbyte>(new sbyte[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[16])) using (TestTable <byte> byteTable = new TestTable <byte>(new byte[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[16])) { var vf1 = Unsafe.Read <Vector128 <float> >(floatTable.inArray1Ptr); var vf2 = Unsafe.Read <Vector128 <float> >(floatTable.inArray2Ptr); var vf3 = Sse.Add(vf1, vf2); Unsafe.Write(floatTable.outArrayPtr, vf3); var vd1 = Unsafe.Read <Vector128 <double> >(doubleTable.inArray1Ptr); var vd2 = Unsafe.Read <Vector128 <double> >(doubleTable.inArray2Ptr); var vd3 = Sse2.Add(vd1, vd2); Unsafe.Write(doubleTable.outArrayPtr, vd3); var vi1 = Unsafe.Read <Vector128 <int> >(intTable.inArray1Ptr); var vi2 = Unsafe.Read <Vector128 <int> >(intTable.inArray2Ptr); var vi3 = Sse2.Add(vi1, vi2); Unsafe.Write(intTable.outArrayPtr, vi3); var vl1 = Unsafe.Read <Vector128 <long> >(longTable.inArray1Ptr); var vl2 = Unsafe.Read <Vector128 <long> >(longTable.inArray2Ptr); var vl3 = Sse2.Add(vl1, vl2); Unsafe.Write(longTable.outArrayPtr, vl3); var vui1 = Unsafe.Read <Vector128 <uint> >(uintTable.inArray1Ptr); var vui2 = Unsafe.Read <Vector128 <uint> >(uintTable.inArray2Ptr); var vui3 = Sse2.Add(vui1, vui2); Unsafe.Write(uintTable.outArrayPtr, vui3); var vul1 = Unsafe.Read <Vector128 <ulong> >(ulongTable.inArray1Ptr); var vul2 = Unsafe.Read <Vector128 <ulong> >(ulongTable.inArray2Ptr); var vul3 = Sse2.Add(vul1, vul2); Unsafe.Write(ulongTable.outArrayPtr, vul3); var vs1 = Unsafe.Read <Vector128 <short> >(shortTable.inArray1Ptr); var vs2 = Unsafe.Read <Vector128 <short> >(shortTable.inArray2Ptr); var vs3 = Sse2.Add(vs1, vs2); Unsafe.Write(shortTable.outArrayPtr, vs3); var vus1 = Unsafe.Read <Vector128 <ushort> >(ushortTable.inArray1Ptr); var vus2 = Unsafe.Read <Vector128 <ushort> >(ushortTable.inArray2Ptr); var vus3 = Sse2.Add(vus1, vus2); Unsafe.Write(ushortTable.outArrayPtr, vus3); var vsb1 = Unsafe.Read <Vector128 <sbyte> >(sbyteTable.inArray1Ptr); var vsb2 = Unsafe.Read <Vector128 <sbyte> >(sbyteTable.inArray2Ptr); var vsb3 = Sse2.Add(vsb1, vsb2); Unsafe.Write(sbyteTable.outArrayPtr, vsb3); var vb1 = Unsafe.Read <Vector128 <byte> >(byteTable.inArray1Ptr); var vb2 = Unsafe.Read <Vector128 <byte> >(byteTable.inArray2Ptr); var vb3 = Sse2.Add(vb1, vb2); Unsafe.Write(byteTable.outArrayPtr, vb3); if (!intTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!longTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on long:"); foreach (var item in longTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!uintTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on uint:"); foreach (var item in uintTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!ulongTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on ulong:"); foreach (var item in ulongTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!shortTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on short:"); foreach (var item in shortTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!ushortTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on ushort:"); foreach (var item in ushortTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!floatTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE Add failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!doubleTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on sbyte:"); foreach (var item in sbyteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } if (!byteTable.CheckResult((x, y, z) => x + y == z)) { Console.WriteLine("SSE2 Add failed on byte:"); foreach (var item in byteTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }
static unsafe int Main(string[] args) { int testResult = Pass; if (Avx.IsSupported) { using (TestTable <float> floatTable = new TestTable <float>(new float[8] { 1, -5, 100, 0, 1, 2, 3, 4 }, new float[8])) { var vf = Avx.LoadVector256((float *)(floatTable.inArrayPtr)); Unsafe.Write(floatTable.outArrayPtr, vf); if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y))) { Console.WriteLine("AVX LoadVector256 failed on float:"); foreach (var item in floatTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <double> doubleTable = new TestTable <double>(new double[4] { 1, -5, 100, 0 }, new double[4])) { var vf = Avx.LoadVector256((double *)(doubleTable.inArrayPtr)); Unsafe.Write(doubleTable.outArrayPtr, vf); if (!doubleTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y))) { Console.WriteLine("AVX LoadVector256 failed on double:"); foreach (var item in doubleTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <int> intTable = new TestTable <int>(new int[8] { 1, -5, 100, 0, 1, 2, 3, 4 }, new int[8])) { var vf = Avx.LoadVector256((int *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on int:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <uint> intTable = new TestTable <uint>(new uint[8] { 1, 5, 100, 0, 1, 2, 3, 4 }, new uint[8])) { var vf = Avx.LoadVector256((uint *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on uint:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <long> intTable = new TestTable <long>(new long[4] { 1, -5, 100, 0 }, new long[4])) { var vf = Avx.LoadVector256((long *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on long:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <ulong> intTable = new TestTable <ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4])) { var vf = Avx.LoadVector256((ulong *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on ulong:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <short> intTable = new TestTable <short>(new short[16] { 1, -5, 100, 0, 1, 2, 3, 4, 1, -5, 100, 0, 1, 2, 3, 4 }, new short[16])) { var vf = Avx.LoadVector256((short *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on short:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <ushort> intTable = new TestTable <ushort>(new ushort[16] { 1, 5, 100, 0, 1, 2, 3, 4, 1, 5, 100, 0, 1, 2, 3, 4 }, new ushort[16])) { var vf = Avx.LoadVector256((ushort *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on ushort:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <byte> intTable = new TestTable <byte>(new byte[32] { 1, 5, 100, 0, 1, 2, 3, 4, 1, 5, 100, 0, 1, 2, 3, 4, 1, 5, 100, 0, 1, 2, 3, 4, 1, 5, 100, 0, 1, 2, 3, 4 }, new byte[32])) { var vf = Avx.LoadVector256((byte *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on byte:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } using (TestTable <sbyte> intTable = new TestTable <sbyte>(new sbyte[32] { 1, -5, 100, 0, 1, 2, 3, 4, 1, -5, 100, 0, 1, 2, 3, 4, 1, -5, 100, 0, 1, 2, 3, 4, 1, -5, 100, 0, 1, 2, 3, 4 }, new sbyte[32])) { var vf = Avx.LoadVector256((sbyte *)(intTable.inArrayPtr)); Unsafe.Write(intTable.outArrayPtr, vf); if (!intTable.CheckResult((x, y) => x == y)) { Console.WriteLine("AVX LoadVector256 failed on sbyte:"); foreach (var item in intTable.outArray) { Console.Write(item + ", "); } Console.WriteLine(); testResult = Fail; } } } return(testResult); }