From 0991c876cd5acf6fd79db7b08140f1d97f947586 Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 19 Sep 2023 17:11:49 -0700 Subject: [PATCH 1/6] Fixed incorrect reversed condition for GT --- src/coreclr/jit/gentree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 5a06113fa8d717..2720a1e2b18341 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -8635,7 +8635,7 @@ struct GenCondition NONE, NONE, SGE, SGT, SLT, SLE, NS, S, NE, EQ, UGE, UGT, ULT, ULE, NC, C, FNEU, FEQU, FGEU, FGTU, FLTU, FLEU, NO, O, - FNE, FEQ, FGE, FGT, FLT, FGT, NP, P + FNE, FEQ, FGE, FGT, FLT, FLE, NP, P }; // clang-format on From 17b5cecf552c8af25d4b1c3d4d3567361cb69320 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 20 Sep 2023 13:32:32 -0700 Subject: [PATCH 2/6] Added test case --- .../JitBlue/Runtime_92201/Runtime_92201.cs | 221 ++++++++++++++++++ .../Runtime_92201/Runtime_92201.csproj | 12 + 2 files changed, 233 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs new file mode 100644 index 00000000000000..4025110dd61a47 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs @@ -0,0 +1,221 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/****************************************************************************** + * This file is auto-generated from a template file by the GenerateTests.csx * + * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * + * changes, please update the corresponding template and run according to the * + * directions listed in the file. * + ******************************************************************************/ + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using Xunit; + +namespace JIT.HardwareIntrinsics.General._Vector128 +{ + public static partial class Program + { + [Fact] + public static void Test() + { + var test = new VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle(); + + // Validates basic functionality works, using Unsafe.Read + test.RunBasicScenario_UnsafeRead(); + + if (!test.Succeeded) + { + throw new Exception("One or more scenarios did not complete as expected."); + } + } + } + + public sealed unsafe class VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle + { + private struct DataTable + { + private byte[] inArray1; + private byte[] inArray2; + + private GCHandle inHandle1; + private GCHandle inHandle2; + + private ulong alignment; + + public DataTable(Single[] inArray1, Single[] inArray2, int alignment) + { + int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf(); + int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf(); + if (!int.IsPow2(alignment) || (alignment > 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2) + { + throw new ArgumentException("Invalid value of alignment"); + } + + this.inArray1 = new byte[alignment * 2]; + this.inArray2 = new byte[alignment * 2]; + + this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); + this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); + + this.alignment = (ulong)alignment; + + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray1Ptr), ref Unsafe.As(ref inArray1[0]), (uint)sizeOfinArray1); + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef(inArray2Ptr), ref Unsafe.As(ref inArray2[0]), (uint)sizeOfinArray2); + } + + public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); + public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + } + + private static unsafe void* Align(byte* buffer, ulong expectedAlignment) + { + return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); + } + } + + private struct TestStruct + { + public Vector128 _fld1; + public Vector128 _fld2; + + public static TestStruct Create() + { + var testStruct = new TestStruct(); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 123; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 123; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); + + return testStruct; + } + } + + private static readonly int LargestVectorSize = 16; + + private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Single); + private static readonly int Op2ElementCount = Unsafe.SizeOf>() / sizeof(Single); + + private static Single[] _data1 = new Single[Op1ElementCount]; + private static Single[] _data2 = new Single[Op2ElementCount]; + + private static Vector128 _clsVar1; + private static Vector128 _clsVar2; + + private Vector128 _fld1; + private Vector128 _fld2; + + private DataTable _dataTable; + + static VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle() + { + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = Single.MaxValue; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = Single.MaxValue; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); + } + + public VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle() + { + Succeeded = true; + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 0.168625f; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 0.5899811f; } + Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); + + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 0.8042229f; } + for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 0.8173325f; } + + _data1[0] = 0.168625f; + _data1[1] = 0.5899811f; + _data1[2] = 0.8042229f; + _data1[3] = 0.8173325f; + + _data2[0] = 0.059660614f; + _data2[1] = 0.13952714f; + _data2[2] = 0.23523656f; + _data2[3] = 0.48773053f; + + _dataTable = new DataTable(_data1, _data2, LargestVectorSize); + } + + public bool Succeeded { get; set; } + + [MethodImpl(MethodImplOptions.NoInlining)] + public bool LessThanOrEqualAnyProblem() + { + return Vector128.LessThanOrEqualAny( + Unsafe.Read>(_dataTable.inArray1Ptr), + Unsafe.Read>(_dataTable.inArray2Ptr) + ); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public void* GetPtr1() + { + return _dataTable.inArray1Ptr; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public void* GetPtr2() + { + return _dataTable.inArray2Ptr; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public void CheckResult(bool result) + { + ValidateResult(GetPtr1(), GetPtr2(), result); + } + + public void RunBasicScenario_UnsafeRead() + { + var result = Vector128.LessThanOrEqualAny( + Unsafe.Read>(GetPtr1()), + Unsafe.Read>(GetPtr2()) + ); + + CheckResult(result); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "") + { + Single[] inArray1 = new Single[Op1ElementCount]; + Single[] inArray2 = new Single[Op2ElementCount]; + + Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)Unsafe.SizeOf>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As(ref inArray2[0]), ref Unsafe.AsRef(op2), (uint)Unsafe.SizeOf>()); + + ValidateResult(inArray1, inArray2, result, method); + } + + private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "") + { + bool succeeded = true; + + var expectedResult = false; + + for (var i = 0; i < Op1ElementCount; i++) + { + expectedResult |= (left[i] <= right[i]); + } + + succeeded = (expectedResult == result); + + if (!succeeded) + { + Succeeded = false; + } + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj new file mode 100644 index 00000000000000..cd1399bb28aedf --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj @@ -0,0 +1,12 @@ + + + True + + + + + + + + + From 99fe5af3e8643f26cd0705d26a1c740c2feb4999 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 20 Sep 2023 13:33:23 -0700 Subject: [PATCH 3/6] Remove comment --- .../JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs index 4025110dd61a47..968a08f9a8c5d4 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs @@ -1,13 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -/****************************************************************************** - * This file is auto-generated from a template file by the GenerateTests.csx * - * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make * - * changes, please update the corresponding template and run according to the * - * directions listed in the file. * - ******************************************************************************/ - using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; From a95566c9823e2ecb3da9fe3bf3a378f5fdf74466 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 20 Sep 2023 14:25:08 -0700 Subject: [PATCH 4/6] Use JitStressModeNames --- .../JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj index cd1399bb28aedf..4f31948ff0913e 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj @@ -7,6 +7,6 @@ - + From 3b8c9a014e9e624d7329aef93e32a879fe9e1192 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 20 Sep 2023 14:33:34 -0700 Subject: [PATCH 5/6] Cleaned up test --- .../JitBlue/Runtime_92201/Runtime_92201.cs | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs index 968a08f9a8c5d4..445cc3f915ef80 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.cs @@ -74,24 +74,6 @@ public void Dispose() } } - private struct TestStruct - { - public Vector128 _fld1; - public Vector128 _fld2; - - public static TestStruct Create() - { - var testStruct = new TestStruct(); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 123; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 123; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref testStruct._fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - return testStruct; - } - } - private static readonly int LargestVectorSize = 16; private static readonly int Op1ElementCount = Unsafe.SizeOf>() / sizeof(Single); @@ -100,34 +82,12 @@ public static TestStruct Create() private static Single[] _data1 = new Single[Op1ElementCount]; private static Single[] _data2 = new Single[Op2ElementCount]; - private static Vector128 _clsVar1; - private static Vector128 _clsVar2; - - private Vector128 _fld1; - private Vector128 _fld2; - private DataTable _dataTable; - static VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle() - { - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = Single.MaxValue; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = Single.MaxValue; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _clsVar2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - } - public VectorBooleanBinaryOpTest__LessThanOrEqualAnySingle() { Succeeded = true; - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 0.168625f; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld1), ref Unsafe.As(ref _data1[0]), (uint)Unsafe.SizeOf>()); - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 0.5899811f; } - Unsafe.CopyBlockUnaligned(ref Unsafe.As, byte>(ref _fld2), ref Unsafe.As(ref _data2[0]), (uint)Unsafe.SizeOf>()); - - for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = 0.8042229f; } - for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = 0.8173325f; } - _data1[0] = 0.168625f; _data1[1] = 0.5899811f; _data1[2] = 0.8042229f; From 950b01a9a3b982cd6488349ef97cd2a90d12401b Mon Sep 17 00:00:00 2001 From: Will Smith Date: Wed, 20 Sep 2023 15:53:51 -0700 Subject: [PATCH 6/6] Update Runtime_92201.csproj --- .../JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj index 4f31948ff0913e..717798d9d4e2bd 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92201/Runtime_92201.csproj @@ -1,6 +1,7 @@ True + True