diff options
author | Tanner Gooding <tagoo@outlook.com> | 2017-12-22 11:11:08 -0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-12-22 11:11:08 -0800 |
commit | c127fa74fde9143e39d1cdf979aee21f31d3d31d (patch) | |
tree | d1cd1f7430ba48d2f1965a65c74c3f9780df5084 | |
parent | 8f9d5e02337fc3b0c72508c6aefc48a3d483adbf (diff) | |
download | coreclr-c127fa74fde9143e39d1cdf979aee21f31d3d31d.tar.gz coreclr-c127fa74fde9143e39d1cdf979aee21f31d3d31d.tar.bz2 coreclr-c127fa74fde9143e39d1cdf979aee21f31d3d31d.zip |
Organizing the tests/src/JIT/HardwareIntrinsics/X86 folder by ISA to make it more manageable. (#15617)
22 files changed, 857 insertions, 436 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Add.cs b/tests/src/JIT/HardwareIntrinsics/X86/Add.cs deleted file mode 100644 index cf39254c74..0000000000 --- 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<float> floatTable = new TestTable<float>(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<double> doubleTable = new TestTable<double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) - { - var vf1 = Unsafe.Read<Vector256<float>>(floatTable.inArray1Ptr); - var vf2 = Unsafe.Read<Vector256<float>>(floatTable.inArray2Ptr); - var vf3 = Avx.Add(vf1, vf2); - Unsafe.Write(floatTable.outArrayPtr, vf3); - - 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)) - { - 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<int> intTable = new TestTable<int>(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<long> longTable = new TestTable<long>(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) - using (TestTable<uint> uintTable = new TestTable<uint>(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<ulong> ulongTable = new TestTable<ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) - using (TestTable<short> shortTable = new TestTable<short>(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<ushort> ushortTable = new TestTable<ushort>(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<sbyte> sbyteTable = new TestTable<sbyte>(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<byte> byteTable = new TestTable<byte>(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<Vector256<int>>(intTable.inArray1Ptr); - var vi2 = Unsafe.Read<Vector256<int>>(intTable.inArray2Ptr); - 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); - - 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 (!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<float> floatTable = new TestTable<float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) - using (TestTable<double> doubleTable = new TestTable<double>(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) - using (TestTable<int> intTable = new TestTable<int>(new int[4] { 1, -5, 100, 0 }, new int[4] { 22, -1, -50, 0 }, new int[4])) - using (TestTable<long> longTable = new TestTable<long>(new long[2] { 1, -5 }, new long[2] { 22, -1 }, new long[2])) - using (TestTable<uint> uintTable = new TestTable<uint>(new uint[4] { 1, 5, 100, 0 }, new uint[4] { 22, 1, 50, 0 }, new uint[4])) - using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[2] { 1, 5 }, new ulong[2] { 22, 1 }, new ulong[2])) - using (TestTable<short> shortTable = new TestTable<short>(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<ushort> ushortTable = new TestTable<ushort>(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<sbyte> sbyteTable = new TestTable<sbyte>(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<byte> byteTable = new TestTable<byte>(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<Vector128<float>>(floatTable.inArray1Ptr); - var vf2 = Unsafe.Read<Vector128<float>>(floatTable.inArray2Ptr); - var vf3 = Sse.Add(vf1, vf2); - Unsafe.Write(floatTable.outArrayPtr, vf3); - - var vd1 = Unsafe.Read<Vector128<double>>(doubleTable.inArray1Ptr); - var vd2 = Unsafe.Read<Vector128<double>>(doubleTable.inArray2Ptr); - var vd3 = Sse2.Add(vd1, vd2); - Unsafe.Write(doubleTable.outArrayPtr, vd3); - 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); - - 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 (!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<T> : 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<T, T, T, bool> 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 0000000000..d67adedd96 --- /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<float> floatTable = new TestTable<float>(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<double> doubleTable = new TestTable<double>(new double[4] { 1, -5, 100, 0 }, new double[4] { 22, -1, -50, 0 }, new double[4])) + { + var vf1 = Unsafe.Read<Vector256<float>>(floatTable.inArray1Ptr); + var vf2 = Unsafe.Read<Vector256<float>>(floatTable.inArray2Ptr); + var vf3 = Avx.Add(vf1, vf2); + Unsafe.Write(floatTable.outArrayPtr, vf3); + + 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)) + { + 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<T> : 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<T, T, T, bool> 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 index 6179540b29..376806fd2b 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Add_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_r.csproj @@ -31,4 +31,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj index 7c5ee7ce34..0b1b518216 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Add_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx/Add_ro.csproj @@ -31,4 +31,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> 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 0000000000..6ab142f73d --- /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<int> intTable = new TestTable<int>(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<long> longTable = new TestTable<long>(new long[4] { 1, -5, 100, 0 }, new long[4] { 22, -1, -50, 0 }, new long[4])) + using (TestTable<uint> uintTable = new TestTable<uint>(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<ulong> ulongTable = new TestTable<ulong>(new ulong[4] { 1, 5, 100, 0 }, new ulong[4] { 22, 1, 50, 0 }, new ulong[4])) + using (TestTable<short> shortTable = new TestTable<short>(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<ushort> ushortTable = new TestTable<ushort>(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<sbyte> sbyteTable = new TestTable<sbyte>(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<byte> byteTable = new TestTable<byte>(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<Vector256<int>>(intTable.inArray1Ptr); + var vi2 = Unsafe.Read<Vector256<int>>(intTable.inArray2Ptr); + 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); + + 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 (!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<T> : 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<T, T, T, bool> 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 0000000000..376806fd2b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_r.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> 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 0000000000..0b1b518216 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Avx2/Add_ro.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt.cs index 9d40c08c54..9d40c08c54 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt.cs +++ b/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 index cc76545fcc..32579db6f6 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_r.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_ro.csproj index 9bc71c3767..3ad1b1855d 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Lzcnt/Lzcnt_ro.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt.cs index 20c443ba53..20c443ba53 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt.cs +++ b/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 index 2a0e814c3e..a01109a534 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_r.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_ro.csproj index 1a1414aecf..193c2ace98 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Popcnt_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Popcnt/Popcnt_ro.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> 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 0000000000..490bb2a9e6 --- /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<float> floatTable = new TestTable<float>(new float[4] { 1, -5, 100, 0 }, new float[4] { 22, -1, -50, 0 }, new float[4])) + { + + var vf1 = Unsafe.Read<Vector128<float>>(floatTable.inArray1Ptr); + var vf2 = Unsafe.Read<Vector128<float>>(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<T> : 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<T, T, T, bool> 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 0000000000..376806fd2b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_r.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> 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 0000000000..0b1b518216 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Add_ro.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> 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 0000000000..7c25578fb4 --- /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<double> doubleTable = new TestTable<double>(new double[2] { 1, -5 }, new double[2] { 22, -1 }, new double[2])) + using (TestTable<int> intTable = new TestTable<int>(new int[4] { 1, -5, 100, 0 }, new int[4] { 22, -1, -50, 0 }, new int[4])) + using (TestTable<long> longTable = new TestTable<long>(new long[2] { 1, -5 }, new long[2] { 22, -1 }, new long[2])) + using (TestTable<uint> uintTable = new TestTable<uint>(new uint[4] { 1, 5, 100, 0 }, new uint[4] { 22, 1, 50, 0 }, new uint[4])) + using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[2] { 1, 5 }, new ulong[2] { 22, 1 }, new ulong[2])) + using (TestTable<short> shortTable = new TestTable<short>(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<ushort> ushortTable = new TestTable<ushort>(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<sbyte> sbyteTable = new TestTable<sbyte>(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<byte> byteTable = new TestTable<byte>(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<Vector128<double>>(doubleTable.inArray1Ptr); + var vd2 = Unsafe.Read<Vector128<double>>(doubleTable.inArray2Ptr); + var vd3 = Sse2.Add(vd1, vd2); + Unsafe.Write(doubleTable.outArrayPtr, vd3); + + 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); + + 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 (!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<T> : 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<T, T, T, bool> 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 0000000000..376806fd2b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_r.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize></Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> 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 0000000000..0b1b518216 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse2/Add_ro.csproj @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <PropertyGroup> + <DebugType>None</DebugType> + <Optimize>True</Optimize> + </PropertyGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Add.cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Crc32.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32.cs index 27ea5a9bbf..27ea5a9bbf 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Crc32.cs +++ b/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 index e42eeb4f93..a8e8a0a175 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_r.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_r.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_ro.csproj index 0dfe5e0930..0f78f5c35f 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Crc32_ro.csproj +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse42/Crc32_ro.csproj @@ -30,4 +30,4 @@ </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> -</Project>
\ No newline at end of file +</Project> |