-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Sve.UnzipEven/Odd & Sve.ZipHighLow #101294
Merged
+996
−34
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c5a3dc6
Add support for Sve.UnzipEven/Odd & Sve.ZipHighLow
SwapnilGaikwad cb9566b
Rename the test template
SwapnilGaikwad d0fd883
Merge main
SwapnilGaikwad 5c2d4ef
Merge main
SwapnilGaikwad 88acf3c
Merge remote-tracking branch 'origin/main' into github-sve-zip
kunalspathak 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
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
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
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
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
109 changes: 75 additions & 34 deletions
109
src/tests/Common/GenerateHWIntrinsicTests/GenerateHWIntrinsicTests_Arm.cs
Large diffs are not rendered by default.
Oops, something went wrong.
327 changes: 327 additions & 0 deletions
327
src/tests/JIT/HardwareIntrinsics/Arm/Shared/_BinaryOp_SveTestTemplate.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,327 @@ | ||
// 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.Arm\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.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Intrinsics; | ||
using System.Runtime.Intrinsics.Arm; | ||
using Xunit; | ||
|
||
namespace JIT.HardwareIntrinsics.Arm | ||
{ | ||
public static partial class Program | ||
{ | ||
[Fact] | ||
public static void {TestName}() | ||
{ | ||
var test = new {TemplateName}BinaryOpTest__{TestName}(); | ||
|
||
if (test.IsSupported) | ||
{ | ||
// Validates basic functionality works, using Unsafe.Read | ||
test.RunBasicScenario_UnsafeRead(); | ||
|
||
if ({LoadIsa}.IsSupported) | ||
{ | ||
// Validates basic functionality works, using Load | ||
test.RunBasicScenario_Load(); | ||
} | ||
|
||
// Validates calling via reflection works, using Unsafe.Read | ||
test.RunReflectionScenario_UnsafeRead(); | ||
|
||
// Validates passing a local works, using Unsafe.Read | ||
test.RunLclVarScenario_UnsafeRead(); | ||
|
||
// Validates passing an instance member of a class works | ||
test.RunClassFldScenario(); | ||
|
||
// Validates passing the field of a local struct works | ||
test.RunStructLclFldScenario(); | ||
|
||
// Validates passing an instance member of a struct works | ||
test.RunStructFldScenario(); | ||
} | ||
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 {TemplateName}BinaryOpTest__{TestName} | ||
{ | ||
private struct DataTable | ||
{ | ||
private byte[] inArray1; | ||
private byte[] inArray2; | ||
private byte[] outArray; | ||
|
||
private GCHandle inHandle1; | ||
private GCHandle inHandle2; | ||
private GCHandle outHandle; | ||
|
||
private ulong alignment; | ||
|
||
public DataTable({Op1BaseType}[] inArray1, {Op2BaseType}[] inArray2, {RetBaseType}[] outArray, int alignment) | ||
{ | ||
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<{Op1BaseType}>(); | ||
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<{Op2BaseType}>(); | ||
int sizeOfoutArray = outArray.Length * Unsafe.SizeOf<{RetBaseType}>(); | ||
if ((alignment != 16 && alignment != 8) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2 || (alignment * 2) < sizeOfoutArray) | ||
{ | ||
throw new ArgumentException("Invalid value of alignment"); | ||
} | ||
|
||
this.inArray1 = new byte[alignment * 2]; | ||
this.inArray2 = new byte[alignment * 2]; | ||
this.outArray = new byte[alignment * 2]; | ||
|
||
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); | ||
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); | ||
this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned); | ||
|
||
this.alignment = (ulong)alignment; | ||
|
||
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), (uint)sizeOfinArray1); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<{Op2BaseType}, byte>(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* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), alignment); | ||
|
||
public void Dispose() | ||
{ | ||
inHandle1.Free(); | ||
inHandle2.Free(); | ||
outHandle.Free(); | ||
} | ||
|
||
private static unsafe void* Align(byte* buffer, ulong expectedAlignment) | ||
{ | ||
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); | ||
} | ||
} | ||
|
||
private struct TestStruct | ||
{ | ||
public {Op1VectorType}<{Op1BaseType}> _fld1; | ||
public {Op2VectorType}<{Op2BaseType}> _fld2; | ||
|
||
public static TestStruct Create() | ||
{ | ||
var testStruct = new TestStruct(); | ||
|
||
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref testStruct._fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); | ||
for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; } | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref testStruct._fld2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>()); | ||
|
||
return testStruct; | ||
} | ||
|
||
public void RunStructFldScenario({TemplateName}BinaryOpTest__{TestName} testClass) | ||
{ | ||
var result = {Isa}.{Method}(_fld1, _fld2); | ||
|
||
Unsafe.Write(testClass._dataTable.outArrayPtr, result); | ||
testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr); | ||
} | ||
} | ||
|
||
private static readonly int LargestVectorSize = {LargestVectorSize}; | ||
|
||
private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType}); | ||
private static readonly int Op2ElementCount = Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>() / sizeof({Op2BaseType}); | ||
private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType}); | ||
|
||
private static {Op1BaseType}[] _data1 = new {Op1BaseType}[Op1ElementCount]; | ||
private static {Op2BaseType}[] _data2 = new {Op2BaseType}[Op2ElementCount]; | ||
|
||
private {Op1VectorType}<{Op1BaseType}> _fld1; | ||
private {Op2VectorType}<{Op2BaseType}> _fld2; | ||
|
||
private DataTable _dataTable; | ||
|
||
public {TemplateName}BinaryOpTest__{TestName}() | ||
{ | ||
Succeeded = true; | ||
|
||
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); | ||
for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; } | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref _fld2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>()); | ||
|
||
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } | ||
for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; } | ||
_dataTable = new DataTable(_data1, _data2, new {RetBaseType}[RetElementCount], LargestVectorSize); | ||
} | ||
|
||
public bool IsSupported => {Isa}.IsSupported; | ||
|
||
public bool Succeeded { get; set; } | ||
|
||
public void RunBasicScenario_UnsafeRead() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); | ||
|
||
var result = {Isa}.{Method}( | ||
Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr), | ||
Unsafe.Read<{Op2VectorType}<{Op2BaseType}>>(_dataTable.inArray2Ptr) | ||
); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunBasicScenario_Load() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load)); | ||
Vector<{Op1BaseType}> loadMask = Sve.CreateTrueMask{Op1BaseType}(SveMaskPattern.All); | ||
|
||
var result = {Isa}.{Method}( | ||
{LoadIsa}.Load{Op1VectorType}(loadMask, ({Op1BaseType}*)(_dataTable.inArray1Ptr)), | ||
{LoadIsa}.Load{Op2VectorType}(loadMask, ({Op2BaseType}*)(_dataTable.inArray2Ptr)) | ||
); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunReflectionScenario_UnsafeRead() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); | ||
|
||
var result = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1VectorType}<{Op1BaseType}>), typeof({Op2VectorType}<{Op2BaseType}>) }) | ||
.Invoke(null, new object[] { | ||
Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr), | ||
Unsafe.Read<{Op2VectorType}<{Op2BaseType}>>(_dataTable.inArray2Ptr) | ||
}); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result)); | ||
ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunLclVarScenario_UnsafeRead() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); | ||
|
||
var op1 = Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr); | ||
var op2 = Unsafe.Read<{Op2VectorType}<{Op2BaseType}>>(_dataTable.inArray2Ptr); | ||
var result = {Isa}.{Method}(op1, op2); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(op1, op2, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunClassFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); | ||
|
||
var result = {Isa}.{Method}(_fld1, _fld2); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunStructLclFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); | ||
|
||
var test = TestStruct.Create(); | ||
var result = {Isa}.{Method}(test._fld1, test._fld2); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunStructFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); | ||
|
||
var test = TestStruct.Create(); | ||
test.RunStructFldScenario(this); | ||
} | ||
|
||
public void RunUnsupportedScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); | ||
|
||
bool succeeded = false; | ||
|
||
try | ||
{ | ||
RunBasicScenario_UnsafeRead(); | ||
} | ||
catch (PlatformNotSupportedException) | ||
{ | ||
succeeded = true; | ||
} | ||
|
||
if (!succeeded) | ||
{ | ||
Succeeded = false; | ||
} | ||
} | ||
|
||
private void ValidateResult({Op1VectorType}<{Op1BaseType}> op1, {Op2VectorType}<{Op2BaseType}> op2, void* result, [CallerMemberName] string method = "") | ||
{ | ||
{Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount]; | ||
{Op2BaseType}[] inArray2 = new {Op2BaseType}[Op2ElementCount]; | ||
{RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; | ||
|
||
Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), op1); | ||
Unsafe.WriteUnaligned(ref Unsafe.As<{Op2BaseType}, byte>(ref inArray2[0]), op2); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); | ||
|
||
ValidateResult(inArray1, inArray2, outArray, method); | ||
} | ||
|
||
private void ValidateResult(void* op1, void* op2, void* result, [CallerMemberName] string method = "") | ||
{ | ||
{Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount]; | ||
{Op2BaseType}[] inArray2 = new {Op2BaseType}[Op2ElementCount]; | ||
{RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; | ||
|
||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(op1), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2BaseType}, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(op2), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>()); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); | ||
|
||
ValidateResult(inArray1, inArray2, outArray, method); | ||
} | ||
|
||
private void ValidateResult({Op1BaseType}[] left, {Op2BaseType}[] right, {RetBaseType}[] result, [CallerMemberName] string method = "") | ||
{ | ||
bool succeeded = true; | ||
|
||
{TemplateValidationLogic} | ||
|
||
if (!succeeded) | ||
{ | ||
TestLibrary.TestFramework.LogInformation($"{nameof({Isa})}.{nameof({Isa}.{Method})}<{RetBaseType}>({Op1VectorType}<{Op1BaseType}>, {Op2VectorType}<{Op2BaseType}>): {method} failed:"); | ||
TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})"); | ||
TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})"); | ||
TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); | ||
TestLibrary.TestFramework.LogInformation(string.Empty); | ||
|
||
Succeeded = false; | ||
} | ||
} | ||
} | ||
} |
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.
I just realized that zip and unzip instructions operate on both vector and predicate registers. How do we know which one to invoke? Currently, we will always invoke vector variants? @a74nh ?
If we always going to support just the vector version, then please remove the comment for predicate registers.
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.
Right now it'll just be the vector variant. If we're using masks then there will be a lot of conversions and the vector version will be used.
Raised a ticket: #101598
In the meantime, is it ok to leave the comment as is?
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.
Thanks for opening an issue and yes, ok to keep it as of now.