Updating the existing HWIntrinsic tests to also test indirect calling via reflection.
authorTanner Gooding <tagoo@outlook.com>
Fri, 5 Jan 2018 04:14:03 +0000 (20:14 -0800)
committerTanner Gooding <tagoo@outlook.com>
Fri, 5 Jan 2018 04:14:03 +0000 (20:14 -0800)
tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs
tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs
tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt.cs
tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt.cs
tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs
tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs
tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32.cs

index d67aded..47624a0 100644 (file)
@@ -30,15 +30,40 @@ namespace IntelHardwareIntrinsicTest
                     var vf3 = Avx.Add(vf1, vf2);
                     Unsafe.Write(floatTable.outArrayPtr, vf3);
 
+                    if (!floatTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX Add failed on float:");
+                        foreach (var item in floatTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    vf3 = (Vector256<float>)typeof(Avx).GetMethod(nameof(Avx.Add), new Type[] { vf1.GetType(), vf2.GetType() }).Invoke(null, new object[] { vf1, vf2 });
+                    Unsafe.Write(floatTable.outArrayPtr, vf3);
+
+                    if (!floatTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX Add failed via reflection on float:");
+                        foreach (var item in floatTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
                     var vd1 = Unsafe.Read<Vector256<double>>(doubleTable.inArray1Ptr);
                     var vd2 = Unsafe.Read<Vector256<double>>(doubleTable.inArray2Ptr);
                     var vd3 = Avx.Add(vd1, vd2);
                     Unsafe.Write(doubleTable.outArrayPtr, vd3);
 
-                    if (!floatTable.CheckResult((x, y, z) => x + y == z))
+                    if (!doubleTable.CheckResult((x, y, z) => x + y == z))
                     {
-                        Console.WriteLine("AVX Add failed on float:");
-                        foreach (var item in floatTable.outArray)
+                        Console.WriteLine("AVX Add failed on double:");
+                        foreach (var item in doubleTable.outArray)
                         {
                             Console.Write(item + ", ");
                         }
@@ -46,9 +71,12 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vd3 = (Vector256<double>)typeof(Avx).GetMethod(nameof(Avx.Add), new Type[] { vd1.GetType(), vd2.GetType() }).Invoke(null, new object[] { vd1, vd2 });
+                    Unsafe.Write(doubleTable.outArrayPtr, vd3);
+
                     if (!doubleTable.CheckResult((x, y, z) => x + y == z))
                     {
-                        Console.WriteLine("AVX Add failed on double:");
+                        Console.WriteLine("AVX Add failed via reflection on double:");
                         foreach (var item in doubleTable.outArray)
                         {
                             Console.Write(item + ", ");
index 6ab142f..7a84f91 100644 (file)
@@ -37,44 +37,23 @@ namespace IntelHardwareIntrinsicTest
                     var vi3 = Avx2.Add(vi1, vi2);
                     Unsafe.Write(intTable.outArrayPtr, vi3);
 
-                    var vl1 = Unsafe.Read<Vector256<long>>(longTable.inArray1Ptr);
-                    var vl2 = Unsafe.Read<Vector256<long>>(longTable.inArray2Ptr);
-                    var vl3 = Avx2.Add(vl1, vl2);
-                    Unsafe.Write(longTable.outArrayPtr, vl3);
-
-                    var vui1 = Unsafe.Read<Vector256<uint>>(uintTable.inArray1Ptr);
-                    var vui2 = Unsafe.Read<Vector256<uint>>(uintTable.inArray2Ptr);
-                    var vui3 = Avx2.Add(vui1, vui2);
-                    Unsafe.Write(uintTable.outArrayPtr, vui3);
-
-                    var vul1 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray1Ptr);
-                    var vul2 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray2Ptr);
-                    var vul3 = Avx2.Add(vul1, vul2);
-                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
-
-                    var vs1 = Unsafe.Read<Vector256<short>>(shortTable.inArray1Ptr);
-                    var vs2 = Unsafe.Read<Vector256<short>>(shortTable.inArray2Ptr);
-                    var vs3 = Avx2.Add(vs1, vs2);
-                    Unsafe.Write(shortTable.outArrayPtr, vs3);
-
-                    var vus1 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray1Ptr);
-                    var vus2 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray2Ptr);
-                    var vus3 = Avx2.Add(vus1, vus2);
-                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
-
-                    var vsb1 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray1Ptr);
-                    var vsb2 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray2Ptr);
-                    var vsb3 = Avx2.Add(vsb1, vsb2);
-                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+                    if (!intTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed on int:");
+                        foreach (var item in intTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
 
-                    var vb1 = Unsafe.Read<Vector256<byte>>(byteTable.inArray1Ptr);
-                    var vb2 = Unsafe.Read<Vector256<byte>>(byteTable.inArray2Ptr);
-                    var vb3 = Avx2.Add(vb1, vb2);
-                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+                    vi3 = (Vector256<int>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vi1.GetType(), vi2.GetType() }).Invoke(null, new object[] { vi1, vi2 });
+                    Unsafe.Write(intTable.outArrayPtr, vi3);
 
                     if (!intTable.CheckResult((x, y, z) => x + y == z))
                     {
-                        Console.WriteLine("AVX2 Add failed on int:");
+                        Console.WriteLine("AVX2 Add failed via reflection on int:");
                         foreach (var item in intTable.outArray)
                         {
                             Console.Write(item + ", ");
@@ -83,6 +62,11 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    var vl1 = Unsafe.Read<Vector256<long>>(longTable.inArray1Ptr);
+                    var vl2 = Unsafe.Read<Vector256<long>>(longTable.inArray2Ptr);
+                    var vl3 = Avx2.Add(vl1, vl2);
+                    Unsafe.Write(longTable.outArrayPtr, vl3);
+
                     if (!longTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on long:");
@@ -94,6 +78,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vl3 = (Vector256<long>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vl1.GetType(), vl2.GetType() }).Invoke(null, new object[] { vl1, vl2 });
+                    Unsafe.Write(longTable.outArrayPtr, vl3);
+
+                    if (!longTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on long:");
+                        foreach (var item in longTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vui1 = Unsafe.Read<Vector256<uint>>(uintTable.inArray1Ptr);
+                    var vui2 = Unsafe.Read<Vector256<uint>>(uintTable.inArray2Ptr);
+                    var vui3 = Avx2.Add(vui1, vui2);
+                    Unsafe.Write(uintTable.outArrayPtr, vui3);
+
                     if (!uintTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on uint:");
@@ -105,6 +108,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vui3 = (Vector256<uint>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vui1.GetType(), vui2.GetType() }).Invoke(null, new object[] { vui1, vui2 });
+                    Unsafe.Write(uintTable.outArrayPtr, vui3);
+
+                    if (!uintTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on uint:");
+                        foreach (var item in uintTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vul1 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray1Ptr);
+                    var vul2 = Unsafe.Read<Vector256<ulong>>(ulongTable.inArray2Ptr);
+                    var vul3 = Avx2.Add(vul1, vul2);
+                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
+
                     if (!ulongTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on ulong:");
@@ -116,6 +138,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vul3 = (Vector256<ulong>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vul1.GetType(), vul2.GetType() }).Invoke(null, new object[] { vul1, vul2 });
+                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
+
+                    if (!ulongTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on ulong:");
+                        foreach (var item in ulongTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vs1 = Unsafe.Read<Vector256<short>>(shortTable.inArray1Ptr);
+                    var vs2 = Unsafe.Read<Vector256<short>>(shortTable.inArray2Ptr);
+                    var vs3 = Avx2.Add(vs1, vs2);
+                    Unsafe.Write(shortTable.outArrayPtr, vs3);
+
                     if (!shortTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on short:");
@@ -127,6 +168,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vs3 = (Vector256<short>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vs1.GetType(), vs2.GetType() }).Invoke(null, new object[] { vs1, vs2 });
+                    Unsafe.Write(shortTable.outArrayPtr, vs3);
+
+                    if (!shortTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on short:");
+                        foreach (var item in shortTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vus1 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray1Ptr);
+                    var vus2 = Unsafe.Read<Vector256<ushort>>(ushortTable.inArray2Ptr);
+                    var vus3 = Avx2.Add(vus1, vus2);
+                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
+
                     if (!ushortTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on ushort:");
@@ -138,6 +198,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vus3 = (Vector256<ushort>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vus1.GetType(), vus2.GetType() }).Invoke(null, new object[] { vus1, vus2 });
+                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
+
+                    if (!ushortTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on ushort:");
+                        foreach (var item in ushortTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vsb1 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray1Ptr);
+                    var vsb2 = Unsafe.Read<Vector256<sbyte>>(sbyteTable.inArray2Ptr);
+                    var vsb3 = Avx2.Add(vsb1, vsb2);
+                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+
                     if (!sbyteTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on sbyte:");
@@ -149,6 +228,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vsb3 = (Vector256<sbyte>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vsb1.GetType(), vsb2.GetType() }).Invoke(null, new object[] { vsb1, vsb2 });
+                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+
+                    if (!sbyteTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on sbyte:");
+                        foreach (var item in sbyteTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vb1 = Unsafe.Read<Vector256<byte>>(byteTable.inArray1Ptr);
+                    var vb2 = Unsafe.Read<Vector256<byte>>(byteTable.inArray2Ptr);
+                    var vb3 = Avx2.Add(vb1, vb2);
+                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+
                     if (!byteTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("AVX2 Add failed on byte:");
@@ -159,8 +257,21 @@ namespace IntelHardwareIntrinsicTest
                         Console.WriteLine();
                         testResult = Fail;
                     }
-                }
 
+                    vb3 = (Vector256<byte>)typeof(Avx2).GetMethod(nameof(Avx2.Add), new Type[] { vb1.GetType(), vb2.GetType() }).Invoke(null, new object[] { vb1, vb2 });
+                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+
+                    if (!byteTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("AVX2 Add failed via reflection on byte:");
+                        foreach (var item in byteTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+                }
             }
 
             return testResult;
index 9d40c08..9489233 100644 (file)
@@ -4,6 +4,7 @@
 //
 
 using System;
+using System.Reflection;
 using System.Runtime.Intrinsics.X86;
 
 namespace IntelHardwareIntrinsicTest
@@ -26,11 +27,22 @@ namespace IntelHardwareIntrinsicTest
                     Console.WriteLine("Intrinsic Lzcnt.LeadingZeroCount is called on non-supported hardware.");
                     Console.WriteLine("Lzcnt.IsSupported " + Lzcnt.IsSupported);
                     Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
-                    return Fail;
+                    testResult = Fail;
                 }
                 catch (PlatformNotSupportedException)
                 {
-                    testResult = Pass;
+                }
+
+                try
+                {
+                    resl = Convert.ToUInt64(typeof(Lzcnt).GetMethod(nameof(Lzcnt.LeadingZeroCount), new Type[] { sl.GetType() }).Invoke(null, new object[] { sl }));
+                    Console.WriteLine("Intrinsic Lzcnt.LeadingZeroCount is called via reflection on non-supported hardware.");
+                    Console.WriteLine("Lzcnt.IsSupported " + Lzcnt.IsSupported);
+                    Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
+                    testResult = Fail;
+                }
+                catch (TargetInvocationException e) when (e.InnerException is PlatformNotSupportedException)
+                {
                 }
             }
 
@@ -42,6 +54,7 @@ namespace IntelHardwareIntrinsicTest
                     for (int i = 0; i < longLzcntTable.Length; i++)
                     {
                         sl = longLzcntTable[i].s;
+
                         resl = Lzcnt.LeadingZeroCount(sl);
                         if (resl != longLzcntTable[i].res)
                         {
@@ -49,6 +62,14 @@ namespace IntelHardwareIntrinsicTest
                                 i, sl, longLzcntTable[i].res, resl);
                             testResult = Fail;
                         }
+                        
+                        resl = Convert.ToUInt64(typeof(Lzcnt).GetMethod(nameof(Lzcnt.LeadingZeroCount), new Type[] { sl.GetType() }).Invoke(null, new object[] { sl }));
+                        if (resl != longLzcntTable[i].res)
+                        {
+                            Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x} - Reflection",
+                                i, sl, longLzcntTable[i].res, resl);
+                            testResult = Fail;
+                        }
                     }
                 }
 
@@ -56,6 +77,7 @@ namespace IntelHardwareIntrinsicTest
                 for (int i = 0; i < intLzcntTable.Length; i++)
                 {
                     si = intLzcntTable[i].s;
+
                     resi = Lzcnt.LeadingZeroCount(si);
                     if (resi != intLzcntTable[i].res)
                     {
@@ -63,6 +85,14 @@ namespace IntelHardwareIntrinsicTest
                             i, si, intLzcntTable[i].res, resi);
                         testResult = Fail;
                     }
+
+                    resl = Convert.ToUInt64(typeof(Lzcnt).GetMethod(nameof(Lzcnt.LeadingZeroCount), new Type[] { si.GetType() }).Invoke(null, new object[] { si }));
+                    if (resi != intLzcntTable[i].res)
+                    {
+                        Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x} - Reflection",
+                            i, si, intLzcntTable[i].res, resi);
+                        testResult = Fail;
+                    }
                 }
             }
 
@@ -96,4 +126,4 @@ namespace IntelHardwareIntrinsicTest
             new LZCNT<uint>(0x0005423fU, 13)
         };
     }
-}
\ No newline at end of file
+}
index 20c443b..fd2bdf5 100644 (file)
@@ -4,6 +4,7 @@
 //
 
 using System;
+using System.Reflection;
 using System.Runtime.Intrinsics.X86;
 
 namespace IntelHardwareIntrinsicTest
@@ -27,11 +28,22 @@ namespace IntelHardwareIntrinsicTest
                     Console.WriteLine("Intrinsic Popcnt.PopCount is called on non-supported hardware");
                     Console.WriteLine("Popcnt.IsSupported " + Popcnt.IsSupported);
                     Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
-                    return Fail;
+                    testResult = Fail;
                 }
                 catch (PlatformNotSupportedException)
                 {
-                    testResult = Pass;
+                }
+
+                try
+                {
+                    resl = Convert.ToInt64(typeof(Popcnt).GetMethod(nameof(Popcnt.PopCount), new Type[] { sl.GetType() }).Invoke(null, new object[] { sl }));
+                    Console.WriteLine("Intrinsic Popcnt.PopCount is called via reflection on non-supported hardware");
+                    Console.WriteLine("Popcnt.IsSupported " + Popcnt.IsSupported);
+                    Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
+                    testResult = Fail;
+                }
+                catch (TargetInvocationException e) when (e.InnerException is PlatformNotSupportedException)
+                {
                 }
             }
 
@@ -43,6 +55,7 @@ namespace IntelHardwareIntrinsicTest
                     for (int i = 0; i < longPopcntTable.Length; i++)
                     {
                         sl = longPopcntTable[i].s;
+
                         resl = Popcnt.PopCount(sl);
                         if (resl != longPopcntTable[i].res)
                         {
@@ -50,6 +63,14 @@ namespace IntelHardwareIntrinsicTest
                                 i, sl, longPopcntTable[i].res, resl);
                             testResult = Fail;
                         }
+
+                        resl = Convert.ToInt64(typeof(Popcnt).GetMethod(nameof(Popcnt.PopCount), new Type[] { sl.GetType() }).Invoke(null, new object[] { sl }));
+                        if (resl != longPopcntTable[i].res)
+                        {
+                            Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x} - Reflection",
+                                i, sl, longPopcntTable[i].res, resl);
+                            testResult = Fail;
+                        }
                     }
                 }
 
@@ -58,6 +79,7 @@ namespace IntelHardwareIntrinsicTest
                 for (int i = 0; i < intPopcntTable.Length; i++)
                 {
                     si = intPopcntTable[i].s;
+
                     resi = Popcnt.PopCount(si);
                     if (resi != intPopcntTable[i].res)
                     {
@@ -65,6 +87,14 @@ namespace IntelHardwareIntrinsicTest
                             i, si, intPopcntTable[i].res, resi);
                         testResult = Fail;
                     }
+
+                    resi = Convert.ToInt32(typeof(Popcnt).GetMethod(nameof(Popcnt.PopCount), new Type[] { si.GetType() }).Invoke(null, new object[] { si }));
+                    if (resi != intPopcntTable[i].res)
+                    {
+                        Console.WriteLine("{0}: Inputs: 0x{1,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x} - Reflection",
+                            i, si, intPopcntTable[i].res, resi);
+                        testResult = Fail;
+                    }
                 }
             }
 
@@ -98,4 +128,4 @@ namespace IntelHardwareIntrinsicTest
             new POPCNT<uint,int>(0x0005423fU, 10)
         };
     }
-}
\ No newline at end of file
+}
index 490bb2a..97f8111 100644 (file)
@@ -40,10 +40,23 @@ namespace IntelHardwareIntrinsicTest
                         Console.WriteLine();
                         testResult = Fail;
                     }
+
+                    vf3 = (Vector128<float>)typeof(Sse).GetMethod(nameof(Sse.Add), new Type[] { vf1.GetType(), vf2.GetType() }).Invoke(null, new object[] { vf1, vf2 });
+                    Unsafe.Write(floatTable.outArrayPtr, vf3);
+
+                    if (!floatTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE Add failed via reflection on float:");
+                        foreach (var item in floatTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
                 }
             }
 
-
             return testResult;
         }
 
index 7c25578..3d4458c 100644 (file)
@@ -37,49 +37,53 @@ namespace IntelHardwareIntrinsicTest
                     var vd3 = Sse2.Add(vd1, vd2);
                     Unsafe.Write(doubleTable.outArrayPtr, vd3);
 
+                    if (!doubleTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed on double:");
+                        foreach (var item in doubleTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    vd3 = (Vector128<double>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vd1.GetType(), vd2.GetType() }).Invoke(null, new object[] { vd1, vd2 });
+                    Unsafe.Write(doubleTable.outArrayPtr, vd3);
+
+                    if (!doubleTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on double:");
+                        foreach (var item in doubleTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
                     var vi1 = Unsafe.Read<Vector128<int>>(intTable.inArray1Ptr);
                     var vi2 = Unsafe.Read<Vector128<int>>(intTable.inArray2Ptr);
                     var vi3 = Sse2.Add(vi1, vi2);
                     Unsafe.Write(intTable.outArrayPtr, vi3);
-                    var vl1 = Unsafe.Read<Vector128<long>>(longTable.inArray1Ptr);
-                    var vl2 = Unsafe.Read<Vector128<long>>(longTable.inArray2Ptr);
-                    var vl3 = Sse2.Add(vl1, vl2);
-                    Unsafe.Write(longTable.outArrayPtr, vl3);
-
-                    var vui1 = Unsafe.Read<Vector128<uint>>(uintTable.inArray1Ptr);
-                    var vui2 = Unsafe.Read<Vector128<uint>>(uintTable.inArray2Ptr);
-                    var vui3 = Sse2.Add(vui1, vui2);
-                    Unsafe.Write(uintTable.outArrayPtr, vui3);
-                    var vul1 = Unsafe.Read<Vector128<ulong>>(ulongTable.inArray1Ptr);
-                    var vul2 = Unsafe.Read<Vector128<ulong>>(ulongTable.inArray2Ptr);
-                    var vul3 = Sse2.Add(vul1, vul2);
-                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
-
-                    var vs1 = Unsafe.Read<Vector128<short>>(shortTable.inArray1Ptr);
-                    var vs2 = Unsafe.Read<Vector128<short>>(shortTable.inArray2Ptr);
-                    var vs3 = Sse2.Add(vs1, vs2);
-                    Unsafe.Write(shortTable.outArrayPtr, vs3);
-
-                    var vus1 = Unsafe.Read<Vector128<ushort>>(ushortTable.inArray1Ptr);
-                    var vus2 = Unsafe.Read<Vector128<ushort>>(ushortTable.inArray2Ptr);
-                    var vus3 = Sse2.Add(vus1, vus2);
-                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
 
-                    var vsb1 = Unsafe.Read<Vector128<sbyte>>(sbyteTable.inArray1Ptr);
-                    var vsb2 = Unsafe.Read<Vector128<sbyte>>(sbyteTable.inArray2Ptr);
-                    var vsb3 = Sse2.Add(vsb1, vsb2);
-                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+                    if (!intTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed on int:");
+                        foreach (var item in intTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
 
-                    var vb1 = Unsafe.Read<Vector128<byte>>(byteTable.inArray1Ptr);
-                    var vb2 = Unsafe.Read<Vector128<byte>>(byteTable.inArray2Ptr);
-                    var vb3 = Sse2.Add(vb1, vb2);
-                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+                    vi3 = (Vector128<int>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vi1.GetType(), vi2.GetType() }).Invoke(null, new object[] { vi1, vi2 });
+                    Unsafe.Write(intTable.outArrayPtr, vi3);
 
                     if (!intTable.CheckResult((x, y, z) => x + y == z))
                     {
-                        Console.WriteLine("SSE2 Add failed on int:");
+                        Console.WriteLine("SSE2 Add failed via reflection on int:");
                         foreach (var item in intTable.outArray)
                         {
                             Console.Write(item + ", ");
@@ -88,6 +92,11 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    var vl1 = Unsafe.Read<Vector128<long>>(longTable.inArray1Ptr);
+                    var vl2 = Unsafe.Read<Vector128<long>>(longTable.inArray2Ptr);
+                    var vl3 = Sse2.Add(vl1, vl2);
+                    Unsafe.Write(longTable.outArrayPtr, vl3);
+
                     if (!longTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on long:");
@@ -99,6 +108,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vl3 = (Vector128<long>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vl1.GetType(), vl2.GetType() }).Invoke(null, new object[] { vl1, vl2 });
+                    Unsafe.Write(longTable.outArrayPtr, vl3);
+
+                    if (!longTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on long:");
+                        foreach (var item in longTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vui1 = Unsafe.Read<Vector128<uint>>(uintTable.inArray1Ptr);
+                    var vui2 = Unsafe.Read<Vector128<uint>>(uintTable.inArray2Ptr);
+                    var vui3 = Sse2.Add(vui1, vui2);
+                    Unsafe.Write(uintTable.outArrayPtr, vui3);
+
                     if (!uintTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on uint:");
@@ -110,6 +138,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vui3 = (Vector128<uint>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vui1.GetType(), vui2.GetType() }).Invoke(null, new object[] { vui1, vui2 });
+                    Unsafe.Write(uintTable.outArrayPtr, vui3);
+
+                    if (!uintTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on uint:");
+                        foreach (var item in uintTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vul1 = Unsafe.Read<Vector128<ulong>>(ulongTable.inArray1Ptr);
+                    var vul2 = Unsafe.Read<Vector128<ulong>>(ulongTable.inArray2Ptr);
+                    var vul3 = Sse2.Add(vul1, vul2);
+                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
+
                     if (!ulongTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on ulong:");
@@ -121,6 +168,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vul3 = (Vector128<ulong>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vul1.GetType(), vul2.GetType() }).Invoke(null, new object[] { vul1, vul2 });
+                    Unsafe.Write(ulongTable.outArrayPtr, vul3);
+
+                    if (!ulongTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on ulong:");
+                        foreach (var item in ulongTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vs1 = Unsafe.Read<Vector128<short>>(shortTable.inArray1Ptr);
+                    var vs2 = Unsafe.Read<Vector128<short>>(shortTable.inArray2Ptr);
+                    var vs3 = Sse2.Add(vs1, vs2);
+                    Unsafe.Write(shortTable.outArrayPtr, vs3);
+
                     if (!shortTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on short:");
@@ -132,6 +198,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vs3 = (Vector128<short>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vs1.GetType(), vs2.GetType() }).Invoke(null, new object[] { vs1, vs2 });
+                    Unsafe.Write(shortTable.outArrayPtr, vs3);
+
+                    if (!shortTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on short:");
+                        foreach (var item in shortTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vus1 = Unsafe.Read<Vector128<ushort>>(ushortTable.inArray1Ptr);
+                    var vus2 = Unsafe.Read<Vector128<ushort>>(ushortTable.inArray2Ptr);
+                    var vus3 = Sse2.Add(vus1, vus2);
+                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
+
                     if (!ushortTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on ushort:");
@@ -143,10 +228,13 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
-                    if (!doubleTable.CheckResult((x, y, z) => x + y == z))
+                    vus3 = (Vector128<ushort>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vus1.GetType(), vus2.GetType() }).Invoke(null, new object[] { vus1, vus2 });
+                    Unsafe.Write(ushortTable.outArrayPtr, vus3);
+
+                    if (!ushortTable.CheckResult((x, y, z) => x + y == z))
                     {
-                        Console.WriteLine("SSE2 Add failed on double:");
-                        foreach (var item in doubleTable.outArray)
+                        Console.WriteLine("SSE2 Add failed via reflection on ushort:");
+                        foreach (var item in ushortTable.outArray)
                         {
                             Console.Write(item + ", ");
                         }
@@ -154,6 +242,11 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    var vsb1 = Unsafe.Read<Vector128<sbyte>>(sbyteTable.inArray1Ptr);
+                    var vsb2 = Unsafe.Read<Vector128<sbyte>>(sbyteTable.inArray2Ptr);
+                    var vsb3 = Sse2.Add(vsb1, vsb2);
+                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+
                     if (!sbyteTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on sbyte:");
@@ -165,6 +258,25 @@ namespace IntelHardwareIntrinsicTest
                         testResult = Fail;
                     }
 
+                    vsb3 = (Vector128<sbyte>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vsb1.GetType(), vsb2.GetType() }).Invoke(null, new object[] { vsb1, vsb2 });
+                    Unsafe.Write(sbyteTable.outArrayPtr, vsb3);
+
+                    if (!sbyteTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on sbyte:");
+                        foreach (var item in sbyteTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+
+                    var vb1 = Unsafe.Read<Vector128<byte>>(byteTable.inArray1Ptr);
+                    var vb2 = Unsafe.Read<Vector128<byte>>(byteTable.inArray2Ptr);
+                    var vb3 = Sse2.Add(vb1, vb2);
+                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+
                     if (!byteTable.CheckResult((x, y, z) => x + y == z))
                     {
                         Console.WriteLine("SSE2 Add failed on byte:");
@@ -175,6 +287,21 @@ namespace IntelHardwareIntrinsicTest
                         Console.WriteLine();
                         testResult = Fail;
                     }
+
+                    vb3 = (Vector128<byte>)typeof(Sse2).GetMethod(nameof(Sse2.Add), new Type[] { vb1.GetType(), vb2.GetType() }).Invoke(null, new object[] { vb1, vb2 });
+                    Unsafe.Write(byteTable.outArrayPtr, vb3);
+
+                    if (!byteTable.CheckResult((x, y, z) => x + y == z))
+                    {
+                        Console.WriteLine("SSE2 Add failed via reflection on byte:");
+                        foreach (var item in byteTable.outArray)
+                        {
+                            Console.Write(item + ", ");
+                        }
+                        Console.WriteLine();
+                        testResult = Fail;
+                    }
+                
                 }
             }
 
index 27ea5a9..043bcbb 100644 (file)
@@ -4,6 +4,7 @@
 //
 
 using System;
+using System.Reflection;
 using System.Runtime.Intrinsics.X86;
 
 namespace IntelHardwareIntrinsicTest
@@ -26,11 +27,22 @@ namespace IntelHardwareIntrinsicTest
                     Console.WriteLine("Intrinsic Sse42.Crc32 is called on non-supported hardware.");
                     Console.WriteLine("Sse42.IsSupported " + Sse42.IsSupported);
                     Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
-                    return Fail;
+                    testResult = Fail;
                 }
                 catch (PlatformNotSupportedException)
                 {
-                    testResult = Pass;
+                }
+
+                try
+                {
+                    resl = Convert.ToUInt64(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { s1l.GetType(), s2l.GetType() }).Invoke(null, new object[] { s1l, s2l }));
+                    Console.WriteLine("Intrinsic Sse42.Crc32 is called via reflection on non-supported hardware.");
+                    Console.WriteLine("Sse42.IsSupported " + Sse42.IsSupported);
+                    Console.WriteLine("Environment.Is64BitProcess " + Environment.Is64BitProcess);
+                    testResult = Fail;
+                }
+                catch (TargetInvocationException e) when (e.InnerException is PlatformNotSupportedException)
+                {
                 }
             }
 
@@ -43,6 +55,7 @@ namespace IntelHardwareIntrinsicTest
                     {
                         s1l = longCrcTable[i].s1;
                         s2l = longCrcTable[i].s2;
+
                         resl = Sse42.Crc32(s1l, s2l);
                         if (resl != longCrcTable[i].res)
                         {
@@ -50,6 +63,14 @@ namespace IntelHardwareIntrinsicTest
                                 i, s1l, s2l, longCrcTable[i].res, resl);
                             testResult = Fail;
                         }
+
+                        resl = Convert.ToUInt64(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { s1l.GetType(), s2l.GetType() }).Invoke(null, new object[] { s1l, s2l }));
+                        if (resl != longCrcTable[i].res)
+                        {
+                            Console.WriteLine("{0}: Inputs: 0x{1,16:x}, 0x{2,16:x} Expected: 0x{3,16:x} actual: 0x{4,16:x} - Reflection",
+                                i, s1l, s2l, longCrcTable[i].res, resl);
+                            testResult = Fail;
+                        }
                     }
                 }
 
@@ -58,6 +79,7 @@ namespace IntelHardwareIntrinsicTest
                 {
                     s1i = intCrcTable[i].s1;
                     s2i = intCrcTable[i].s2;
+
                     resi = Sse42.Crc32(s1i, s2i);
                     if (resi != intCrcTable[i].res)
                     {
@@ -65,6 +87,14 @@ namespace IntelHardwareIntrinsicTest
                             i, s1i, s2i, intCrcTable[i].res, resi);
                         testResult = Fail;
                     }
+
+                    resi = Convert.ToUInt32(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { s1i.GetType(), s2i.GetType() }).Invoke(null, new object[] { s1i, s2i }));
+                    if (resi != intCrcTable[i].res)
+                    {
+                        Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x} - Reflection",
+                            i, s1i, s2i, intCrcTable[i].res, resi);
+                        testResult = Fail;
+                    }
                 }
 
                 ushort s2s;
@@ -72,6 +102,7 @@ namespace IntelHardwareIntrinsicTest
                 {
                     s1i = shortCrcTable[i].s1;
                     s2s = shortCrcTable[i].s2;
+
                     resi = Sse42.Crc32(s1i, s2s);
                     if (resi != shortCrcTable[i].res)
                     {
@@ -79,6 +110,14 @@ namespace IntelHardwareIntrinsicTest
                             i, s1i, s2s, shortCrcTable[i].res, resi);
                         testResult = Fail;
                     }
+
+                    resi = Convert.ToUInt32(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { s1i.GetType(), s2s.GetType() }).Invoke(null, new object[] { s1i, s2s }));
+                    if (resi != shortCrcTable[i].res)
+                    {
+                        Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x} - Reflection",
+                            i, s1i, s2s, shortCrcTable[i].res, resi);
+                        testResult = Fail;
+                    }
                 }
 
                 byte s2b;
@@ -86,6 +125,7 @@ namespace IntelHardwareIntrinsicTest
                 {
                     s1i = byteCrcTable[i].s1;
                     s2b = byteCrcTable[i].s2;
+
                     resi = Sse42.Crc32(s1i, s2b);
                     if (resi != byteCrcTable[i].res)
                     {
@@ -93,6 +133,14 @@ namespace IntelHardwareIntrinsicTest
                             i, s1i, s2b, byteCrcTable[i].res, resi);
                         testResult = Fail;
                     }
+
+                    resi = Convert.ToUInt32(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { s1i.GetType(), s2b.GetType() }).Invoke(null, new object[] { s1i, s2b }));
+                    if (resi != byteCrcTable[i].res)
+                    {
+                        Console.WriteLine("{0}: Inputs: 0x{1,8:x}, 0x{2,8:x} Expected: 0x{3,8:x} actual: 0x{4,8:x}",
+                            i, s1i, s2b, byteCrcTable[i].res, resi);
+                        testResult = Fail;
+                    }
                 }
             }
 
@@ -177,4 +225,4 @@ namespace IntelHardwareIntrinsicTest
         };
 
     }
-}
\ No newline at end of file
+}