From c127fa74fde9143e39d1cdf979aee21f31d3d31d Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 22 Dec 2017 11:11:08 -0800 Subject: [PATCH] Organizing the tests/src/JIT/HardwareIntrinsics/X86 folder by ISA to make it more manageable. (#15617) --- tests/src/JIT/HardwareIntrinsics/X86/Add.cs | 428 --------------------- tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs | 109 ++++++ .../HardwareIntrinsics/X86/{ => Avx}/Add_r.csproj | 2 +- .../HardwareIntrinsics/X86/{ => Avx}/Add_ro.csproj | 2 +- tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs | 213 ++++++++++ .../JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj | 34 ++ .../JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj | 34 ++ .../HardwareIntrinsics/X86/{ => Lzcnt}/Lzcnt.cs | 0 .../X86/{ => Lzcnt}/Lzcnt_r.csproj | 2 +- .../X86/{ => Lzcnt}/Lzcnt_ro.csproj | 2 +- .../HardwareIntrinsics/X86/{ => Popcnt}/Popcnt.cs | 0 .../X86/{ => Popcnt}/Popcnt_r.csproj | 2 +- .../X86/{ => Popcnt}/Popcnt_ro.csproj | 2 +- tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs | 94 +++++ .../JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj | 34 ++ .../JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj | 34 ++ tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs | 229 +++++++++++ .../JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj | 34 ++ .../JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj | 34 ++ .../HardwareIntrinsics/X86/{ => Sse42}/Crc32.cs | 0 .../X86/{ => Sse42}/Crc32_r.csproj | 2 +- .../X86/{ => Sse42}/Crc32_ro.csproj | 2 +- 22 files changed, 857 insertions(+), 436 deletions(-) delete mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Add.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs rename tests/src/JIT/HardwareIntrinsics/X86/{ => Avx}/Add_r.csproj (99%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Avx}/Add_ro.csproj (99%) create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj rename tests/src/JIT/HardwareIntrinsics/X86/{ => Lzcnt}/Lzcnt.cs (100%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Lzcnt}/Lzcnt_r.csproj (99%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Lzcnt}/Lzcnt_ro.csproj (99%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Popcnt}/Popcnt.cs (100%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Popcnt}/Popcnt_r.csproj (99%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Popcnt}/Popcnt_ro.csproj (99%) create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj rename tests/src/JIT/HardwareIntrinsics/X86/{ => Sse42}/Crc32.cs (100%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Sse42}/Crc32_r.csproj (99%) rename tests/src/JIT/HardwareIntrinsics/X86/{ => Sse42}/Crc32_ro.csproj (99%) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Add.cs deleted file mode 100644 index cf39254..0000000 --- a/tests/src/JIT/HardwareIntrinsics/X86/Add.cs +++ /dev/null @@ -1,428 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.X86; -using System.Runtime.Intrinsics; - -namespace IntelHardwareIntrinsicTest -{ - class Program - { - const int Pass = 100; - const int Fail = 0; - - static unsafe int Main(string[] args) - { - int testResult = Pass; - - if (Avx.IsSupported) - { - using (TestTable floatTable = new TestTable(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8])) - using (TestTable doubleTable = new TestTable(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) - { - var vf1 = Unsafe.Read>(floatTable.inArray1Ptr); - var vf2 = Unsafe.Read>(floatTable.inArray2Ptr); - var vf3 = Avx.Add(vf1, vf2); - Unsafe.Write(floatTable.outArrayPtr, vf3); - - var vd1 = Unsafe.Read>(doubleTable.inArray1Ptr); - var vd2 = Unsafe.Read>(doubleTable.inArray2Ptr); - var vd3 = Avx.Add(vd1, vd2); - Unsafe.Write(doubleTable.outArrayPtr, vd3); - - if (!floatTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX Add failed on float:"); - foreach (var item in floatTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!doubleTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX Add failed on double:"); - foreach (var item in doubleTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - } - } - - if (Avx2.IsSupported) - { - using (TestTable intTable = new TestTable(new int[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new int[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new int[8])) - using (TestTable longTable = new TestTable(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) - using (TestTable uintTable = new TestTable(new uint[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new uint[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new uint[8])) - using (TestTable ulongTable = new TestTable(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) - using (TestTable shortTable = new TestTable(new short[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new short[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new short[16])) - using (TestTable ushortTable = new TestTable(new ushort[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[16])) - using (TestTable sbyteTable = new TestTable(new sbyte[32] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[32] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[32])) - using (TestTable byteTable = new TestTable(new byte[32] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[32] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[32])) - { - - var vi1 = Unsafe.Read>(intTable.inArray1Ptr); - var vi2 = Unsafe.Read>(intTable.inArray2Ptr); - var vi3 = Avx2.Add(vi1, vi2); - Unsafe.Write(intTable.outArrayPtr, vi3); - - var vl1 = Unsafe.Read>(longTable.inArray1Ptr); - var vl2 = Unsafe.Read>(longTable.inArray2Ptr); - var vl3 = Avx2.Add(vl1, vl2); - Unsafe.Write(longTable.outArrayPtr, vl3); - - var vui1 = Unsafe.Read>(uintTable.inArray1Ptr); - var vui2 = Unsafe.Read>(uintTable.inArray2Ptr); - var vui3 = Avx2.Add(vui1, vui2); - Unsafe.Write(uintTable.outArrayPtr, vui3); - - var vul1 = Unsafe.Read>(ulongTable.inArray1Ptr); - var vul2 = Unsafe.Read>(ulongTable.inArray2Ptr); - var vul3 = Avx2.Add(vul1, vul2); - Unsafe.Write(ulongTable.outArrayPtr, vul3); - - var vs1 = Unsafe.Read>(shortTable.inArray1Ptr); - var vs2 = Unsafe.Read>(shortTable.inArray2Ptr); - var vs3 = Avx2.Add(vs1, vs2); - Unsafe.Write(shortTable.outArrayPtr, vs3); - - var vus1 = Unsafe.Read>(ushortTable.inArray1Ptr); - var vus2 = Unsafe.Read>(ushortTable.inArray2Ptr); - var vus3 = Avx2.Add(vus1, vus2); - Unsafe.Write(ushortTable.outArrayPtr, vus3); - - var vsb1 = Unsafe.Read>(sbyteTable.inArray1Ptr); - var vsb2 = Unsafe.Read>(sbyteTable.inArray2Ptr); - var vsb3 = Avx2.Add(vsb1, vsb2); - Unsafe.Write(sbyteTable.outArrayPtr, vsb3); - - var vb1 = Unsafe.Read>(byteTable.inArray1Ptr); - var vb2 = Unsafe.Read>(byteTable.inArray2Ptr); - var vb3 = Avx2.Add(vb1, vb2); - Unsafe.Write(byteTable.outArrayPtr, vb3); - - if (!intTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on int:"); - foreach (var item in intTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!longTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on long:"); - foreach (var item in longTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!uintTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on uint:"); - foreach (var item in uintTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!ulongTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on ulong:"); - foreach (var item in ulongTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!shortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on short:"); - foreach (var item in shortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!ushortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on ushort:"); - foreach (var item in ushortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on sbyte:"); - foreach (var item in sbyteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!byteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("AVX2 Add failed on byte:"); - foreach (var item in byteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - } - - } - - if (Sse2.IsSupported) - { - using (TestTable floatTable = new TestTable(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) - using (TestTable doubleTable = new TestTable(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) - using (TestTable intTable = new TestTable(new int[4] { 1, -5, 100, 0 }, new int[4] { 22, -1, -50, 0 }, new int[4])) - using (TestTable longTable = new TestTable(new long[2] { 1, -5 }, new long[2] { 22, -1 }, new long[2])) - using (TestTable uintTable = new TestTable(new uint[4] { 1, 5, 100, 0 }, new uint[4] { 22, 1, 50, 0 }, new uint[4])) - using (TestTable ulongTable = new TestTable(new ulong[2] { 1, 5 }, new ulong[2] { 22, 1 }, new ulong[2])) - using (TestTable shortTable = new TestTable(new short[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new short[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new short[8])) - using (TestTable ushortTable = new TestTable(new ushort[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[8])) - using (TestTable sbyteTable = new TestTable(new sbyte[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[16])) - using (TestTable byteTable = new TestTable(new byte[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[16])) - { - - var vf1 = Unsafe.Read>(floatTable.inArray1Ptr); - var vf2 = Unsafe.Read>(floatTable.inArray2Ptr); - var vf3 = Sse.Add(vf1, vf2); - Unsafe.Write(floatTable.outArrayPtr, vf3); - - var vd1 = Unsafe.Read>(doubleTable.inArray1Ptr); - var vd2 = Unsafe.Read>(doubleTable.inArray2Ptr); - var vd3 = Sse2.Add(vd1, vd2); - Unsafe.Write(doubleTable.outArrayPtr, vd3); - var vi1 = Unsafe.Read>(intTable.inArray1Ptr); - var vi2 = Unsafe.Read>(intTable.inArray2Ptr); - var vi3 = Sse2.Add(vi1, vi2); - Unsafe.Write(intTable.outArrayPtr, vi3); - - var vl1 = Unsafe.Read>(longTable.inArray1Ptr); - var vl2 = Unsafe.Read>(longTable.inArray2Ptr); - var vl3 = Sse2.Add(vl1, vl2); - Unsafe.Write(longTable.outArrayPtr, vl3); - - var vui1 = Unsafe.Read>(uintTable.inArray1Ptr); - var vui2 = Unsafe.Read>(uintTable.inArray2Ptr); - var vui3 = Sse2.Add(vui1, vui2); - Unsafe.Write(uintTable.outArrayPtr, vui3); - - var vul1 = Unsafe.Read>(ulongTable.inArray1Ptr); - var vul2 = Unsafe.Read>(ulongTable.inArray2Ptr); - var vul3 = Sse2.Add(vul1, vul2); - Unsafe.Write(ulongTable.outArrayPtr, vul3); - - var vs1 = Unsafe.Read>(shortTable.inArray1Ptr); - var vs2 = Unsafe.Read>(shortTable.inArray2Ptr); - var vs3 = Sse2.Add(vs1, vs2); - Unsafe.Write(shortTable.outArrayPtr, vs3); - - var vus1 = Unsafe.Read>(ushortTable.inArray1Ptr); - var vus2 = Unsafe.Read>(ushortTable.inArray2Ptr); - var vus3 = Sse2.Add(vus1, vus2); - Unsafe.Write(ushortTable.outArrayPtr, vus3); - - var vsb1 = Unsafe.Read>(sbyteTable.inArray1Ptr); - var vsb2 = Unsafe.Read>(sbyteTable.inArray2Ptr); - var vsb3 = Sse2.Add(vsb1, vsb2); - Unsafe.Write(sbyteTable.outArrayPtr, vsb3); - - var vb1 = Unsafe.Read>(byteTable.inArray1Ptr); - var vb2 = Unsafe.Read>(byteTable.inArray2Ptr); - var vb3 = Sse2.Add(vb1, vb2); - Unsafe.Write(byteTable.outArrayPtr, vb3); - - if (!intTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on int:"); - foreach (var item in intTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!longTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on long:"); - foreach (var item in longTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!uintTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on uint:"); - foreach (var item in uintTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!ulongTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on ulong:"); - foreach (var item in ulongTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!shortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on short:"); - foreach (var item in shortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!ushortTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on ushort:"); - foreach (var item in ushortTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!floatTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE Add failed on float:"); - foreach (var item in floatTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!doubleTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on double:"); - foreach (var item in doubleTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on sbyte:"); - foreach (var item in sbyteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - - if (!byteTable.CheckResult((x, y, z) => x + y == z)) - { - Console.WriteLine("SSE2 Add failed on byte:"); - foreach (var item in byteTable.outArray) - { - Console.Write(item + ", "); - } - Console.WriteLine(); - testResult = Fail; - } - } - } - - - return testResult; - } - - public unsafe struct TestTable : IDisposable where T : struct - { - public T[] inArray1; - public T[] inArray2; - public T[] outArray; - - public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); - public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); - public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); - - GCHandle inHandle1; - GCHandle inHandle2; - GCHandle outHandle; - public TestTable(T[] a, T[] b, T[] c) - { - this.inArray1 = a; - this.inArray2 = b; - this.outArray = c; - - inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); - inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); - outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); - } - public bool CheckResult(Func check) - { - for (int i = 0; i < inArray1.Length; i++) - { - if (!check(inArray1[i], inArray2[i], outArray[i])) - { - return false; - } - } - return true; - } - - public void Dispose() - { - inHandle1.Free(); - inHandle2.Free(); - outHandle.Free(); - } - } - - } -} \ No newline at end of file diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs new file mode 100644 index 0000000..d67aded --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; +using System.Runtime.Intrinsics; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static unsafe int Main(string[] args) + { + int testResult = Pass; + + if (Avx.IsSupported) + { + using (TestTable floatTable = new TestTable(new float[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new float[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new float[8])) + using (TestTable doubleTable = new TestTable(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) + { + var vf1 = Unsafe.Read>(floatTable.inArray1Ptr); + var vf2 = Unsafe.Read>(floatTable.inArray2Ptr); + var vf3 = Avx.Add(vf1, vf2); + Unsafe.Write(floatTable.outArrayPtr, vf3); + + var vd1 = Unsafe.Read>(doubleTable.inArray1Ptr); + var vd2 = Unsafe.Read>(doubleTable.inArray2Ptr); + var vd3 = Avx.Add(vd1, vd2); + Unsafe.Write(doubleTable.outArrayPtr, vd3); + + if (!floatTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX Add failed on float:"); + foreach (var item in floatTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!doubleTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX Add failed on double:"); + foreach (var item in doubleTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + } + } + + return testResult; + } + + public unsafe struct TestTable : IDisposable where T : struct + { + public T[] inArray1; + public T[] inArray2; + public T[] outArray; + + public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); + public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle1; + GCHandle inHandle2; + GCHandle outHandle; + public TestTable(T[] a, T[] b, T[] c) + { + this.inArray1 = a; + this.inArray2 = b; + this.outArray = c; + + inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); + inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + for (int i = 0; i < inArray1.Length; i++) + { + if (!check(inArray1[i], inArray2[i], outArray[i])) + { + return false; + } + } + return true; + } + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Add_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_r.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Add_r.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_r.csproj index 6179540..376806f 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Add_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_r.csproj @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj index 7c5ee7c..0b1b518 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs new file mode 100644 index 0000000..6ab142f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add.cs @@ -0,0 +1,213 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; +using System.Runtime.Intrinsics; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static unsafe int Main(string[] args) + { + int testResult = Pass; + + if (Avx2.IsSupported) + { + using (TestTable intTable = new TestTable(new int[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new int[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new int[8])) + using (TestTable longTable = new TestTable(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) + using (TestTable uintTable = new TestTable(new uint[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new uint[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new uint[8])) + using (TestTable ulongTable = new TestTable(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) + using (TestTable shortTable = new TestTable(new short[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new short[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new short[16])) + using (TestTable ushortTable = new TestTable(new ushort[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[16])) + using (TestTable sbyteTable = new TestTable(new sbyte[32] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[32] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[32])) + using (TestTable byteTable = new TestTable(new byte[32] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[32] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[32])) + { + + var vi1 = Unsafe.Read>(intTable.inArray1Ptr); + var vi2 = Unsafe.Read>(intTable.inArray2Ptr); + var vi3 = Avx2.Add(vi1, vi2); + Unsafe.Write(intTable.outArrayPtr, vi3); + + var vl1 = Unsafe.Read>(longTable.inArray1Ptr); + var vl2 = Unsafe.Read>(longTable.inArray2Ptr); + var vl3 = Avx2.Add(vl1, vl2); + Unsafe.Write(longTable.outArrayPtr, vl3); + + var vui1 = Unsafe.Read>(uintTable.inArray1Ptr); + var vui2 = Unsafe.Read>(uintTable.inArray2Ptr); + var vui3 = Avx2.Add(vui1, vui2); + Unsafe.Write(uintTable.outArrayPtr, vui3); + + var vul1 = Unsafe.Read>(ulongTable.inArray1Ptr); + var vul2 = Unsafe.Read>(ulongTable.inArray2Ptr); + var vul3 = Avx2.Add(vul1, vul2); + Unsafe.Write(ulongTable.outArrayPtr, vul3); + + var vs1 = Unsafe.Read>(shortTable.inArray1Ptr); + var vs2 = Unsafe.Read>(shortTable.inArray2Ptr); + var vs3 = Avx2.Add(vs1, vs2); + Unsafe.Write(shortTable.outArrayPtr, vs3); + + var vus1 = Unsafe.Read>(ushortTable.inArray1Ptr); + var vus2 = Unsafe.Read>(ushortTable.inArray2Ptr); + var vus3 = Avx2.Add(vus1, vus2); + Unsafe.Write(ushortTable.outArrayPtr, vus3); + + var vsb1 = Unsafe.Read>(sbyteTable.inArray1Ptr); + var vsb2 = Unsafe.Read>(sbyteTable.inArray2Ptr); + var vsb3 = Avx2.Add(vsb1, vsb2); + Unsafe.Write(sbyteTable.outArrayPtr, vsb3); + + var vb1 = Unsafe.Read>(byteTable.inArray1Ptr); + var vb2 = Unsafe.Read>(byteTable.inArray2Ptr); + var vb3 = Avx2.Add(vb1, vb2); + Unsafe.Write(byteTable.outArrayPtr, vb3); + + if (!intTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on int:"); + foreach (var item in intTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!longTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on long:"); + foreach (var item in longTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!uintTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on uint:"); + foreach (var item in uintTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!ulongTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on ulong:"); + foreach (var item in ulongTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!shortTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on short:"); + foreach (var item in shortTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!ushortTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on ushort:"); + foreach (var item in ushortTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on sbyte:"); + foreach (var item in sbyteTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!byteTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("AVX2 Add failed on byte:"); + foreach (var item in byteTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + } + + } + + return testResult; + } + + public unsafe struct TestTable : IDisposable where T : struct + { + public T[] inArray1; + public T[] inArray2; + public T[] outArray; + + public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); + public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle1; + GCHandle inHandle2; + GCHandle outHandle; + public TestTable(T[] a, T[] b, T[] c) + { + this.inArray1 = a; + this.inArray2 = b; + this.outArray = c; + + inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); + inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + for (int i = 0; i < inArray1.Length; i++) + { + if (!check(inArray1[i], inArray2[i], outArray[i])) + { + return false; + } + } + return true; + } + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj new file mode 100644 index 0000000..376806f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj new file mode 100644 index 0000000..0b1b518 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + True + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt.cs similarity index 100% rename from tests/src/JIT/HardwareIntrinsics/X86/Lzcnt.cs rename to tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt.cs diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_r.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_r.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_r.csproj index cc76545..32579db 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_r.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_ro.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_ro.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_ro.csproj index 9bc71c3..3ad1b18 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_ro.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt.cs similarity index 100% rename from tests/src/JIT/HardwareIntrinsics/X86/Popcnt.cs rename to tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt.cs diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_r.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Popcnt_r.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_r.csproj index 2a0e814..a01109a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_r.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_ro.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Popcnt_ro.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_ro.csproj index 1a1414a..193c2ac 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_ro.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs new file mode 100644 index 0000000..490bb2a --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add.cs @@ -0,0 +1,94 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; +using System.Runtime.Intrinsics; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static unsafe int Main(string[] args) + { + int testResult = Pass; + + if (Sse.IsSupported) + { + using (TestTable floatTable = new TestTable(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) + { + + var vf1 = Unsafe.Read>(floatTable.inArray1Ptr); + var vf2 = Unsafe.Read>(floatTable.inArray2Ptr); + var vf3 = Sse.Add(vf1, vf2); + Unsafe.Write(floatTable.outArrayPtr, vf3); + + if (!floatTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE Add failed on float:"); + foreach (var item in floatTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + } + } + + + return testResult; + } + + public unsafe struct TestTable : IDisposable where T : struct + { + public T[] inArray1; + public T[] inArray2; + public T[] outArray; + + public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); + public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle1; + GCHandle inHandle2; + GCHandle outHandle; + public TestTable(T[] a, T[] b, T[] c) + { + this.inArray1 = a; + this.inArray2 = b; + this.outArray = c; + + inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); + inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + for (int i = 0; i < inArray1.Length; i++) + { + if (!check(inArray1[i], inArray2[i], outArray[i])) + { + return false; + } + } + return true; + } + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj new file mode 100644 index 0000000..376806f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj new file mode 100644 index 0000000..0b1b518 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + True + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs new file mode 100644 index 0000000..7c25578 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add.cs @@ -0,0 +1,229 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; +using System.Runtime.Intrinsics; + +namespace IntelHardwareIntrinsicTest +{ + class Program + { + const int Pass = 100; + const int Fail = 0; + + static unsafe int Main(string[] args) + { + int testResult = Pass; + + if (Sse2.IsSupported) + { + using (TestTable doubleTable = new TestTable(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) + using (TestTable intTable = new TestTable(new int[4] { 1, -5, 100, 0 }, new int[4] { 22, -1, -50, 0 }, new int[4])) + using (TestTable longTable = new TestTable(new long[2] { 1, -5 }, new long[2] { 22, -1 }, new long[2])) + using (TestTable uintTable = new TestTable(new uint[4] { 1, 5, 100, 0 }, new uint[4] { 22, 1, 50, 0 }, new uint[4])) + using (TestTable ulongTable = new TestTable(new ulong[2] { 1, 5 }, new ulong[2] { 22, 1 }, new ulong[2])) + using (TestTable shortTable = new TestTable(new short[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new short[8] { 22, -1, -50, 0, 22, -1, -50, 0 }, new short[8])) + using (TestTable ushortTable = new TestTable(new ushort[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[8] { 22, 1, 50, 0, 22, 1, 50, 0 }, new ushort[8])) + using (TestTable sbyteTable = new TestTable(new sbyte[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[16] { 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0, 22, -1, -50, 0 }, new sbyte[16])) + using (TestTable byteTable = new TestTable(new byte[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[16] { 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0, 22, 1, 50, 0 }, new byte[16])) + { + var vd1 = Unsafe.Read>(doubleTable.inArray1Ptr); + var vd2 = Unsafe.Read>(doubleTable.inArray2Ptr); + var vd3 = Sse2.Add(vd1, vd2); + Unsafe.Write(doubleTable.outArrayPtr, vd3); + + var vi1 = Unsafe.Read>(intTable.inArray1Ptr); + var vi2 = Unsafe.Read>(intTable.inArray2Ptr); + var vi3 = Sse2.Add(vi1, vi2); + Unsafe.Write(intTable.outArrayPtr, vi3); + + var vl1 = Unsafe.Read>(longTable.inArray1Ptr); + var vl2 = Unsafe.Read>(longTable.inArray2Ptr); + var vl3 = Sse2.Add(vl1, vl2); + Unsafe.Write(longTable.outArrayPtr, vl3); + + var vui1 = Unsafe.Read>(uintTable.inArray1Ptr); + var vui2 = Unsafe.Read>(uintTable.inArray2Ptr); + var vui3 = Sse2.Add(vui1, vui2); + Unsafe.Write(uintTable.outArrayPtr, vui3); + + var vul1 = Unsafe.Read>(ulongTable.inArray1Ptr); + var vul2 = Unsafe.Read>(ulongTable.inArray2Ptr); + var vul3 = Sse2.Add(vul1, vul2); + Unsafe.Write(ulongTable.outArrayPtr, vul3); + + var vs1 = Unsafe.Read>(shortTable.inArray1Ptr); + var vs2 = Unsafe.Read>(shortTable.inArray2Ptr); + var vs3 = Sse2.Add(vs1, vs2); + Unsafe.Write(shortTable.outArrayPtr, vs3); + + var vus1 = Unsafe.Read>(ushortTable.inArray1Ptr); + var vus2 = Unsafe.Read>(ushortTable.inArray2Ptr); + var vus3 = Sse2.Add(vus1, vus2); + Unsafe.Write(ushortTable.outArrayPtr, vus3); + + var vsb1 = Unsafe.Read>(sbyteTable.inArray1Ptr); + var vsb2 = Unsafe.Read>(sbyteTable.inArray2Ptr); + var vsb3 = Sse2.Add(vsb1, vsb2); + Unsafe.Write(sbyteTable.outArrayPtr, vsb3); + + var vb1 = Unsafe.Read>(byteTable.inArray1Ptr); + var vb2 = Unsafe.Read>(byteTable.inArray2Ptr); + var vb3 = Sse2.Add(vb1, vb2); + Unsafe.Write(byteTable.outArrayPtr, vb3); + + if (!intTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on int:"); + foreach (var item in intTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!longTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on long:"); + foreach (var item in longTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!uintTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on uint:"); + foreach (var item in uintTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!ulongTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on ulong:"); + foreach (var item in ulongTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!shortTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on short:"); + foreach (var item in shortTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!ushortTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on ushort:"); + foreach (var item in ushortTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!doubleTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on double:"); + foreach (var item in doubleTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!sbyteTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on sbyte:"); + foreach (var item in sbyteTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + + if (!byteTable.CheckResult((x, y, z) => x + y == z)) + { + Console.WriteLine("SSE2 Add failed on byte:"); + foreach (var item in byteTable.outArray) + { + Console.Write(item + ", "); + } + Console.WriteLine(); + testResult = Fail; + } + } + } + + + return testResult; + } + + public unsafe struct TestTable : IDisposable where T : struct + { + public T[] inArray1; + public T[] inArray2; + public T[] outArray; + + public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); + public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle1; + GCHandle inHandle2; + GCHandle outHandle; + public TestTable(T[] a, T[] b, T[] c) + { + this.inArray1 = a; + this.inArray2 = b; + this.outArray = c; + + inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); + inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + for (int i = 0; i < inArray1.Length; i++) + { + if (!check(inArray1[i], inArray2[i], outArray[i])) + { + return false; + } + } + return true; + } + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj new file mode 100644 index 0000000..376806f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj new file mode 100644 index 0000000..0b1b518 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + False + + + + None + True + + + + + + + + + + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Crc32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32.cs similarity index 100% rename from tests/src/JIT/HardwareIntrinsics/X86/Crc32.cs rename to tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32.cs diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_r.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Crc32_r.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_r.csproj index e42eeb4..a8e8a0a 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_r.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_ro.csproj similarity index 99% rename from tests/src/JIT/HardwareIntrinsics/X86/Crc32_ro.csproj rename to tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_ro.csproj index 0dfe5e0..0f78f5c 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_ro.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + -- 2.7.4