From c09ad386736bb4584df65be1e4b0b291d1a685aa Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Sat, 23 Dec 2017 20:45:49 -0800 Subject: Adding tests for the SSE Reciprocal, ReciprocalSqrt, and Sqrt intrinsics --- .../JIT/HardwareIntrinsics/X86/Sse/Reciprocal.cs | 93 ++++++++++++++++++++++ .../HardwareIntrinsics/X86/Sse/ReciprocalSqrt.cs | 93 ++++++++++++++++++++++ .../X86/Sse/ReciprocalSqrt_r.csproj | 34 ++++++++ .../X86/Sse/ReciprocalSqrt_ro.csproj | 34 ++++++++ .../HardwareIntrinsics/X86/Sse/Reciprocal_r.csproj | 34 ++++++++ .../X86/Sse/Reciprocal_ro.csproj | 34 ++++++++ tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt.cs | 91 +++++++++++++++++++++ .../JIT/HardwareIntrinsics/X86/Sse/Sqrt_r.csproj | 34 ++++++++ .../JIT/HardwareIntrinsics/X86/Sse/Sqrt_ro.csproj | 34 ++++++++ 9 files changed, 481 insertions(+) create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_ro.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_ro.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt.cs create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_r.csproj create mode 100644 tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_ro.csproj (limited to 'tests') diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal.cs new file mode 100644 index 0000000000..88123215d1 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal.cs @@ -0,0 +1,93 @@ +// 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 vf1 = Unsafe.Read>(floatTable.inArrayPtr); + var vf2 = Sse.Reciprocal(vf1); + Unsafe.Write(floatTable.outArrayPtr, vf2); + + if (!floatTable.CheckResult((x, y) => { + var expected = 1 / x; + return (Math.Abs((1 / x) - y) <= 0.0003662109375f) // |Relative Error| <= 1.5 * 2^-12 + || (float.IsNaN(expected) && float.IsNaN(y)) + || (float.IsNegativeInfinity(expected) && float.IsNegativeInfinity(y)) + || (float.IsPositiveInfinity(expected) && float.IsPositiveInfinity(y)); + })) + { + Console.WriteLine("SSE Reciprocal 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/ReciprocalSqrt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt.cs new file mode 100644 index 0000000000..70abaf80ae --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt.cs @@ -0,0 +1,93 @@ +// 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 vf1 = Unsafe.Read>(floatTable.inArrayPtr); + var vf2 = Sse.ReciprocalSqrt(vf1); + Unsafe.Write(floatTable.outArrayPtr, vf2); + + if (!floatTable.CheckResult((x, y) => { + var expected = 1 / MathF.Sqrt(x); + return (Math.Abs(expected - y) <= 0.0003662109375f) // |Relative Error| <= 1.5 * 2^-12 + || (float.IsNaN(expected) && float.IsNaN(y)) + || (float.IsNegativeInfinity(expected) && float.IsNegativeInfinity(y)) + || (float.IsPositiveInfinity(expected) && float.IsPositiveInfinity(y)); + })) + { + Console.WriteLine("SSE ReciprocalSqrt 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/ReciprocalSqrt_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_r.csproj new file mode 100644 index 0000000000..35384bbb08 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_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/ReciprocalSqrt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_ro.csproj new file mode 100644 index 0000000000..b4224f80a4 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/ReciprocalSqrt_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/Reciprocal_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_r.csproj new file mode 100644 index 0000000000..cec442f086 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_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/Reciprocal_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_ro.csproj new file mode 100644 index 0000000000..f18ac097d0 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Reciprocal_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/Sqrt.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt.cs new file mode 100644 index 0000000000..07300f8509 --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt.cs @@ -0,0 +1,91 @@ +// 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 vf1 = Unsafe.Read>(floatTable.inArrayPtr); + var vf2 = Sse.Sqrt(vf1); + Unsafe.Write(floatTable.outArrayPtr, vf2); + + if (!floatTable.CheckResult((x, y) => { + var expected = MathF.Sqrt(x); + return (expected == y) + || (float.IsNaN(expected) && float.IsNaN(y)); + })) + { + Console.WriteLine("SSE Sqrt 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/Sqrt_r.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_r.csproj new file mode 100644 index 0000000000..453d09dd2d --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_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/Sqrt_ro.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_ro.csproj new file mode 100644 index 0000000000..012829729f --- /dev/null +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/Sqrt_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 + + + + + + + + + + -- cgit v1.2.3