From: Tanner Gooding Date: Sun, 28 Jan 2018 19:37:31 +0000 (-0800) Subject: Adding tests for the SSE Store, StoreAligned, StoreAlignedNonTemporal, StoreHigh... X-Git-Tag: accepted/tizen/unified/20190422.045933~3168^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82b57bf4ed1db41bbb7628a1b5280acc641f9903;p=platform%2Fupstream%2Fcoreclr.git Adding tests for the SSE Store, StoreAligned, StoreAlignedNonTemporal, StoreHigh, StoreLow, and StoreScalar intrinsics --- diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store.cs new file mode 100644 index 0000000..4fd4007 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store.cs @@ -0,0 +1,84 @@ +// 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])) + { + var vf = Unsafe.Read>(floatTable.inArrayPtr); + Sse.Store((float*)(floatTable.outArrayPtr), vf); + + if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y))) + { + Console.WriteLine("SSE Store 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[] inArray; + public T[] outArray; + + public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle; + GCHandle outHandle; + public TestTable(T[] a, T[] b) + { + this.inArray = a; + this.outArray = b; + + inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + for (int i = 0; i < inArray.Length; i++) + { + if (!check(inArray[i], outArray[i])) + { + return false; + } + } + return true; + } + + public void Dispose() + { + inHandle.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned.cs new file mode 100644 index 0000000..85a698b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned.cs @@ -0,0 +1,62 @@ +// 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) + { + float* inArray = stackalloc float[4]; + byte* outBuffer = stackalloc byte[32]; + float* outArray = Align(outBuffer, 16); + + var vf = Unsafe.Read>(inArray); + Sse.StoreAligned(outArray, vf); + + for (var i = 0; i < 4; i++) + { + if (BitConverter.SingleToInt32Bits(inArray[i]) != BitConverter.SingleToInt32Bits(outArray[i])) + { + Console.WriteLine("SSE StoreAligned failed on float:"); + for (var n = 0; n < 4; n++) + { + Console.Write(outArray[n] + ", "); + } + Console.WriteLine(); + + testResult = Fail; + break; + } + } + } + + return testResult; + } + + static unsafe float* Align(byte* buffer, byte expectedAlignment) + { + // Compute how bad the misalignment is, which is at most (expectedAlignment - 1). + // Then subtract that from the expectedAlignment and add it to the original address + // to compute the aligned address. + + var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment); + return (float*)(buffer + misalignment); + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal.cs new file mode 100644 index 0000000..4c4cd52 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal.cs @@ -0,0 +1,62 @@ +// 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) + { + float* inArray = stackalloc float[4]; + byte* outBuffer = stackalloc byte[32]; + float* outArray = Align(outBuffer, 16); + + var vf = Unsafe.Read>(inArray); + Sse.StoreAlignedNonTemporal(outArray, vf); + + for (var i = 0; i < 4; i++) + { + if (BitConverter.SingleToInt32Bits(inArray[i]) != BitConverter.SingleToInt32Bits(outArray[i])) + { + Console.WriteLine("SSE StoreAlignedNonTemporal failed on float:"); + for (var n = 0; n < 4; n++) + { + Console.Write(outArray[n] + ", "); + } + Console.WriteLine(); + + testResult = Fail; + break; + } + } + } + + return testResult; + } + + static unsafe float* Align(byte* buffer, byte expectedAlignment) + { + // Compute how bad the misalignment is, which is at most (expectedAlignment - 1). + // Then subtract that from the expectedAlignment and add it to the original address + // to compute the aligned address. + + var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment); + return (float*)(buffer + misalignment); + } + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal_r.csproj new file mode 100644 index 0000000..81ca111 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal_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/StoreAlignedNonTemporal_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal_ro.csproj new file mode 100644 index 0000000..1170f4b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAlignedNonTemporal_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/Sse/StoreAligned_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned_r.csproj new file mode 100644 index 0000000..41a34bb --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned_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/StoreAligned_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned_ro.csproj new file mode 100644 index 0000000..eaa180f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreAligned_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/Sse/StoreHigh.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh.cs new file mode 100644 index 0000000..d19755b --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh.cs @@ -0,0 +1,78 @@ +// 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])) + { + var vf = Unsafe.Read>(floatTable.inArrayPtr); + Sse.StoreHigh((float*)(floatTable.outArrayPtr), vf); + + if (!floatTable.CheckResult((x, y) => y[0] == x[2] && y[1] == x[3] && + y[2] == 0 && y[3] == 0)) + { + Console.WriteLine("SSE StoreHigh 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[] inArray; + public T[] outArray; + + public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle; + GCHandle outHandle; + public TestTable(T[] a, T[] b) + { + this.inArray = a; + this.outArray = b; + + inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + return check(inArray, outArray); + } + + public void Dispose() + { + inHandle.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh_r.csproj new file mode 100644 index 0000000..ca533fe --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh_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/StoreHigh_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh_ro.csproj new file mode 100644 index 0000000..10acc69 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreHigh_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/Sse/StoreLow.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow.cs new file mode 100644 index 0000000..43007b5 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow.cs @@ -0,0 +1,78 @@ +// 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])) + { + var vf = Unsafe.Read>(floatTable.inArrayPtr); + Sse.StoreLow((float*)(floatTable.outArrayPtr), vf); + + if (!floatTable.CheckResult((x, y) => y[0] == x[0] && y[1] == x[1] && + y[2] == 0 && y[3] == 0)) + { + Console.WriteLine("SSE StoreLow 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[] inArray; + public T[] outArray; + + public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle; + GCHandle outHandle; + public TestTable(T[] a, T[] b) + { + this.inArray = a; + this.outArray = b; + + inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + return check(inArray, outArray); + } + + public void Dispose() + { + inHandle.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow_r.csproj new file mode 100644 index 0000000..6a53cfe --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow_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/StoreLow_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow_ro.csproj new file mode 100644 index 0000000..5c7de6d --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreLow_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/Sse/StoreScalar.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar.cs new file mode 100644 index 0000000..7721c09 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar.cs @@ -0,0 +1,80 @@ +// 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, 3 }, new float[4])) + { + var vf = Unsafe.Read>(floatTable.inArrayPtr); + Sse.StoreScalar((float*)(floatTable.outArrayPtr), vf); + + if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x[0]) == BitConverter.SingleToInt32Bits(y[0]) + && BitConverter.SingleToInt32Bits(y[1]) == 0 + && BitConverter.SingleToInt32Bits(y[2]) == 0 + && BitConverter.SingleToInt32Bits(y[3]) == 0)) + { + Console.WriteLine("SSE StoreScalar 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[] inArray; + public T[] outArray; + + public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer(); + public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer(); + + GCHandle inHandle; + GCHandle outHandle; + public TestTable(T[] a, T[] b) + { + this.inArray = a; + this.outArray = b; + + inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned); + outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned); + } + public bool CheckResult(Func check) + { + return check(inArray, outArray); + } + + public void Dispose() + { + inHandle.Free(); + outHandle.Free(); + } + } + + } +} diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar_r.csproj new file mode 100644 index 0000000..977ef94 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar_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/StoreScalar_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar_ro.csproj new file mode 100644 index 0000000..2e6f570 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/StoreScalar_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/Sse/Store_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store_r.csproj new file mode 100644 index 0000000..a803854 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store_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/Store_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store_ro.csproj new file mode 100644 index 0000000..f0e1409 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Store_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 + + + + + + + + + +