From c370ca3e4a0e8d0e255077c309cad2fefd618be2 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 8 Dec 2015 16:03:19 -0800 Subject: [PATCH] Add SIMD tests SIMD correctness tests. --- tests/src/JIT/SIMD/VectorAbs.cs | 85 +++++++++++ tests/src/JIT/SIMD/VectorAbs.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorAdd.cs | 90 +++++++++++ tests/src/JIT/SIMD/VectorAdd.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorArgs.cs | 66 +++++++++ tests/src/JIT/SIMD/VectorArgs.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorArray.cs | 170 +++++++++++++++++++++ tests/src/JIT/SIMD/VectorArray.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorArrayInit.cs | 147 ++++++++++++++++++ tests/src/JIT/SIMD/VectorArrayInit.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorCopyToArray.cs | 148 +++++++++++++++++++ tests/src/JIT/SIMD/VectorCopyToArray.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorDiv.cs | 111 ++++++++++++++ tests/src/JIT/SIMD/VectorDiv.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorDot.cs | 115 ++++++++++++++ tests/src/JIT/SIMD/VectorDot.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorExp.cs | 71 +++++++++ tests/src/JIT/SIMD/VectorExp.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorGet.cs | 177 ++++++++++++++++++++++ tests/src/JIT/SIMD/VectorGet.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorHWAccel.cs | 44 ++++++ tests/src/JIT/SIMD/VectorHWAccel.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorHWAccel2.cs | 41 +++++ tests/src/JIT/SIMD/VectorHWAccel2.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorInit.cs | 47 ++++++ tests/src/JIT/SIMD/VectorInit.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorInitN.cs | 109 ++++++++++++++ tests/src/JIT/SIMD/VectorInitN.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorIntEquals.cs | 33 +++++ tests/src/JIT/SIMD/VectorIntEquals.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorMatrix.cs | 222 ++++++++++++++++++++++++++++ tests/src/JIT/SIMD/VectorMatrix.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorMax.cs | 91 ++++++++++++ tests/src/JIT/SIMD/VectorMax.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorMin.cs | 90 +++++++++++ tests/src/JIT/SIMD/VectorMin.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorMul.cs | 123 +++++++++++++++ tests/src/JIT/SIMD/VectorMul.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorRelOp.cs | 159 ++++++++++++++++++++ tests/src/JIT/SIMD/VectorRelOp.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorReturn.cs | 74 ++++++++++ tests/src/JIT/SIMD/VectorReturn.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorSet.cs | 80 ++++++++++ tests/src/JIT/SIMD/VectorSet.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorSqrt.cs | 52 +++++++ tests/src/JIT/SIMD/VectorSqrt.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorSub.cs | 86 +++++++++++ tests/src/JIT/SIMD/VectorSub.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorUnused.cs | 83 +++++++++++ tests/src/JIT/SIMD/VectorUnused.csproj | 44 ++++++ tests/src/JIT/SIMD/VectorUtil.cs | 214 +++++++++++++++++++++++++++ 51 files changed, 3828 insertions(+) create mode 100644 tests/src/JIT/SIMD/VectorAbs.cs create mode 100644 tests/src/JIT/SIMD/VectorAbs.csproj create mode 100644 tests/src/JIT/SIMD/VectorAdd.cs create mode 100644 tests/src/JIT/SIMD/VectorAdd.csproj create mode 100644 tests/src/JIT/SIMD/VectorArgs.cs create mode 100644 tests/src/JIT/SIMD/VectorArgs.csproj create mode 100644 tests/src/JIT/SIMD/VectorArray.cs create mode 100644 tests/src/JIT/SIMD/VectorArray.csproj create mode 100644 tests/src/JIT/SIMD/VectorArrayInit.cs create mode 100644 tests/src/JIT/SIMD/VectorArrayInit.csproj create mode 100644 tests/src/JIT/SIMD/VectorCopyToArray.cs create mode 100644 tests/src/JIT/SIMD/VectorCopyToArray.csproj create mode 100644 tests/src/JIT/SIMD/VectorDiv.cs create mode 100644 tests/src/JIT/SIMD/VectorDiv.csproj create mode 100644 tests/src/JIT/SIMD/VectorDot.cs create mode 100644 tests/src/JIT/SIMD/VectorDot.csproj create mode 100644 tests/src/JIT/SIMD/VectorExp.cs create mode 100644 tests/src/JIT/SIMD/VectorExp.csproj create mode 100644 tests/src/JIT/SIMD/VectorGet.cs create mode 100644 tests/src/JIT/SIMD/VectorGet.csproj create mode 100644 tests/src/JIT/SIMD/VectorHWAccel.cs create mode 100644 tests/src/JIT/SIMD/VectorHWAccel.csproj create mode 100644 tests/src/JIT/SIMD/VectorHWAccel2.cs create mode 100644 tests/src/JIT/SIMD/VectorHWAccel2.csproj create mode 100644 tests/src/JIT/SIMD/VectorInit.cs create mode 100644 tests/src/JIT/SIMD/VectorInit.csproj create mode 100644 tests/src/JIT/SIMD/VectorInitN.cs create mode 100644 tests/src/JIT/SIMD/VectorInitN.csproj create mode 100644 tests/src/JIT/SIMD/VectorIntEquals.cs create mode 100644 tests/src/JIT/SIMD/VectorIntEquals.csproj create mode 100644 tests/src/JIT/SIMD/VectorMatrix.cs create mode 100644 tests/src/JIT/SIMD/VectorMatrix.csproj create mode 100644 tests/src/JIT/SIMD/VectorMax.cs create mode 100644 tests/src/JIT/SIMD/VectorMax.csproj create mode 100644 tests/src/JIT/SIMD/VectorMin.cs create mode 100644 tests/src/JIT/SIMD/VectorMin.csproj create mode 100644 tests/src/JIT/SIMD/VectorMul.cs create mode 100644 tests/src/JIT/SIMD/VectorMul.csproj create mode 100644 tests/src/JIT/SIMD/VectorRelOp.cs create mode 100644 tests/src/JIT/SIMD/VectorRelOp.csproj create mode 100644 tests/src/JIT/SIMD/VectorReturn.cs create mode 100644 tests/src/JIT/SIMD/VectorReturn.csproj create mode 100644 tests/src/JIT/SIMD/VectorSet.cs create mode 100644 tests/src/JIT/SIMD/VectorSet.csproj create mode 100644 tests/src/JIT/SIMD/VectorSqrt.cs create mode 100644 tests/src/JIT/SIMD/VectorSqrt.csproj create mode 100644 tests/src/JIT/SIMD/VectorSub.cs create mode 100644 tests/src/JIT/SIMD/VectorSub.csproj create mode 100644 tests/src/JIT/SIMD/VectorUnused.cs create mode 100644 tests/src/JIT/SIMD/VectorUnused.csproj create mode 100644 tests/src/JIT/SIMD/VectorUtil.cs diff --git a/tests/src/JIT/SIMD/VectorAbs.cs b/tests/src/JIT/SIMD/VectorAbs.cs new file mode 100644 index 0000000..476bb73 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorAbs.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorAbsTest where T : struct, IComparable, IEquatable + { + public static int VectorAbs(T value, T checkValue) + { + Vector A = new Vector(value); + Vector B = Vector.Abs(A); + + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(B[i], checkValue))) + { + return Fail; + } + } + return Pass; + } + } + + private class Vector4Test + { + public static int VectorAbs() + { + Vector4 A = new Vector4(-1f); + Vector4 B = Vector4.Abs(A); + if (!(CheckValue(B.X, 1f))) return Fail; + if (!(CheckValue(B.Y, 1f))) return Fail; + if (!(CheckValue(B.Z, 1f))) return Fail; + if (!(CheckValue(B.W, 1f))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorAbs() + { + Vector3 A = new Vector3(-1f); + Vector3 B = Vector3.Abs(A); + if (!(CheckValue(B.X, 1f))) return Fail; + if (!(CheckValue(B.Y, 1f))) return Fail; + if (!(CheckValue(B.Z, 1f))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorAbs() + { + Vector2 A = new Vector2(-1f); + Vector2 B = Vector2.Abs(A); + if (!(CheckValue(B.X, 1f))) return Fail; + if (!(CheckValue(B.Y, 1f))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + + if (VectorAbsTest.VectorAbs(-1f, 1f) != Pass) returnVal = Fail; + if (VectorAbsTest.VectorAbs(-1d, 1d) != Pass) returnVal = Fail; + if (VectorAbsTest.VectorAbs(-1, 1) != Pass) returnVal = Fail; + if (VectorAbsTest.VectorAbs(-1, 1) != Pass) returnVal = Fail; + if (Vector4Test.VectorAbs() != Pass) returnVal = Fail; + if (Vector3Test.VectorAbs() != Pass) returnVal = Fail; + if (Vector2Test.VectorAbs() != Pass) returnVal = Fail; + if (VectorAbsTest.VectorAbs((ushort)0xffff, (ushort)0xffff) != Pass) returnVal = Fail; + if (VectorAbsTest.VectorAbs((byte)0xff, (byte)0xff) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorAbs.csproj b/tests/src/JIT/SIMD/VectorAbs.csproj new file mode 100644 index 0000000..ed3bb87 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorAbs.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorAdd.cs b/tests/src/JIT/SIMD/VectorAdd.cs new file mode 100644 index 0000000..cbad495 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorAdd.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorAddTest where T : struct, IComparable, IEquatable + { + public static int VectorAdd(T a, T b, T c) + { + Vector A = new Vector(a); + Vector B = new Vector(b); + Vector C = A + B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], c))) + { + return Fail; + } + } + return Pass; + } + } + private class Vector4Test + { + public static int VectorAdd() + { + Vector4 A = new Vector4(2); + Vector4 B = new Vector4(1); + Vector4 C = A + B; + if (!(CheckValue(C.X, 3))) return Fail; + if (!(CheckValue(C.Y, 3))) return Fail; + if (!(CheckValue(C.Z, 3))) return Fail; + if (!(CheckValue(C.W, 3))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorAdd() + { + Vector3 A = new Vector3(2); + Vector3 B = new Vector3(1); + Vector3 C = A + B; + if (!(CheckValue(C.X, 3))) return Fail; + if (!(CheckValue(C.Y, 3))) return Fail; + if (!(CheckValue(C.Z, 3))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorAdd() + { + Vector2 A = new Vector2(2); + Vector2 B = new Vector2(1); + Vector2 C = A + B; + if (!(CheckValue(C.X, 3))) return Fail; + if (!(CheckValue(C.Y, 3))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorAddTest.VectorAdd(1, 2, (float)(1 + 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(1, 2, (double)(1 + 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(1, 2, (int)(1 + 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(1, 2, (long)(1 + 2)) != Pass) returnVal = Fail; + if (Vector4Test.VectorAdd() != Pass) returnVal = Fail; + if (Vector3Test.VectorAdd() != Pass) returnVal = Fail; + if (Vector2Test.VectorAdd() != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(1, 2, (ushort)(1 + 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(1, 2, (byte)(1 + 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(-1, -2, (short)(-1 - 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(-1, -2, (sbyte)(-1 - 2)) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(0x41000000u, 0x42000000u, 0x41000000u + 0x42000000u) != Pass) returnVal = Fail; + if (VectorAddTest.VectorAdd(0x4100000000000000ul, 0x4200000000000000ul, 0x4100000000000000ul + 0x4200000000000000ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorAdd.csproj b/tests/src/JIT/SIMD/VectorAdd.csproj new file mode 100644 index 0000000..caba852 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorAdd.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorArgs.cs b/tests/src/JIT/SIMD/VectorArgs.cs new file mode 100644 index 0000000..c365ec6 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArgs.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal class Color +{ + private Vector _rgb; + + public Color(float r, float g, float b) + { + float[] temp = new float[Vector.Count]; + temp[0] = r; temp[1] = g; temp[2] = b; + _rgb = new Vector(temp); + } + + public Color(Vector _rgb) + { this._rgb = _rgb; } + + public Color Change(float f) + { + Vector t = new Vector(f); + // t[3] = 0; + return new Color(t * _rgb); + } + + public Vector RGB { get { return _rgb; } } +} + +internal partial class VectorTest +{ + private static int VectorArgs() + { + const int Pass = 100; + const int Fail = -1; + + float[] temp = new float[Vector.Count]; + for (int i = 0; i < Vector.Count; i++) + { + temp[i] = 3 - i; + } + Vector rgb = new Vector(temp); + + float x = 2f; + Color c1 = new Color(rgb); + Color c2 = c1.Change(x); + + for (int i = 0; i < Vector.Count; i++) + { + // Round to integer for comparison. + if (((int)c2.RGB[i]) != (3 - i) * x) + { + return Fail; + } + } + + return Pass; + } + + private static int Main() + { + return VectorArgs(); + } +} diff --git a/tests/src/JIT/SIMD/VectorArgs.csproj b/tests/src/JIT/SIMD/VectorArgs.csproj new file mode 100644 index 0000000..e2aa8b6 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArgs.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorArray.cs b/tests/src/JIT/SIMD/VectorArray.cs new file mode 100644 index 0000000..7d76f91 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArray.cs @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorArrayTest where T : struct, IComparable, IEquatable + { + private static void Move(Vector[] pos, ref Vector delta) + { + for (int i = 0; i < pos.Length; ++i) + pos[i] += delta; + } + + static public int VectorArray(T deltaValue) + { + const int Pass = 100; + const int Fail = -1; + + Vector[] v = new Vector[3]; + for (int i = 0; i < v.Length; ++i) + v[i] = new Vector(GetValueFromInt(i + 1)); + + Vector delta = new Vector(GetValueFromInt(1)); + Move(v, ref delta); + + for (int i = 0; i < v.Length; i++) + { + T checkValue = GetValueFromInt(i + 2); + for (int j = 0; j < Vector.Count; j++) + { + if (!(CheckValue(v[i][j], checkValue))) return Fail; + } + } + + return Pass; + } + } + + private class Vector4Test + { + private static void Move(Vector4[] pos, ref Vector4 delta) + { + for (int i = 0; i < pos.Length; ++i) + pos[i] += delta; + } + + static public int VectorArray(float deltaValue) + { + const int Pass = 100; + const int Fail = -1; + + Vector4[] v = new Vector4[3]; + for (int i = 0; i < 3; ++i) + v[i] = new Vector4(i + 1); + + Vector4 delta = new Vector4(1); + Move(v, ref delta); + + for (int i = 0; i < v.Length; i++) + { + float checkValue = (float)(i + 2); + if (!(CheckValue(v[i].X, checkValue))) return Fail; + if (!(CheckValue(v[i].Y, checkValue))) return Fail; + if (!(CheckValue(v[i].Z, checkValue))) return Fail; + if (!(CheckValue(v[i].W, checkValue))) return Fail; + } + + return Pass; + } + } + + private class Vector3Test + { + private static void Move(Vector3[] pos, ref Vector3 delta) + { + for (int i = 0; i < pos.Length; ++i) + pos[i] += delta; + } + + static public int VectorArray(float deltaValue) + { + const int Pass = 100; + const int Fail = -1; + + Vector3[] v = new Vector3[3]; + for (int i = 0; i < 3; ++i) + v[i] = new Vector3(i + 1); + + Vector3 delta = new Vector3(1); + Move(v, ref delta); + + for (int i = 0; i < v.Length; i++) + { + float checkValue = (float)(i + 2); + if (!(CheckValue(v[i].X, checkValue))) return Fail; + if (!(CheckValue(v[i].Y, checkValue))) return Fail; + if (!(CheckValue(v[i].Z, checkValue))) return Fail; + } + + return Pass; + } + } + + private class Vector2Test + { + private static void Move(Vector2[] pos, ref Vector2 delta) + { + for (int i = 0; i < pos.Length; ++i) + pos[i] += delta; + } + + static public int VectorArray(float deltaValue) + { + const int Pass = 100; + const int Fail = -1; + + Vector2[] v = new Vector2[3]; + for (int i = 0; i < 3; ++i) + v[i] = new Vector2(i + 1); + + Vector2 delta = new Vector2(1); + Move(v, ref delta); + + for (int i = 0; i < v.Length; i++) + { + float checkValue = (float)(i + 2); + if (!(CheckValue(v[i].X, checkValue))) return Fail; + if (!(CheckValue(v[i].Y, checkValue))) return Fail; + } + + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + try + { + if (VectorArrayTest.VectorArray(1f) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1d) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1L) != Pass) returnVal = Fail; + if (Vector4Test.VectorArray(1f) != Pass) returnVal = Fail; + if (Vector3Test.VectorArray(1f) != Pass) returnVal = Fail; + if (Vector2Test.VectorArray(1f) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1) != Pass) returnVal = Fail; + if (VectorArrayTest.VectorArray(1ul) != Pass) returnVal = Fail; + } + catch (ArgumentException ex) + { + Console.WriteLine("Argument Exception was raised"); + Console.WriteLine(ex.StackTrace); + return Fail; + } + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorArray.csproj b/tests/src/JIT/SIMD/VectorArray.csproj new file mode 100644 index 0000000..8a34448 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArray.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorArrayInit.cs b/tests/src/JIT/SIMD/VectorArrayInit.cs new file mode 100644 index 0000000..6bf90ae --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArrayInit.cs @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorArrayInitTest where T : struct, IComparable, IEquatable + { + public static int VectorArrayInit(int size, Random random) + { + int returnVal = Pass; + + if (size < Vector.Count) size = Vector.Count; + int index = size - Vector.Count; + T[] inputArray = GetRandomArray(size, random); + bool caught; + + Vector v1 = new Vector(inputArray); + Vector v2 = new Vector(inputArray, index); + + for (int i = 0; i < Vector.Count; i++) + { + if (!CheckValue(v1[i], inputArray[i])) returnVal = Fail; + if (!CheckValue(v2[i], inputArray[index + i])) returnVal = Fail; + } + + // Test a null input array. + caught = false; + try + { + Vector v = new Vector(null, 0); + // Check one of the values so that v is not optimized away. + // TODO: Also test without this because it should still throw. + if (!CheckValue(v[0], inputArray[0])) returnVal = Fail; + } + catch (NullReferenceException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw NullReferenceException for a null input array."); + returnVal = Fail; + } + + // Test a negative index. + caught = false; + try + { + Vector v = new Vector(inputArray, -1); + } + catch (IndexOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw IndexOutOfRangeException for a negative index."); + returnVal = Fail; + } + + // Test an out-of-range index. + caught = false; + try + { + Vector v = new Vector(inputArray, inputArray.Length); + } + catch (IndexOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw IndexOutOfRangeException for an out-of-range index."); + returnVal = Fail; + } + + // Test insufficient range in target array. + caught = false; + try + { + Vector v = new Vector(inputArray, inputArray.Length - 1); + } + catch (IndexOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw IndexOutOfRangeException for insufficient range in target array."); + returnVal = Fail; + } + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + Random random = new Random(100); + + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(12, random) == Fail) returnVal = Fail; + if (VectorArrayInitTest.VectorArrayInit(17, random) == Fail) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorArrayInit.csproj b/tests/src/JIT/SIMD/VectorArrayInit.csproj new file mode 100644 index 0000000..ae6901a --- /dev/null +++ b/tests/src/JIT/SIMD/VectorArrayInit.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorCopyToArray.cs b/tests/src/JIT/SIMD/VectorCopyToArray.cs new file mode 100644 index 0000000..817336d --- /dev/null +++ b/tests/src/JIT/SIMD/VectorCopyToArray.cs @@ -0,0 +1,148 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorCopyToArrayTest where T : struct, IComparable, IEquatable + { + public static int VectorCopyToArray(int size, Random random) + { + int returnVal = Pass; + + if (size < Vector.Count) size = Vector.Count; + int index = size - Vector.Count; + T[] inputArray = GetRandomArray(size, random); + + Vector v1 = new Vector(inputArray); + Vector v2 = new Vector(inputArray, index); + bool caught; + + T[] outputArray = new T[2 * Vector.Count]; + v1.CopyTo(outputArray); + v2.CopyTo(outputArray, Vector.Count); + + for (int i = 0; i < Vector.Count; i++) + { + if (!CheckValue(v1[i], outputArray[i])) returnVal = Fail; + if (!CheckValue(v2[i], outputArray[i + Vector.Count])) returnVal = Fail; + } + + // Test a null input array. + caught = false; + try + { + v1.CopyTo(null); + } + catch (NullReferenceException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw NullReferenceException for a null input array."); + returnVal = Fail; + } + + // Test a negative index. + caught = false; + try + { + v1.CopyTo(outputArray, -1); + } + catch (ArgumentOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw ArgumentOutOfRangeException for a negative index."); + returnVal = Fail; + } + + // Test an out-of-range index. + caught = false; + try + { + v1.CopyTo(outputArray, outputArray.Length); + } + catch (ArgumentOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw ArgumentOutOfRangeException for an out-of-range index."); + returnVal = Fail; + } + + // Test insufficient range in target array. + caught = false; + try + { + v1.CopyTo(outputArray, outputArray.Length - 1); + } + catch (ArgumentException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw ArgumentException for insufficient range in target array."); + returnVal = Fail; + } + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + Random random = new Random(100); + + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(12, random) == Fail) returnVal = Fail; + if (VectorCopyToArrayTest.VectorCopyToArray(17, random) == Fail) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorCopyToArray.csproj b/tests/src/JIT/SIMD/VectorCopyToArray.csproj new file mode 100644 index 0000000..0912c36 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorCopyToArray.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorDiv.cs b/tests/src/JIT/SIMD/VectorDiv.cs new file mode 100644 index 0000000..2031701 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorDiv.cs @@ -0,0 +1,111 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorMulTest where T : struct, IComparable, IEquatable + { + public static int VectorDiv(T left, T right, T result) + { + Vector A = new Vector(left); + Vector B = new Vector(right); + + Vector C = A / B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], result))) + { + return Fail; + } + } + return Pass; + } + } + private class Vector4Test + { + public static int VectorDiv(float left, float right, float result) + { + Vector4 A = new Vector4(left); + Vector4 B = new Vector4(right); + Vector4 C = A / B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + if (!(CheckValue(C.W, result))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorDiv(float left, float right, float result) + { + Vector3 A = new Vector3(left); + Vector3 B = new Vector3(right); + Vector3 C = A / B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorDiv(float left, float right, float result) + { + Vector2 A = new Vector2(left); + Vector2 B = new Vector2(right); + Vector2 C = A / B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorMulTest.VectorDiv(6f, 2f, 6f / 2f) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(8d, 4d, 8d / 4d) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(6, 3, 2) != Pass) returnVal = Fail; + if (returnVal == Fail) + { + Console.WriteLine("Failed after int"); + } + if (VectorMulTest.VectorDiv(8, 2, 4) != Pass) returnVal = Fail; + if (returnVal == Fail) + { + Console.WriteLine("Failed after long"); + } + if (Vector4Test.VectorDiv(8f, 3f, 8f / 3f) != Pass) + { + Console.WriteLine("Vector4Test.VectorDiv failed"); + returnVal = Fail; + } + if (Vector3Test.VectorDiv(8f, 3f, 8f / 3f) != Pass) + { + Console.WriteLine("Vector3Test.VectorDiv failed"); + returnVal = Fail; + } + if (Vector2Test.VectorDiv(7f, 2f, 7f / 2f) != Pass) + { + Console.WriteLine("Vector2Test.VectorDiv failed"); + returnVal = Fail; + } + if (VectorMulTest.VectorDiv(6, 3, 2) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(6, 3, 2) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(6, -3, -2) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(6, -3, -2) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(6u, 3u, 2u) != Pass) returnVal = Fail; + if (VectorMulTest.VectorDiv(8ul, 2ul, 4ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorDiv.csproj b/tests/src/JIT/SIMD/VectorDiv.csproj new file mode 100644 index 0000000..99e6d81 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorDiv.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorDot.cs b/tests/src/JIT/SIMD/VectorDot.cs new file mode 100644 index 0000000..340a8d8 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorDot.cs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorDotTest where T : struct, IComparable, IEquatable + { + public static int VectorDot(T left, T right, T checkResult) + { + const int Pass = 100; + const int Fail = -1; + + Vector A = new Vector(left); + Vector B = new Vector(right); + + T dotProduct = Vector.Dot(A, B); + if (!(CheckValue(dotProduct, checkResult))) + { + Console.WriteLine("Dot product of Vector<" + typeof(T) + "> failed"); + return Fail; + } + + return Pass; + } + } + + private class Vector4Test + { + public static int VectorDot(float left, float right, float checkResult) + { + const int Pass = 100; + const int Fail = -1; + + Vector4 A = new Vector4(left); + Vector4 B = new Vector4(right); + + float dotProduct = Vector4.Dot(A, B); + if (!(CheckValue(dotProduct, checkResult))) + { + Console.WriteLine("Dot product of Vector4 failed"); + return Fail; + } + + return Pass; + } + } + + private class Vector3Test + { + public static int VectorDot(float left, float right, float checkResult) + { + const int Pass = 100; + const int Fail = -1; + + Vector3 A = new Vector3(left); + Vector3 B = new Vector3(right); + + float dotProduct = Vector3.Dot(A, B); + if (!(CheckValue(dotProduct, checkResult))) + { + Console.WriteLine("Dot product of Vector3 failed"); + return Fail; + } + + return Pass; + } + } + + private class Vector2Test + { + public static int VectorDot(float left, float right, float checkResult) + { + const int Pass = 100; + const int Fail = -1; + + Vector2 A = new Vector2(left); + Vector2 B = new Vector2(right); + + float dotProduct = Vector2.Dot(A, B); + if (!(CheckValue(dotProduct, checkResult))) + { + Console.WriteLine("Dot product of Vector2 failed"); + return Fail; + } + + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorDotTest.VectorDot(3f, 2f, 6f * Vector.Count) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3d, 2d, 6d * Vector.Count) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, 6 * Vector.Count) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, (long)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (Vector4Test.VectorDot(3f, 2f, 24f) != Pass) returnVal = Fail; + if (Vector3Test.VectorDot(3f, 2f, 18f) != Pass) returnVal = Fail; + if (Vector2Test.VectorDot(3f, 2f, 12f) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, (ushort)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, (byte)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, (short)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3, 2, (sbyte)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3u, 2u, (uint)(6 * Vector.Count)) != Pass) returnVal = Fail; + if (VectorDotTest.VectorDot(3ul, 2ul, 6ul * (ulong)Vector.Count) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorDot.csproj b/tests/src/JIT/SIMD/VectorDot.csproj new file mode 100644 index 0000000..a58e4f9 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorDot.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorExp.cs b/tests/src/JIT/SIMD/VectorExp.cs new file mode 100644 index 0000000..c67420c --- /dev/null +++ b/tests/src/JIT/SIMD/VectorExp.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorExpTest where T : struct, IComparable, IEquatable + { + public static int VectorExp(Vector x, T checkValue, T epsilon, T allowableError) + { + Vector sum = Vector.One; + Vector count = Vector.One; + Vector term = x; + Vector epsilonVec = new Vector(epsilon); + + do + { + if (Vector.LessThanOrEqualAll(Vector.Abs(term), epsilonVec)) break; + + sum = sum + term; + count = count + Vector.One; + term = term * (x / count); + } + while (true); + + if (Vector.LessThanOrEqualAll((Vector.Abs(sum) - new Vector(checkValue)), new Vector(allowableError))) + { + return Pass; + } + else + { + Console.WriteLine("Failed " + typeof(T).Name); + VectorPrint(" sum: ", sum); + return Fail; + } + } + } + + private static int Main() + { + int returnVal = Pass; + + if (VectorExpTest.VectorExp(Vector.One, (float)Math.Exp(1d), Single.Epsilon, 1E-06f) != Pass) + { + returnVal = Fail; + } + + if (VectorExpTest.VectorExp(Vector.One, Math.Exp(1d), Double.Epsilon, 1E-14) != Pass) + { + returnVal = Fail; + } + + if (VectorExpTest.VectorExp(Vector.One, (int)Math.Exp(1), 0, 0) != Pass) + { + returnVal = Fail; + } + + if (VectorExpTest.VectorExp(Vector.One, (long)Math.Exp(1), 0, 0) != Pass) + { + returnVal = Fail; + } + + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorExp.csproj b/tests/src/JIT/SIMD/VectorExp.csproj new file mode 100644 index 0000000..cde12b6 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorExp.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorGet.cs b/tests/src/JIT/SIMD/VectorGet.cs new file mode 100644 index 0000000..e92d6d0 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorGet.cs @@ -0,0 +1,177 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorGetTest where T : struct, IComparable, IEquatable + { + public static int VectorGet(T value, int index) + { + int returnVal = Pass; + + Vector A = new Vector(value); + + // Test variable index. + for (int i = 0; i < Vector.Count; i++) + { + if (!CheckValue(A[i], value)) returnVal = Fail; + } + + if (!CheckValue(A[index], value)) returnVal = Fail; + + // Test constant index. + if (!CheckValue(A[0], value)) returnVal = Fail; + if (Vector.Count >= 2) + { + if (!CheckValue(A[1], value)) + { + Console.WriteLine("Failed for [1] for type " + typeof(T).ToString()); + returnVal = Fail; + } + } + if (Vector.Count >= 4) + { + if (!CheckValue(A[2], value)) + { + Console.WriteLine("Failed for [2] for type " + typeof(T).ToString()); + returnVal = Fail; + } + if (!CheckValue(A[3], value)) + { + Console.WriteLine("Failed for [3] for type " + typeof(T).ToString()); + returnVal = Fail; + } + } + if (Vector.Count >= 8) + { + if (!CheckValue(A[4], value)) + { + Console.WriteLine("Failed for [4] for type " + typeof(T).ToString()); + returnVal = Fail; + } + if (!CheckValue(A[5], value)) + { + Console.WriteLine("Failed for [5] for type " + typeof(T).ToString()); + returnVal = Fail; + } + if (!CheckValue(A[6], value)) + { + Console.WriteLine("Failed for [6] for type " + typeof(T).ToString()); + returnVal = Fail; + } + if (!CheckValue(A[7], value)) + { + Console.WriteLine("Failed for [7] for type " + typeof(T).ToString()); + returnVal = Fail; + } + } + if (Vector.Count >= 16) + { + if (!CheckValue(A[8], value)) returnVal = Fail; + if (!CheckValue(A[9], value)) returnVal = Fail; + if (!CheckValue(A[10], value)) returnVal = Fail; + if (!CheckValue(A[11], value)) returnVal = Fail; + if (!CheckValue(A[12], value)) returnVal = Fail; + if (!CheckValue(A[13], value)) returnVal = Fail; + if (!CheckValue(A[14], value)) returnVal = Fail; + if (!CheckValue(A[15], value)) returnVal = Fail; + } + if (Vector.Count >= 32) + { + if (!CheckValue(A[16], value)) returnVal = Fail; + if (!CheckValue(A[17], value)) returnVal = Fail; + if (!CheckValue(A[18], value)) returnVal = Fail; + if (!CheckValue(A[19], value)) returnVal = Fail; + if (!CheckValue(A[20], value)) returnVal = Fail; + if (!CheckValue(A[21], value)) returnVal = Fail; + if (!CheckValue(A[22], value)) returnVal = Fail; + if (!CheckValue(A[23], value)) returnVal = Fail; + if (!CheckValue(A[24], value)) returnVal = Fail; + if (!CheckValue(A[25], value)) returnVal = Fail; + if (!CheckValue(A[26], value)) returnVal = Fail; + if (!CheckValue(A[27], value)) returnVal = Fail; + if (!CheckValue(A[28], value)) returnVal = Fail; + if (!CheckValue(A[29], value)) returnVal = Fail; + if (!CheckValue(A[30], value)) returnVal = Fail; + if (!CheckValue(A[31], value)) returnVal = Fail; + } + + return returnVal; + } + + [MethodImpl(MethodImplOptions.NoOptimization)] + public static int VectorGetIndexerOutOfRange(T value, int index) + { + int returnVal = Pass; + bool caught; + + Vector A = new Vector(value); + + T check; + caught = false; + try + { + switch (Vector.Count) + { + case 2: check = A[2]; break; + case 4: check = A[4]; break; + case 8: check = A[8]; break; + case 16: check = A[16]; break; + case 32: check = A[32]; break; + } + } + catch (IndexOutOfRangeException) + { + caught = true; + } + catch (Exception e) + { + Console.WriteLine("Caught exception: " + e.GetType()); + } + if (!caught) + { + Console.WriteLine("Failed to throw IndexOutOfRangeException for index == Count of " + Vector.Count); + returnVal = Fail; + } + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorGetTest.VectorGet(101D, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100D, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100D, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101F, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100F, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100F, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(-100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(-100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(101, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGet(-100, 1) == Fail) returnVal = Fail; + if (VectorGetTest.VectorGetIndexerOutOfRange(-100, 1) == Fail) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorGet.csproj b/tests/src/JIT/SIMD/VectorGet.csproj new file mode 100644 index 0000000..ab5e5fe --- /dev/null +++ b/tests/src/JIT/SIMD/VectorGet.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorHWAccel.cs b/tests/src/JIT/SIMD/VectorHWAccel.cs new file mode 100644 index 0000000..20eb3a5 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorHWAccel.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorHWAccelTest where T : struct, IComparable, IEquatable + { + public static int VectorHWAccel(T a, T b, T c) + { + if (Vector.IsHardwareAccelerated) + { + Vector A = new Vector(a); + Vector B = new Vector(b); + Vector C = A + B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], c))) + { + return Fail; + } + } + return Pass; + } + else + { + return Pass; + } + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorHWAccelTest.VectorHWAccel(1, 2, (float)(1 + 2)) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorHWAccel.csproj b/tests/src/JIT/SIMD/VectorHWAccel.csproj new file mode 100644 index 0000000..f2d7114 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorHWAccel.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorHWAccel2.cs b/tests/src/JIT/SIMD/VectorHWAccel2.cs new file mode 100644 index 0000000..f3fd503 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorHWAccel2.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorHWAccelTest where T : struct, IComparable, IEquatable + { + public static int VectorHWAccel2(T a, T b, T c) + { + Vector A = new Vector(a); + Vector B = new Vector(b); + Vector C = A + B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], c))) + { + return Fail; + } + } + return Pass; + } + } + + private static int Main() + { + if (Vector.IsHardwareAccelerated) + { + // The test harness will check to ensure that this method was compiled, which it will + // not be if IsHardwareAccelerated returns false. + return VectorHWAccelTest.VectorHWAccel2(1, 2, (float)(1 + 2)); + } + return Pass; + } +} diff --git a/tests/src/JIT/SIMD/VectorHWAccel2.csproj b/tests/src/JIT/SIMD/VectorHWAccel2.csproj new file mode 100644 index 0000000..790ecfc --- /dev/null +++ b/tests/src/JIT/SIMD/VectorHWAccel2.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorInit.cs b/tests/src/JIT/SIMD/VectorInit.cs new file mode 100644 index 0000000..6e57c9b --- /dev/null +++ b/tests/src/JIT/SIMD/VectorInit.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorInitTest + { + public static int VectorInit(float x) + { + int returnVal = Pass; + + Vector2 v2 = new Vector2(x); + Vector3 v3 = new Vector3(v2.X); + Vector4 v4 = new Vector4(v3.Y); + + float result2 = Vector2.Dot(v2, v2); + float result3 = Vector3.Dot(v3, v3); + float result4 = Vector4.Dot(v4, v4); + + Console.WriteLine("result2 : " + result2); + Console.WriteLine("result3 : " + result3); + Console.WriteLine("result4 : " + result4); + + if (result2 != 2f * x * x) return Fail; + if (result3 != 3f * x * x) return Fail; + if (result4 != 4f * x * x) return Fail; + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + + if (VectorInitTest.VectorInit(2f) == Fail) returnVal = Fail; + return returnVal; + } +} + diff --git a/tests/src/JIT/SIMD/VectorInit.csproj b/tests/src/JIT/SIMD/VectorInit.csproj new file mode 100644 index 0000000..262a4b3 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorInit.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorInitN.cs b/tests/src/JIT/SIMD/VectorInitN.cs new file mode 100644 index 0000000..0018c5f --- /dev/null +++ b/tests/src/JIT/SIMD/VectorInitN.cs @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorInitNTest + { + private static float s_value = 1.0F; + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + public static float nextValue() + { + float returnValue = s_value; + s_value += 1.0F; + return returnValue; + } + + public static int VectorInitN(float x, float y, float z, float w) + { + int returnVal = Pass; + + Vector2 v2 = new Vector2(x, y); + if (v2.X != x) + { + Console.WriteLine("Vector2.X failed"); + returnVal = Fail; + } + if (v2.Y != y) + { + Console.WriteLine("Vector2.Y failed"); + returnVal = Fail; + } + v2 = new Vector2(nextValue(), nextValue()); + if (v2.X > v2.Y) + { + Console.WriteLine("Vector2 evaluation order failed."); + } + + Vector3 v3 = new Vector3(x, y, z); + if (v3.X != x) + { + Console.WriteLine("Vector3.X failed"); + returnVal = Fail; + } + if (v3.Y != y) + { + Console.WriteLine("Vector3.Y failed"); + returnVal = Fail; + } + if (v3.Z != z) + { + Console.WriteLine("Vector3.Z failed"); + returnVal = Fail; + } + v3 = new Vector3(nextValue(), nextValue(), nextValue()); + if ((v3.X > v3.Y) || (v3.Y > v3.Z)) + { + Console.WriteLine("Vector3 evaluation order failed."); + } + + Vector4 v4 = new Vector4(x, y, z, w); + if (v4.X != x) + { + Console.WriteLine("Vector4.X failed"); + returnVal = Fail; + } + if (v4.Y != y) + { + Console.WriteLine("Vector4.Y failed"); + returnVal = Fail; + } + if (v4.Z != z) + { + Console.WriteLine("Vector4.Z failed"); + returnVal = Fail; + } + if (v4.W != w) + { + Console.WriteLine("Vector4.W failed"); + returnVal = Fail; + } + v4 = new Vector4(nextValue(), nextValue(), nextValue(), nextValue()); + if ((v4.X > v4.Y) || (v4.Y > v4.Z) || (v4.Z > v4.W)) + { + Console.WriteLine("Vector4 evaluation order failed."); + } + + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + + if (VectorInitNTest.VectorInitN(0.5f, -0.5f, 0f, 1.0f) == Fail) returnVal = Fail; + return returnVal; + } +} + diff --git a/tests/src/JIT/SIMD/VectorInitN.csproj b/tests/src/JIT/SIMD/VectorInitN.csproj new file mode 100644 index 0000000..1afe58b --- /dev/null +++ b/tests/src/JIT/SIMD/VectorInitN.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorIntEquals.cs b/tests/src/JIT/SIMD/VectorIntEquals.cs new file mode 100644 index 0000000..05ba2b9 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorIntEquals.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private static int VectorIntEquals() + { + const int Pass = 100; + const int Fail = -1; + + Vector A = new Vector(3); + Vector B = new Vector(3); + Vector C = new Vector(5); + + + bool result = A.Equals(B); + if (!result) return Fail; + + result = A.Equals(C); + if (result) return Fail; + + return Pass; + } + + private static int Main() + { + return VectorIntEquals(); + } +} diff --git a/tests/src/JIT/SIMD/VectorIntEquals.csproj b/tests/src/JIT/SIMD/VectorIntEquals.csproj new file mode 100644 index 0000000..b409c70 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorIntEquals.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorMatrix.cs b/tests/src/JIT/SIMD/VectorMatrix.cs new file mode 100644 index 0000000..8edc32f --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMatrix.cs @@ -0,0 +1,222 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + // Matrix for test purposes only - no per-dim bounds checking, etc. + public struct Matrix + where T : struct, IComparable, IEquatable + { + // data is a flattened matrix. + private T[] _data; + public int xCount, yCount; + private int _xTileCount; + private int _yTileCount; + private int _flattenedCount; + private static readonly int s_tileSize = Vector.Count; + + public + Matrix(int theXCount, int theYCount) + { + // Round up the dimensions so that we don't have to deal with remnants. + int vectorCount = Vector.Count; + _xTileCount = (theXCount + vectorCount - 1) / vectorCount; + _yTileCount = (theYCount + vectorCount - 1) / vectorCount; + xCount = _xTileCount * vectorCount; + yCount = _yTileCount * vectorCount; + _flattenedCount = xCount * yCount; + _data = new T[_flattenedCount]; + } + + public T this[int indexX, int indexY] + { + get + { + return _data[(indexX * yCount) + indexY]; + } + set + { + _data[(indexX * yCount) + indexY] = value; + } + } + + public static void Transpose(Matrix m, int xStart, int yStart, Vector[] result) + { + int Count = result.Length; + T[][] tempResult = new T[Count][]; + if (Count != Vector.Count) + { + throw new ArgumentException(); + } + for (int i = 0; i < Count; i++) + { + tempResult[i] = new T[Count]; + } + for (int i = 0; i < Count; i++) + { + for (int j = 0; j < Count; j++) + { + tempResult[j][i] = m[xStart + i, yStart + j]; + } + } + for (int i = 0; i < Count; i++) + { + result[i] = new Vector(tempResult[i]); + } + } + + public static Matrix operator *(Matrix left, Matrix right) + { + int newXCount = left.xCount; + int newYCount = right.yCount; + int innerCount = left.yCount; + Matrix result = new Matrix(newXCount, newYCount); + Vector[] temp = new Vector[s_tileSize]; + T[] temp2 = new T[s_tileSize]; + T[] temp3 = new T[s_tileSize]; + if (left.yCount != right.xCount) + { + throw new ArgumentException(); + } + for (int i = 0; i < result.xCount; i += s_tileSize) + { + for (int j = 0; j < result.yCount; j += s_tileSize) + { + for (int k = 0; k < right.xCount; k += s_tileSize) + { + // Compute the result for the tile: + // Result[i,j] = Left[i,k] * Right[k,j] + // Would REALLY like to have a Transpose intrinsic + // that could use shuffles. + Transpose(right, k, j, temp); + Vector dot = Vector.Zero; + for (int m = 0; m < s_tileSize; m++) + { + Vector leftTileRow = new Vector(left._data, (i + m) * left.yCount + k); + + for (int n = 0; n < s_tileSize; n++) + { + temp2[n] = Vector.Dot(leftTileRow, temp[n]); + } + Vector resultVector = new Vector(result._data, (i + m) * result.yCount + j); + + resultVector += new Vector(temp2); + // Store the resultTile + resultVector.CopyTo(result._data, ((i + m) * result.yCount + j)); + } + } + } + } + return result; + } + public void Print() + { + Console.WriteLine("["); + for (int i = 0; i < xCount; i++) + { + Console.Write(" ["); + for (int j = 0; j < yCount; j++) + { + Console.Write(this[i, j]); + if (j < (yCount - 1)) Console.Write(","); + } + Console.WriteLine("]"); + } + Console.WriteLine("]"); + } + } + + public static Matrix GetRandomMatrix(int xDim, int yDim, Random random) + where T : struct, IComparable, IEquatable + { + Matrix result = new Matrix(xDim, yDim); + for (int i = 0; i < xDim; i++) + { + for (int j = 0; j < yDim; j++) + { + int data = random.Next(100); + result[i, j] = GetValueFromInt(data); + } + } + return result; + } + + private static T compareMMPoint(Matrix left, Matrix right, int i, int j) + where T : struct, IComparable, IEquatable + { + T sum = Vector.Zero[0]; + for (int k = 0; k < right.xCount; k++) + { + T l = left[i, k]; + T r = right[k, j]; + sum = Add(sum, Multiply(l, r)); + } + return sum; + } + + public static int VectorMatrix(Matrix left, Matrix right) + where T : struct, IComparable, IEquatable + { + int returnVal = Pass; + Matrix Result = left * right; + for (int i = 0; i < left.xCount; i++) + { + for (int j = 0; j < right.yCount; j++) + { + T compareResult = compareMMPoint(left, right, i, j); + T testResult = Result[i, j]; + if (!(CheckValue(testResult, compareResult))) + { + Console.WriteLine(" Mismatch at [" + i + "," + j + "]: expected " + compareResult + " got " + testResult); + returnVal = Fail; + } + } + } + if (returnVal == Fail) + { + Console.WriteLine("FAILED COMPARE"); + Console.WriteLine("Left:"); + left.Print(); + Console.WriteLine("Right:"); + right.Print(); + Console.WriteLine("Result:"); + Result.Print(); + } + return returnVal; + } + + public static int Main() + { + int returnVal = Pass; + + Random random = new Random(100); + + // Float + Matrix AFloat = GetRandomMatrix(3, 4, random); + Matrix BFloat = GetRandomMatrix(4, 2, random); + if (VectorMatrix(AFloat, BFloat) != Pass) returnVal = Fail; + + AFloat = GetRandomMatrix(33, 20, random); + BFloat = GetRandomMatrix(20, 17, random); + if (VectorMatrix(AFloat, BFloat) != Pass) returnVal = Fail; + + // Double + Matrix ADouble = GetRandomMatrix(3, 4, random); + Matrix BDouble = GetRandomMatrix(4, 2, random); + if (VectorMatrix(ADouble, BDouble) != Pass) returnVal = Fail; + + ADouble = GetRandomMatrix(33, 20, random); + BDouble = GetRandomMatrix(20, 17, random); + if (VectorMatrix(ADouble, BDouble) != Pass) returnVal = Fail; + + return returnVal; + } +} + diff --git a/tests/src/JIT/SIMD/VectorMatrix.csproj b/tests/src/JIT/SIMD/VectorMatrix.csproj new file mode 100644 index 0000000..b4e1b9c --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMatrix.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorMax.cs b/tests/src/JIT/SIMD/VectorMax.cs new file mode 100644 index 0000000..02aafc8 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMax.cs @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorMaxTest where T : struct, IComparable, IEquatable + { + public static int VectorMax(T left, T right, T result) + { + Vector A = new Vector(left); + Vector B = new Vector(right); + + Vector C = Vector.Max(A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], result))) + { + return Fail; + } + } + return Pass; + } + } + private class Vector4Test + { + public static int VectorMax(float left, float right, float result) + { + Vector4 A = new Vector4(left); + Vector4 B = new Vector4(right); + Vector4 C = Vector4.Max(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + if (!(CheckValue(C.W, result))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorMax(float left, float right, float result) + { + Vector3 A = new Vector3(left); + Vector3 B = new Vector3(right); + Vector3 C = Vector3.Max(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorMax(float left, float right, float result) + { + Vector2 A = new Vector2(left); + Vector2 B = new Vector2(right); + Vector2 C = Vector2.Max(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorMaxTest.VectorMax(2f, 3f, 3f) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2d, 3d, 3d) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2, 3, 3) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2, 3, 3) != Pass) returnVal = Fail; + if (Vector4Test.VectorMax(2f, 3f, 3f) != Pass) returnVal = Fail; + if (Vector3Test.VectorMax(2f, 3f, 3f) != Pass) returnVal = Fail; + if (Vector2Test.VectorMax(2f, 3f, 3f) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2, 3, 3) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2, 3, 3) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(-2, -3, -2) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(-2, 3, 3) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(0x80000000u, 0x40000000u, 0x80000000u) != Pass) returnVal = Fail; + if (VectorMaxTest.VectorMax(2ul, 3ul, 3ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorMax.csproj b/tests/src/JIT/SIMD/VectorMax.csproj new file mode 100644 index 0000000..f1fe290 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMax.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorMin.cs b/tests/src/JIT/SIMD/VectorMin.cs new file mode 100644 index 0000000..eea6439 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMin.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorMinTest where T : struct, IComparable, IEquatable + { + public static int VectorMin(T left, T right, T result) + { + Vector A = new Vector(left); + Vector B = new Vector(right); + + Vector C = Vector.Min(A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], result))) + { + return Fail; + } + } + return Pass; + } + } + private class Vector4Test + { + public static int VectorMin(float left, float right, float result) + { + Vector4 A = new Vector4(left); + Vector4 B = new Vector4(right); + Vector4 C = Vector4.Min(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorMin(float left, float right, float result) + { + Vector3 A = new Vector3(left); + Vector3 B = new Vector3(right); + Vector3 C = Vector3.Min(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorMin(float left, float right, float result) + { + Vector2 A = new Vector2(left); + Vector2 B = new Vector2(right); + Vector2 C = Vector2.Min(A, B); + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorMinTest.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2d, 3d, 2d) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2, 3, 2) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2, 3, 2) != Pass) returnVal = Fail; + if (Vector4Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail; + if (Vector3Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail; + if (Vector2Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2, 3, 2) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2, 3, 2) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(-2, -3, -3) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(-2, 3, -2) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(0x80000000u, 0x40000000u, 0x40000000u) != Pass) returnVal = Fail; + if (VectorMinTest.VectorMin(2ul, 3ul, 2ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorMin.csproj b/tests/src/JIT/SIMD/VectorMin.csproj new file mode 100644 index 0000000..31d0bd1 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMin.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorMul.cs b/tests/src/JIT/SIMD/VectorMul.cs new file mode 100644 index 0000000..b50595a --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMul.cs @@ -0,0 +1,123 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorMulTest where T : struct, IComparable, IEquatable + { + public static int VectorMul(T left, T right, T leftTimesRight, T leftTimesRightSquared, T rightTimesRight) + { + Vector A = new Vector(left); + Vector B = new Vector(right); + + Vector C = A * B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], leftTimesRight))) + { + Console.WriteLine("FAILED Loop1: C[" + i + "] = " + C[i] + "; should be " + leftTimesRight); + return Fail; + } + } + + C = C * C; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], leftTimesRightSquared))) + { + Console.WriteLine("FAILED Loop2: C[" + i + "] = " + C[i] + "; should be " + leftTimesRight); + return Fail; + } + } + + B = B * B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(B[i], rightTimesRight))) + { + Console.WriteLine("FAILED Loop3: B[" + i + "] = " + C[i] + "; should be " + leftTimesRight); + return Fail; + } + } + + return Pass; + } + } + private class Vector4Test + { + public static int VectorMul(float left, float right, float result) + { + Vector4 A = new Vector4(left); + Vector4 B = new Vector4(right); + Vector4 C = A * B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + if (!(CheckValue(C.W, result))) return Fail; + return Pass; + } + } + + private class Vector3Test + { + public static int VectorMul(float left, float right, float result) + { + Vector3 A = new Vector3(left); + Vector3 B = new Vector3(right); + Vector3 C = A * B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + if (!(CheckValue(C.Z, result))) return Fail; + return Pass; + } + } + + private class Vector2Test + { + public static int VectorMul(float left, float right, float result) + { + Vector2 A = new Vector2(left); + Vector2 B = new Vector2(right); + Vector2 C = A * B; + if (!(CheckValue(C.X, result))) return Fail; + if (!(CheckValue(C.Y, result))) return Fail; + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorMulTest.VectorMul(2, 3, (float)(2 * 3), (float)(2 * 3) * (2 * 3), (float)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (double)(2 * 3), (double)(2 * 3) * (2 * 3), (double)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (2 * 3), (2 * 3) * (2 * 3), (3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (long)(2 * 3), (long)(2 * 3) * (2 * 3), (long)(3 * 3)) != Pass) + returnVal = Fail; + if (Vector4Test.VectorMul(2, 3, (float)(2 * 3)) != Pass) returnVal = Fail; + if (Vector3Test.VectorMul(2, 3, (float)(2 * 3)) != Pass) returnVal = Fail; + if (Vector2Test.VectorMul(2, 3, (float)(2 * 3)) != Pass) returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (ushort)(2 * 3), (ushort)(2 * 3) * (2 * 3), (ushort)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (byte)(2 * 3), (byte)(2 * 3) * (2 * 3), (byte)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (short)(2 * 3), (short)(2 * 3) * (2 * 3), (short)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2, 3, (sbyte)(2 * 3), (sbyte)(2 * 3) * (2 * 3), (sbyte)(3 * 3)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2u, 3u, 2u * 3u, (2u * 3u) * (2u * 3u), (3u * 3u)) != Pass) + returnVal = Fail; + if (VectorMulTest.VectorMul(2ul, 3ul, 2ul * 3ul, (2ul * 3ul) * (2ul * 3ul), (3ul * 3ul)) != Pass) + returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorMul.csproj b/tests/src/JIT/SIMD/VectorMul.csproj new file mode 100644 index 0000000..02228aa --- /dev/null +++ b/tests/src/JIT/SIMD/VectorMul.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorRelOp.cs b/tests/src/JIT/SIMD/VectorRelOp.cs new file mode 100644 index 0000000..d2568a1 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorRelOp.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorRelopTest where T : struct, IComparable, IEquatable + { + public static int VectorRelOp(T larger, T smaller) + { + const int Pass = 100; + const int Fail = -1; + int returnVal = Pass; + + Vector A = new Vector(larger); + Vector B = new Vector(smaller); + Vector C = new Vector(larger); + Vector D; + + // less than + Vector condition = Vector.LessThan(A, B); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(B[i])) + { + Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + condition = Vector.LessThan(B, A); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(A[i])) + { + Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + // greater than + condition = Vector.GreaterThan(A, B); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(A[i])) + { + Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + condition = Vector.GreaterThan(B, A); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(B[i])) + { + Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + // less than or equal + condition = Vector.LessThanOrEqual(A, C); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(A[i])) + { + Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + condition = Vector.LessThanOrEqual(A, B); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(B[i])) + { + Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + // greater than or equal + condition = Vector.GreaterThanOrEqual(A, C); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(A[i])) + { + Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + condition = Vector.GreaterThanOrEqual(B, C); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(B[i])) + { + Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + // equal + condition = Vector.Equals(A, C); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(A[i])) + { + Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + condition = Vector.Equals(B, C); + D = Vector.ConditionalSelect(condition, A, B); + for (int i = 0; i < Vector.Count; i++) + { + if (!D[i].Equals(B[i])) + { + Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i); + returnVal = Fail; + } + } + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(-2, -3) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(-2, -3) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3u, 2u) != Pass) returnVal = Fail; + if (VectorRelopTest.VectorRelOp(3ul, 2ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorRelOp.csproj b/tests/src/JIT/SIMD/VectorRelOp.csproj new file mode 100644 index 0000000..dfa2717 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorRelOp.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorReturn.cs b/tests/src/JIT/SIMD/VectorReturn.cs new file mode 100644 index 0000000..60e4f09 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorReturn.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + private static Vector2[] s_A; + private static Vector2 s_p0; + private static Vector2 s_p1; + private static Vector2 s_p2; + private static Vector2 s_p3; + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + public static void init() + { + s_A = new Vector2[10]; + Random random = new Random(100); + for (int i = 0; i < 10; i++) + { + s_A[i] = new Vector2(random.Next(100)); + } + s_p0 = new Vector2(random.Next(100)); + s_p1 = new Vector2(random.Next(100)); + s_p2 = new Vector2(random.Next(100)); + s_p3 = new Vector2(random.Next(100)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector2 F1(float t) + { + float ti = 1 - t; + float t0 = ti * ti * ti; + float t1 = 3 * ti * ti * t; + float t2 = 3 * ti * t * t; + float t3 = t * t * t; + return (t0 * s_p0) + (t1 * s_p1) + (t2 * s_p2) + (t3 * s_p3); + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + public static Vector2 F2(float u) + { + if (u < 0) + return s_A[0]; + if (u >= 1) + return s_A[1]; + if (u < 0.1) + return s_A[2]; + if (u > 0.9) + return s_A[3]; + return F1(u); + } + + public static int Main() + { + init(); + Vector2 result = F2(0.5F); + Vector2 expectedResult = F1(0.5F); + Console.WriteLine("Result is " + result.ToString()); + if (!CheckValue(result.X, expectedResult.X) || !CheckValue(result.Y, expectedResult.Y)) + { + Console.WriteLine("Expected result is " + expectedResult.ToString()); + Console.WriteLine("FAILED"); + return Fail; + } + Console.WriteLine("PASSED"); + return Pass; + } +} diff --git a/tests/src/JIT/SIMD/VectorReturn.csproj b/tests/src/JIT/SIMD/VectorReturn.csproj new file mode 100644 index 0000000..332449e --- /dev/null +++ b/tests/src/JIT/SIMD/VectorReturn.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorSet.cs b/tests/src/JIT/SIMD/VectorSet.cs new file mode 100644 index 0000000..8512d88 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSet.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorSetTest + { + public static int VectorSet(float value) + { + int returnVal = Pass; + + Vector2 A = new Vector2(0.0f, 0.0f); + + A.X = value; + if (!CheckValue(A.X, value)) returnVal = Fail; + if (!CheckValue(A.Y, 0.0f)) returnVal = Fail; + + A.Y = value; + if (!CheckValue(A.X, value)) returnVal = Fail; + if (!CheckValue(A.Y, value)) returnVal = Fail; + + Vector3 B = new Vector3(0.0f, 0.0f, 0.0f); + B.X = value; + if (!CheckValue(B.X, value)) returnVal = Fail; + if (!CheckValue(B.Y, 0.0f)) returnVal = Fail; + if (!CheckValue(B.Z, 0.0f)) returnVal = Fail; + + B.Y = value; + if (!CheckValue(B.X, value)) returnVal = Fail; + if (!CheckValue(B.Y, value)) returnVal = Fail; + if (!CheckValue(B.Z, 0.0f)) returnVal = Fail; + + B.Z = value; + if (!CheckValue(B.X, value)) returnVal = Fail; + if (!CheckValue(B.Y, value)) returnVal = Fail; + if (!CheckValue(B.Z, value)) returnVal = Fail; + + Vector4 C = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + C.X = value; + if (!CheckValue(C.X, value)) returnVal = Fail; + if (!CheckValue(C.Y, 0.0f)) returnVal = Fail; + if (!CheckValue(C.Z, 0.0f)) returnVal = Fail; + if (!CheckValue(C.W, 0.0f)) returnVal = Fail; + + C.Y = value; + if (!CheckValue(C.X, value)) returnVal = Fail; + if (!CheckValue(C.Y, value)) returnVal = Fail; + if (!CheckValue(C.Z, 0.0f)) returnVal = Fail; + if (!CheckValue(C.W, 0.0f)) returnVal = Fail; + + C.Z = value; + if (!CheckValue(C.X, value)) returnVal = Fail; + if (!CheckValue(C.Y, value)) returnVal = Fail; + if (!CheckValue(C.Z, value)) returnVal = Fail; + if (!CheckValue(C.W, 0.0f)) returnVal = Fail; + + C.W = value; + if (!CheckValue(C.X, value)) returnVal = Fail; + if (!CheckValue(C.Y, value)) returnVal = Fail; + if (!CheckValue(C.Z, value)) returnVal = Fail; + if (!CheckValue(C.W, value)) returnVal = Fail; + + return returnVal; + } + } + + private static int Main() + { + int returnVal = Pass; + if (VectorSetTest.VectorSet(3.14f) == Fail) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorSet.csproj b/tests/src/JIT/SIMD/VectorSet.csproj new file mode 100644 index 0000000..fbb299c --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSet.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorSqrt.cs b/tests/src/JIT/SIMD/VectorSqrt.cs new file mode 100644 index 0000000..294cfeb --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSqrt.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorSqrtTest where T : struct, IComparable, IEquatable + { + public static int VectorSqrt(T square, T root, T allowableError) + { + Vector A = new Vector(square); + Vector B = Vector.SquareRoot(A); + + if (Vector.LessThanOrEqualAll((Vector.Abs(B) - new Vector(root)), new Vector(allowableError))) + { + return Pass; + } + else + { + Console.WriteLine("Failed " + typeof(T).Name); + VectorPrint(" input: ", A); + VectorPrint(" result: ", B); + return Fail; + } + } + } + + + private static int Main() + { + int returnVal = Pass; + if (VectorSqrtTest.VectorSqrt(25f, 5f, 1E-06f) != Pass) + { + returnVal = Fail; + } + if (VectorSqrtTest.VectorSqrt(25f, 5f, 1E-14) != Pass) + { + returnVal = Fail; + } + if (VectorSqrtTest.VectorSqrt(25f, 5f, 0) != Pass) + { + returnVal = Fail; + } + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorSqrt.csproj b/tests/src/JIT/SIMD/VectorSqrt.csproj new file mode 100644 index 0000000..a6f9f56 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSqrt.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorSub.cs b/tests/src/JIT/SIMD/VectorSub.cs new file mode 100644 index 0000000..f620036 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSub.cs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorSubTest where T : struct, IComparable, IEquatable + { + public static int VectorSub(T a, T b, T c) + { + Vector A = new Vector(a); + Vector B = new Vector(b); + Vector C = A - B; + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(C[i], c))) + { + return Fail; + } + } + return Pass; + } + } + private class Vector4Test + { + public static int VectorSub() + { + Vector4 A = new Vector4(3); + Vector4 B = new Vector4(2); + Vector4 C = A - B; + if (!(CheckValue(C.X, 1f))) return Fail; + if (!(CheckValue(C.Y, 1f))) return Fail; + if (!(CheckValue(C.Z, 1f))) return Fail; + if (!(CheckValue(C.W, 1f))) return Fail; + return Pass; + } + } + private class Vector3Test + { + public static int VectorSub() + { + Vector3 A = new Vector3(3); + Vector3 B = new Vector3(2); + Vector3 C = A - B; + if (!(CheckValue(C.X, 1f))) return Fail; + if (!(CheckValue(C.Y, 1f))) return Fail; + if (!(CheckValue(C.Z, 1f))) return Fail; + return Pass; + } + } + private class Vector2Test + { + public static int VectorSub() + { + Vector2 A = new Vector2(4, 3); + Vector2 B = new Vector2(3, 2); + Vector2 C = A - B; + if (!(CheckValue(C.X, 1f))) return Fail; + if (!(CheckValue(C.Y, 1f))) return Fail; + return Pass; + } + } + private static int Main() + { + int returnVal = Pass; + if (VectorSubTest.VectorSub(3, 2, (float)(3 - 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, 2, (float)(3 - 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, 2, (int)(3 - 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, 2, (long)(3 - 2)) != Pass) returnVal = Fail; + if (Vector3Test.VectorSub() != Pass) returnVal = Fail; + if (Vector2Test.VectorSub() != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, 2, (ushort)(3 - 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, 2, (byte)(3 - 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, -2, (short)(3 + 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(3, -2, (sbyte)(3 + 2)) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(0x42000000u, 0x41000000u, 0x42000000u - 0x41000000u) != Pass) returnVal = Fail; + if (VectorSubTest.VectorSub(0x42000000ul, 0x41000000ul, 0x42000000ul - 0x41000000ul) != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorSub.csproj b/tests/src/JIT/SIMD/VectorSub.csproj new file mode 100644 index 0000000..604bfaf --- /dev/null +++ b/tests/src/JIT/SIMD/VectorSub.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorUnused.cs b/tests/src/JIT/SIMD/VectorUnused.cs new file mode 100644 index 0000000..08e2033 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorUnused.cs @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// The Rationalizer was not correctly handling a case of an unused SIMD expression +// involving a localVar or temporary value, where the SIMD expression is returning a non-SIMD +// value, and the expression is sufficiently complex (e.g. a call to vector * scalar which is +// inlined but not an intrinsic). + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + private const int Pass = 100; + private const int Fail = -1; + + private class VectorUnusedTest where T : struct, IComparable, IEquatable + { + public static int VectorUnused(T t1, T t2) + { + Vector v1 = new Vector(t1); + v1.Equals(Vector.One * t2); + return Pass; + } + } + + private class Vector4Test + { + public static int VectorUnused() + { + Vector4 v1 = new Vector4(3f); + Vector4.Dot(default(Vector4) * 2f, Vector4.One); + Vector4.Dot(v1, Vector4.One * 2f); + v1.Equals(Vector4.One * 3f); + return Pass; + } + } + + private class Vector3Test + { + public static int VectorUnused() + { + Vector3 v1 = new Vector3(3f); + Vector3.Dot(default(Vector3) * 2f, Vector3.One); + Vector3.Dot(v1, Vector3.One * 2f); + v1.Equals(Vector3.One * 3f); + return Pass; + } + } + + private class Vector2Test + { + public static int VectorUnused() + { + Vector2 v1 = new Vector2(3f); + Vector2.Dot(default(Vector2) * 2f, Vector2.One); + Vector2.Dot(v1, Vector2.One * 2f); + v1.Equals(Vector2.One * 3f); + return Pass; + } + } + + private static int Main() + { + int returnVal = Pass; + + if (VectorUnusedTest.VectorUnused(3f, 2f) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (VectorUnusedTest.VectorUnused(3, 2) != Pass) returnVal = Fail; + if (Vector4Test.VectorUnused() != Pass) returnVal = Fail; + if (Vector3Test.VectorUnused() != Pass) returnVal = Fail; + if (Vector2Test.VectorUnused() != Pass) returnVal = Fail; + return returnVal; + } +} diff --git a/tests/src/JIT/SIMD/VectorUnused.csproj b/tests/src/JIT/SIMD/VectorUnused.csproj new file mode 100644 index 0000000..a5b12c5 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorUnused.csproj @@ -0,0 +1,44 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/SIMD/VectorUtil.cs b/tests/src/JIT/SIMD/VectorUtil.cs new file mode 100644 index 0000000..80c9fd2 --- /dev/null +++ b/tests/src/JIT/SIMD/VectorUtil.cs @@ -0,0 +1,214 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Numerics; + +internal partial class VectorTest +{ + public static bool CheckValue(T value, T expectedValue) + { + bool returnVal; + if (typeof(T) == typeof(float)) + { + returnVal = Math.Abs(((float)(object)value) - ((float)(object)expectedValue)) <= Single.Epsilon; + } + if (typeof(T) == typeof(double)) + { + returnVal = Math.Abs(((double)(object)value) - ((double)(object)expectedValue)) <= Double.Epsilon; + } + else + { + returnVal = value.Equals(expectedValue); + } + if (returnVal == false) + { + Console.WriteLine("CheckValue failed for " + expectedValue + " of type " + typeof(T).ToString()); + } + return returnVal; + } + + private static bool CheckVector(Vector V, T value) where T : struct, IComparable, IEquatable + { + for (int i = 0; i < Vector.Count; i++) + { + if (!(CheckValue(V[i], value))) + { + return false; + } + } + return true; + } + + public static T GetValueFromInt(int value) + { + if (typeof(T) == typeof(float)) + { + float floatValue = (float)value; + return (T)(object)floatValue; + } + if (typeof(T) == typeof(double)) + { + double doubleValue = (double)value; + return (T)(object)doubleValue; + } + if (typeof(T) == typeof(int)) + { + return (T)(object)value; + } + if (typeof(T) == typeof(uint)) + { + uint uintValue = (uint)value; + return (T)(object)uintValue; + } + if (typeof(T) == typeof(long)) + { + long longValue = (long)value; + return (T)(object)longValue; + } + if (typeof(T) == typeof(ulong)) + { + ulong longValue = (ulong)value; + return (T)(object)longValue; + } + if (typeof(T) == typeof(ushort)) + { + return (T)(object)(ushort)value; + } + if (typeof(T) == typeof(byte)) + { + return (T)(object)(byte)value; + } + if (typeof(T) == typeof(short)) + { + return (T)(object)(short)value; + } + if (typeof(T) == typeof(sbyte)) + { + return (T)(object)(sbyte)value; + } + else + { + throw new ArgumentException(); + } + } + + private static void VectorPrint(string mesg, Vector v) where T : struct, IComparable, IEquatable + { + Console.Write(mesg + "["); + for (int i = 0; i < Vector.Count; i++) + { + Console.Write(" " + v[i]); + if (i < (Vector.Count - 1)) Console.Write(","); + } + Console.WriteLine(" ]"); + } + + private static T Add(T left, T right) where T : struct, IComparable, IEquatable + { + if (typeof(T) == typeof(float)) + { + return (T)(object)(((float)(object)left) + ((float)(object)right)); + } + if (typeof(T) == typeof(double)) + { + return (T)(object)(((double)(object)left) + ((double)(object)right)); + } + if (typeof(T) == typeof(int)) + { + return (T)(object)(((int)(object)left) + ((int)(object)right)); + } + if (typeof(T) == typeof(uint)) + { + return (T)(object)(((uint)(object)left) + ((uint)(object)right)); + } + if (typeof(T) == typeof(ushort)) + { + return (T)(object)(((ushort)(object)left) + ((ushort)(object)right)); + } + if (typeof(T) == typeof(byte)) + { + return (T)(object)(((byte)(object)left) + ((byte)(object)right)); + } + if (typeof(T) == typeof(short)) + { + return (T)(object)(((short)(object)left) + ((short)(object)right)); + } + if (typeof(T) == typeof(sbyte)) + { + return (T)(object)(((sbyte)(object)left) + ((sbyte)(object)right)); + } + if (typeof(T) == typeof(long)) + { + return (T)(object)(((long)(object)left) + ((long)(object)right)); + } + if (typeof(T) == typeof(ulong)) + { + return (T)(object)(((ulong)(object)left) + ((ulong)(object)right)); + } + else + { + throw new ArgumentException(); + } + } + private static T Multiply(T left, T right) where T : struct, IComparable, IEquatable + { + if (typeof(T) == typeof(float)) + { + return (T)(object)(((float)(object)left) * ((float)(object)right)); + } + if (typeof(T) == typeof(double)) + { + return (T)(object)(((double)(object)left) * ((double)(object)right)); + } + if (typeof(T) == typeof(int)) + { + return (T)(object)(((int)(object)left) * ((int)(object)right)); + } + if (typeof(T) == typeof(uint)) + { + return (T)(object)(((uint)(object)left) * ((uint)(object)right)); + } + if (typeof(T) == typeof(ushort)) + { + return (T)(object)(((ushort)(object)left) * ((ushort)(object)right)); + } + if (typeof(T) == typeof(byte)) + { + return (T)(object)(((byte)(object)left) * ((byte)(object)right)); + } + if (typeof(T) == typeof(short)) + { + return (T)(object)(((short)(object)left) * ((short)(object)right)); + } + if (typeof(T) == typeof(sbyte)) + { + return (T)(object)(((sbyte)(object)left) * ((sbyte)(object)right)); + } + if (typeof(T) == typeof(long)) + { + return (T)(object)(((long)(object)left) * ((long)(object)right)); + } + if (typeof(T) == typeof(ulong)) + { + return (T)(object)(((ulong)(object)left) * ((ulong)(object)right)); + } + else + { + throw new ArgumentException(); + } + } + + public static T[] GetRandomArray(int size, Random random) + where T : struct, IComparable, IEquatable + { + T[] result = new T[size]; + for (int i = 0; i < size; i++) + { + int data = random.Next(100); + result[i] = GetValueFromInt(data); + } + return result; + } +} -- 2.7.4