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 + ", ");
}
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 + ", ");
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 + ", ");
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:");
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:");
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:");
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:");
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:");
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:");
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:");
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;
//
using System;
+using System.Reflection;
using System.Runtime.Intrinsics.X86;
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)
+ {
}
}
for (int i = 0; i < longLzcntTable.Length; i++)
{
sl = longLzcntTable[i].s;
+
resl = Lzcnt.LeadingZeroCount(sl);
if (resl != longLzcntTable[i].res)
{
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;
+ }
}
}
for (int i = 0; i < intLzcntTable.Length; i++)
{
si = intLzcntTable[i].s;
+
resi = Lzcnt.LeadingZeroCount(si);
if (resi != intLzcntTable[i].res)
{
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;
+ }
}
}
new LZCNT<uint>(0x0005423fU, 13)
};
}
-}
\ No newline at end of file
+}
//
using System;
+using System.Reflection;
using System.Runtime.Intrinsics.X86;
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)
+ {
}
}
for (int i = 0; i < longPopcntTable.Length; i++)
{
sl = longPopcntTable[i].s;
+
resl = Popcnt.PopCount(sl);
if (resl != longPopcntTable[i].res)
{
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;
+ }
}
}
for (int i = 0; i < intPopcntTable.Length; i++)
{
si = intPopcntTable[i].s;
+
resi = Popcnt.PopCount(si);
if (resi != intPopcntTable[i].res)
{
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;
+ }
}
}
new POPCNT<uint,int>(0x0005423fU, 10)
};
}
-}
\ No newline at end of file
+}
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;
}
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 + ", ");
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:");
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:");
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:");
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:");
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:");
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 + ", ");
}
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:");
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:");
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;
+ }
+
}
}
//
using System;
+using System.Reflection;
using System.Runtime.Intrinsics.X86;
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)
+ {
}
}
{
s1l = longCrcTable[i].s1;
s2l = longCrcTable[i].s2;
+
resl = Sse42.Crc32(s1l, s2l);
if (resl != longCrcTable[i].res)
{
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;
+ }
}
}
{
s1i = intCrcTable[i].s1;
s2i = intCrcTable[i].s2;
+
resi = Sse42.Crc32(s1i, s2i);
if (resi != intCrcTable[i].res)
{
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;
{
s1i = shortCrcTable[i].s1;
s2s = shortCrcTable[i].s2;
+
resi = Sse42.Crc32(s1i, s2s);
if (resi != shortCrcTable[i].res)
{
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;
{
s1i = byteCrcTable[i].s1;
s2b = byteCrcTable[i].s2;
+
resi = Sse42.Crc32(s1i, s2b);
if (resi != byteCrcTable[i].res)
{
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;
+ }
}
}
};
}
-}
\ No newline at end of file
+}