From 1f5249331cccdad8ee5ef0bd2e4999c49cf5e00a Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 15 Mar 2019 16:58:00 -0700 Subject: [PATCH] Restructure the test src/JIT/Directed/VectorABI/VectorMgdMgd.cs Commit migrated from https://github.com/dotnet/coreclr/commit/ed8ef5e574a886917546a133d5344362226d7733 --- .../JIT/Directed/VectorABI/VectorMgdMgd.cs | 242 ++++++++++-------- 1 file changed, 137 insertions(+), 105 deletions(-) diff --git a/src/coreclr/tests/src/JIT/Directed/VectorABI/VectorMgdMgd.cs b/src/coreclr/tests/src/JIT/Directed/VectorABI/VectorMgdMgd.cs index 99a77abd536..09feea9990c 100644 --- a/src/coreclr/tests/src/JIT/Directed/VectorABI/VectorMgdMgd.cs +++ b/src/coreclr/tests/src/JIT/Directed/VectorABI/VectorMgdMgd.cs @@ -24,111 +24,6 @@ public static class VectorMgdMgd static Random random = new Random(12345); - public unsafe class HVATests where T : struct - { - // We can have up to 4 vectors in an HVA, and we'll test structs with up to 5 of them - // (to ensure that even those that are too large are handled consistently). - // So we need 5 * the element count in the largest (128-bit) vector with the smallest - // element type (byte). - static T[] values; - static T[] check; - private int ElementCount = (Unsafe.SizeOf>() / sizeof(byte)) * 5; - public bool isPassing = true; - - public struct HVA128_02 - { - public Vector128 v0; - public Vector128 v1; - } - - public HVATests() - { - values = new T[ElementCount]; - for (int i = 0; i < values.Length; i++) - { - int data = random.Next(100); - values[i] = GetValueFromInt(data); - } - } - - public void doTests() - { - HVA128_02 hva128_02; - hva128_02.v0 = Unsafe.As>(ref values[0]); - hva128_02.v1 = Unsafe.As>(ref values[Vector128.Count]); - test1Argument_HVA128_02(hva128_02); - - testReturn_HFA128_02(); - - Type[] parameterTypes = new Type[] { typeof(HVA128_02) }; - System.Reflection.MethodInfo methodInfo = typeof(HVATests) - .GetMethod(nameof(HVATests.test1Argument_HVA128_02), parameterTypes); - methodInfo.Invoke(this, new object[] { hva128_02 }); - - testReflectionReturn_HFA128_02(); - } - - // Checks that the values in v correspond to those in the values array starting - // with values[index] - private void checkValues(Vector128 v, int index) - { - for (int i = 0; i < Vector128.Count; i++) - { - if (!CheckValue(v.GetElement(i), values[index])) - { - isPassing = false; - } - index++; - } - } - - // Test the case where we've passed in a single argument HVA of 2 vectors. - [MethodImpl(MethodImplOptions.NoInlining)] - public void test1Argument_HVA128_02(HVA128_02 s) - { - checkValues(s.v0, 0); - checkValues(s.v1, Vector128.Count); - } - - // Return an HVA of 2 vectors, with values from the 'values' array. - [MethodImpl(MethodImplOptions.NoInlining)] - public HVA128_02 returnTest() - { - HVA128_02 hva128_02; - hva128_02.v0 = Unsafe.As>(ref values[0]); - hva128_02.v1 = Unsafe.As>(ref values[Vector128.Count]); - return hva128_02; - } - - public void testReturn_HFA128_02() - { - HVA128_02 s = returnTest(); - checkValues(s.v0, 0); - checkValues(s.v1, Vector128.Count); - } - - public void testReflectionReturn_HFA128_02() - { - Type[] parameterTypes = new Type[] {}; - System.Reflection.MethodInfo methodInfo = typeof(HVATests) - .GetMethod(nameof(HVATests.returnTest), parameterTypes); - object o = methodInfo.Invoke(this, new object[] { }); - HVA128_02 s = (HVA128_02)o; - checkValues(s.v0, 0); - checkValues(s.v1, Vector128.Count); - } - } - - public static int Main(string[] args) - { - var isPassing = true; - - HVATests byteTests = new HVATests(); - byteTests.doTests(); - - return byteTests.isPassing ? PASS : FAIL; - } - public static T GetValueFromInt(int value) { if (typeof(T) == typeof(float)) @@ -210,5 +105,142 @@ public static class VectorMgdMgd return returnVal; } + public unsafe class HVATests where T : struct + { + // We can have up to 4 vectors in an HVA, and we'll test structs with up to 5 of them + // (to ensure that even those that are too large are handled consistently). + // So we need 5 * the element count in the largest (128-bit) vector with the smallest + // element type (byte). + static T[] values; + static T[] check; + private int ElementCount = (Unsafe.SizeOf>() / sizeof(byte)) * 5; + public bool isPassing = true; + Type[] reflectionParameterTypes; + System.Reflection.MethodInfo reflectionMethodInfo; + object[] reflectionInvokeArgs; + + public struct HVA128_02 + { + public Vector128 v0; + public Vector128 v1; + } + + private HVA128_02 hva128_02; + + public void Init_HVAs() + { + hva128_02.v0 = Unsafe.As>(ref values[0]); + hva128_02.v1 = Unsafe.As>(ref values[Vector128.Count]); + } + + public HVATests() + { + values = new T[ElementCount]; + for (int i = 0; i < values.Length; i++) + { + int data = random.Next(100); + values[i] = GetValueFromInt(data); + } + + Init_HVAs(); + } + + // Checks that the values in v correspond to those in the values array starting + // with values[index] + private void checkValues(Vector128 v, int index) + { + bool printedMsg = false; // Print at most one message + + for (int i = 0; i < Vector128.Count; i++) + { + if (!CheckValue(v.GetElement(i), values[index])) + { + if (!printedMsg) + { + Console.WriteLine("FAILED: checkValues(index = {1}, i = {2})", index, i); + printedMsg = true; + } + + isPassing = false; + } + index++; + } + } + + // Test the case where we've passed in a single argument HVA of 2 vectors. + [MethodImpl(MethodImplOptions.NoInlining)] + public void test1Argument_HVA128_02(HVA128_02 arg1) + { + checkValues(arg1.v0, 0); + checkValues(arg1.v1, Vector128.Count); + } + + // Return an HVA of 2 vectors, with values from the 'values' array. + [MethodImpl(MethodImplOptions.NoInlining)] + public HVA128_02 returnTest_HVA128_02() + { + return hva128_02; + } + + public void testReturn_HFA128_02() + { + HVA128_02 result = returnTest_HVA128_02(); + checkValues(result.v0, 0); + checkValues(result.v1, Vector128.Count); + } + + public void Init_Reflection_Args_HVA128_02() + { + reflectionParameterTypes = new Type[] { typeof(HVA128_02) }; + reflectionMethodInfo = typeof(HVATests).GetMethod(nameof(HVATests.test1Argument_HVA128_02), reflectionParameterTypes); + reflectionInvokeArgs = new object[] { hva128_02 }; + } + + public void Init_Reflection_Return_HVA128_02() + { + reflectionParameterTypes = new Type[] { }; + reflectionMethodInfo = typeof(HVATests).GetMethod(nameof(HVATests.returnTest_HVA128_02), reflectionParameterTypes); + reflectionInvokeArgs = new object[] { }; + } + + public void testReflectionReturn_HFA128_02() + { + Init_Reflection_Return_HVA128_02(); + + object objResult = reflectionMethodInfo.Invoke(this, reflectionInvokeArgs); + + HVA128_02 result = (HVA128_02)objResult; + + checkValues(result.v0, 0); + checkValues(result.v1, Vector128.Count); + } + + public void doTests() + { + // Test HVA Argumnets + + test1Argument_HVA128_02(hva128_02); + + Init_Reflection_Args_HVA128_02(); + reflectionMethodInfo.Invoke(this, reflectionInvokeArgs); + + + // Test HVA Return values + + testReturn_HFA128_02(); + + testReflectionReturn_HFA128_02(); + } + } + + public static int Main(string[] args) + { + var isPassing = true; + + HVATests byteTests = new HVATests(); + byteTests.doTests(); + + return byteTests.isPassing ? PASS : FAIL; + } }