This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Converting more of the x86 HWIntrinsic tests to be generated from a template #16115
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
038a7d6
Moving the Sse comparison tests to use the template.
tannergooding a7c8d03
Moving the Sse max/min tests to use the template.
tannergooding bf0b2c3
Moving the Sse Compare*OrderedScalar and Compare*UnorderedScalar test…
tannergooding 5dd26eb
Fixing some of the x86 HWIntrinsics to only use byteable registers, w…
tannergooding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
// 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. | ||
|
||
/****************************************************************************** | ||
* 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 System.Runtime.Intrinsics.X86; | ||
|
||
namespace JIT.HardwareIntrinsics.X86 | ||
{{ | ||
public static partial class Program | ||
{{ | ||
private static void {1}{2}() | ||
{{ | ||
var test = new BooleanComparisonOpTest__{1}{2}(); | ||
|
||
if (test.IsSupported) | ||
{{ | ||
// Validates basic functionality works | ||
test.RunBasicScenario(); | ||
|
||
// Validates calling via reflection works | ||
test.RunReflectionScenario(); | ||
|
||
// Validates passing a static member works | ||
test.RunClsVarScenario(); | ||
|
||
// Validates passing a local works | ||
test.RunLclVarScenario(); | ||
|
||
// Validates passing the field of a local works | ||
test.RunLclFldScenario(); | ||
|
||
// Validates passing an instance member works | ||
test.RunFldScenario(); | ||
}} | ||
else | ||
{{ | ||
// Validates we throw on unsupported hardware | ||
test.RunUnsupportedScenario(); | ||
}} | ||
|
||
if (!test.Succeeded) | ||
{{ | ||
throw new Exception("One or more scenarios did not complete as expected."); | ||
}} | ||
}} | ||
}} | ||
|
||
public sealed unsafe class BooleanComparisonOpTest__{1}{2} | ||
{{ | ||
private const int VectorSize = {4}; | ||
private const int ElementCount = VectorSize / sizeof({2}); | ||
|
||
private static {2}[] _data1 = new {2}[ElementCount]; | ||
private static {2}[] _data2 = new {2}[ElementCount]; | ||
|
||
private static {3}<{2}> _clsVar1; | ||
private static {3}<{2}> _clsVar2; | ||
|
||
private {3}<{2}> _fld1; | ||
private {3}<{2}> _fld2; | ||
|
||
private BooleanComparisonOpTest__DataTable<{2}> _dataTable; | ||
|
||
static BooleanComparisonOpTest__{1}{2}() | ||
{{ | ||
var random = new Random(); | ||
|
||
for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar1), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _clsVar2), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); | ||
}} | ||
|
||
public BooleanComparisonOpTest__{1}{2}() | ||
{{ | ||
Succeeded = true; | ||
|
||
var random = new Random(); | ||
|
||
for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld1), ref Unsafe.As<{2}, byte>(ref _data1[0]), VectorSize); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{3}<{2}>, byte>(ref _fld2), ref Unsafe.As<{2}, byte>(ref _data2[0]), VectorSize); | ||
|
||
for (var i = 0; i < ElementCount; i++) {{ _data1[i] = {5}; _data2[i] = {5}; }} | ||
_dataTable = new BooleanComparisonOpTest__DataTable<{2}>(_data1, _data2); | ||
}} | ||
|
||
public bool IsSupported => {0}.IsSupported; | ||
|
||
public bool Succeeded {{ get; set; }} | ||
|
||
public void RunBasicScenario() | ||
{{ | ||
var result = {0}.{1}( | ||
Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), | ||
Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) | ||
); | ||
|
||
ValidateResult(_dataTable.inArray1, _dataTable.inArray2, result); | ||
}} | ||
|
||
public void RunReflectionScenario() | ||
{{ | ||
var result = typeof({0}).GetMethod(nameof({0}.{1}), new Type[] {{ typeof({3}<{2}>), typeof({3}<{2}>) }}) | ||
.Invoke(null, new object[] {{ | ||
Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr), | ||
Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr) | ||
}}); | ||
|
||
ValidateResult(_dataTable.inArray1, _dataTable.inArray2, (bool)(result)); | ||
}} | ||
|
||
public void RunClsVarScenario() | ||
{{ | ||
var result = {0}.{1}( | ||
_clsVar1, | ||
_clsVar2 | ||
); | ||
|
||
ValidateResult(_clsVar1, _clsVar2, result); | ||
}} | ||
|
||
public void RunLclVarScenario() | ||
{{ | ||
var left = Unsafe.Read<{3}<{2}>>(_dataTable.inArray1Ptr); | ||
var right = Unsafe.Read<{3}<{2}>>(_dataTable.inArray2Ptr); | ||
var result = {0}.{1}(left, right); | ||
|
||
ValidateResult(left, right, result); | ||
}} | ||
|
||
public void RunLclFldScenario() | ||
{{ | ||
var test = new BooleanComparisonOpTest__{1}{2}(); | ||
var result = {0}.{1}(test._fld1, test._fld2); | ||
|
||
ValidateResult(test._fld1, test._fld2, result); | ||
}} | ||
|
||
public void RunFldScenario() | ||
{{ | ||
var result = {0}.{1}(_fld1, _fld2); | ||
|
||
ValidateResult(_fld1, _fld2, result); | ||
}} | ||
|
||
public void RunUnsupportedScenario() | ||
{{ | ||
Succeeded = false; | ||
|
||
try | ||
{{ | ||
RunBasicScenario(); | ||
}} | ||
catch (PlatformNotSupportedException) | ||
{{ | ||
Succeeded = true; | ||
}} | ||
}} | ||
|
||
private void ValidateResult({3}<{2}> left, {3}<{2}> right, bool result, [CallerMemberName] string method = "") | ||
{{ | ||
{2}[] inArray1 = new {2}[ElementCount]; | ||
{2}[] inArray2 = new {2}[ElementCount]; | ||
|
||
Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left); | ||
Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right); | ||
|
||
ValidateResult(inArray1, inArray2, result, method); | ||
}} | ||
|
||
private void ValidateResult({2}[] left, {2}[] right, bool result, [CallerMemberName] string method = "") | ||
{{ | ||
if ({6}) | ||
{{ | ||
Succeeded = false; | ||
|
||
Console.WriteLine($"{{nameof({0})}}.{{nameof({0}.{1})}}<{2}>: {{method}} failed:"); | ||
Console.WriteLine($" left: ({{string.Join(", ", left)}})"); | ||
Console.WriteLine($" right: ({{string.Join(", ", right)}})"); | ||
Console.WriteLine($" result: ({{string.Join(", ", result)}})"); | ||
Console.WriteLine(); | ||
}} | ||
}} | ||
}} | ||
}} |
39 changes: 39 additions & 0 deletions
39
tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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; | ||
using System.Runtime.Intrinsics.X86; | ||
|
||
namespace JIT.HardwareIntrinsics.X86 | ||
{ | ||
public unsafe struct BooleanComparisonOpTest__DataTable<T> : IDisposable where T : struct | ||
{ | ||
private GCHandle inHandle1; | ||
private GCHandle inHandle2; | ||
|
||
public T[] inArray1; | ||
public T[] inArray2; | ||
|
||
public BooleanComparisonOpTest__DataTable(T[] inArray1, T[] inArray2) | ||
{ | ||
this.inArray1 = inArray1; | ||
this.inArray2 = inArray2; | ||
|
||
this.inHandle1 = GCHandle.Alloc(inArray1, GCHandleType.Pinned); | ||
this.inHandle2 = GCHandle.Alloc(inArray2, GCHandleType.Pinned); | ||
} | ||
|
||
public void* inArray1Ptr => inHandle1.AddrOfPinnedObject().ToPointer(); | ||
public void* inArray2Ptr => inHandle2.AddrOfPinnedObject().ToPointer(); | ||
|
||
public void Dispose() | ||
{ | ||
inHandle1.Free(); | ||
inHandle2.Free(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. Looks like we need another template for Avx comparisons that take two vectors and an imm value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we will end up having at least 5-10 templates to support all tests, but this is much more manageable than 500-1000 individual tests that need handling 😉
I think it is even fine if the templates are "nearly" identical in some cases, as they are still few in number and it makes the overall logic to maintain them simpler.