Skip to content
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

(WIP) Arm64/SVE: Implemented ConvertToSingle and ConvertToDouble #104259

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c738b77
Added ConverToInt32 and ConvertToUInt32 for float inputs.
ebepho Jun 5, 2024
35d39d9
Added flags to handle only low predicate registers.
ebepho Jun 5, 2024
7a781e1
Fixed merge conflicts.
ebepho Jun 5, 2024
1378d60
Fix whitespace
ebepho Jun 5, 2024
10c7a15
Remove special codegen flag
ebepho Jun 7, 2024
8004868
Added new test template for operations with different return types.
ebepho Jun 10, 2024
af7ccd4
Merge branch 'main' into ConvertToInt32
ebepho Jun 10, 2024
8cb76da
Add new test template.
ebepho Jun 11, 2024
abe25fc
Added api for ConvertToInt32 and ConvertToUInt 32 for double.
ebepho Jun 13, 2024
0f51f38
fix merge conflicts.
ebepho Jun 13, 2024
7fabb91
Merge branch 'dotnet:main' into main
ebepho Jun 14, 2024
d5374ca
Merge branch 'main' of github.com:ebepho/runtime
ebepho Jun 15, 2024
fe32a2f
ConvertToSingle for int and uint.
ebepho Jun 15, 2024
478b969
ConvertToSingle for long and ulong.
ebepho Jun 15, 2024
4aa224d
Merge branch 'main' of github.com:ebepho/runtime
ebepho Jun 15, 2024
cc63edf
Merge branch 'main' into ConvertToSingleDouble
ebepho Jun 15, 2024
ff54068
Started ConvertToDouble.
ebepho Jun 15, 2024
56601b4
Merge branch 'main' of github.com:ebepho/runtime
ebepho Jun 17, 2024
04071a3
Merge branch 'main' of github.com:ebepho/runtime
ebepho Jun 18, 2024
ffcd267
Merge branch 'main' of github.com:ebepho/runtime
ebepho Jun 18, 2024
5ac4a05
Merge branch 'main' into converttosingledouble
ebepho Jun 18, 2024
04c069a
addressed comments.
ebepho Jun 28, 2024
94d04f4
double or long to 32 bit value.
ebepho Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new test template.
ebepho committed Jun 11, 2024
commit 8cb76daf603f6031836b92d7a1a2252d1148fc18
Original file line number Diff line number Diff line change
@@ -51,9 +51,6 @@ namespace JIT.HardwareIntrinsics.Arm
// Validates passing an instance member of a struct works
test.RunStructFldScenario();

// Validates executing the test inside conditional, with op1 as falseValue
test.ConditionalSelect_Op1();

// Validates executing the test inside conditional, with op3 as falseValue
test.ConditionalSelect_FalseOp();

@@ -148,24 +145,25 @@ namespace JIT.HardwareIntrinsics.Arm
private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType});
private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType});

private static {Op1BaseType}[] _maskData = new {Op1BaseType}[Op1ElementCount];
private static {Op1BaseType}[] _data1 = new {Op1BaseType}[Op1ElementCount];
private static {RetBaseType}[] _data2 = new {RetBaseType}[Op1ElementCount];

private {Op1VectorType}<{Op1BaseType}> _mask;
private {Op1VectorType}<{RetBaseType}> _mask;
private {Op1VectorType}<{Op1BaseType}> _fld1;
private {Op1VectorType}<{Op1BaseType}> _falseFld;
private {Op1VectorType}<{RetBaseType}> _falseFld;

private DataTable _dataTable;

public {TemplateName}UnaryOpTest__{TestName}()
{
Succeeded = true;

for (var i = 0; i < Op1ElementCount; i++) { _maskData[i] = ({Op1BaseType})({NextValueOp1} % 2); }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _mask), ref Unsafe.As<{Op1BaseType}, byte>(ref _maskData[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
for (var i = 0; i < Op1ElementCount; i++) { _data2[i] = ({RetBaseType})({NextValueOp1} % 2); }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{RetBaseType}>, byte>(ref _mask), ref Unsafe.As<{RetBaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{RetBaseType}>>());
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}>>());
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _falseFld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
for (var i = 0; i < Op1ElementCount; i++) { _data2[i] = ({RetBaseType})_data1[i]; }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{RetBaseType}>, byte>(ref _falseFld), ref Unsafe.As<{RetBaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{RetBaseType}>>());

for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
_dataTable = new DataTable(_data1, new {RetBaseType}[RetElementCount], LargestVectorSize);
@@ -254,46 +252,34 @@ namespace JIT.HardwareIntrinsics.Arm
test.RunStructFldScenario(this);
}

public void ConditionalSelect_Op1()
{
TestLibrary.TestFramework.BeginScenario("ConditionalSelect_Op1_mask");
ConditionalSelectScenario(_mask, _fld1, _fld1);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_Op1_zero");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.Zero, _fld1, _fld1);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_Op1_all");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.AllBitsSet, _fld1, _fld1);
}

public void ConditionalSelect_FalseOp()
{
TestLibrary.TestFramework.BeginScenario(nameof(ConditionalSelect_FalseOp));
ConditionalSelectScenario(_mask, _fld1, _falseFld);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_zero");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.Zero, _fld1, _falseFld);
ConditionalSelectScenario({Op1VectorType}<{RetBaseType}>.Zero, _fld1, _falseFld);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_all");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.AllBitsSet, _fld1, _falseFld);
ConditionalSelectScenario({Op1VectorType}<{RetBaseType}>.AllBitsSet, _fld1, _falseFld);
}

public void ConditionalSelect_ZeroOp()
{
TestLibrary.TestFramework.BeginScenario(nameof(ConditionalSelect_ZeroOp));
ConditionalSelectScenario(_mask, _fld1, {Op1VectorType}<{Op1BaseType}>.Zero);
ConditionalSelectScenario(_mask, _fld1, {Op1VectorType}<{RetBaseType}>.Zero);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_zero");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.Zero, _fld1, {Op1VectorType}<{Op1BaseType}>.Zero);
ConditionalSelectScenario({Op1VectorType}<{RetBaseType}>.Zero, _fld1, {Op1VectorType}<{RetBaseType}>.Zero);

TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_all");
ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}>.AllBitsSet, _fld1, {Op1VectorType}<{Op1BaseType}>.Zero);
ConditionalSelectScenario({Op1VectorType}<{RetBaseType}>.AllBitsSet, _fld1, {Op1VectorType}<{RetBaseType}>.Zero);
}

[method: MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ConditionalSelectScenario({Op1VectorType}<{Op1BaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {Op1VectorType}<{Op1BaseType}> falseOp)
private void ConditionalSelectScenario({Op1VectorType}<{RetBaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {Op1VectorType}<{RetBaseType}> falseOp)
{
var result = Sve.ConditionalSelect({Isa}.{Method}(mask), {Isa}.{Method}(op1), {Isa}.{Method}(falseOp));
var result = Sve.ConditionalSelect(mask, {Isa}.{Method}(op1), falseOp);

Unsafe.Write(_dataTable.outArrayPtr, result);
ValidateConditionalSelectResult(mask, op1, falseOp, _dataTable.outArrayPtr);
@@ -320,16 +306,16 @@ namespace JIT.HardwareIntrinsics.Arm
}
}

private void ValidateConditionalSelectResult({Op1VectorType}<{Op1BaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {Op1VectorType}<{Op1BaseType}> falseOp, void* output, [CallerMemberName] string method = "")
private void ValidateConditionalSelectResult({Op1VectorType}<{RetBaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {Op1VectorType}<{RetBaseType}> falseOp, void* output, [CallerMemberName] string method = "")
{
{Op1BaseType}[] mask = new {Op1BaseType}[Op1ElementCount];
{RetBaseType}[] mask = new {RetBaseType}[Op1ElementCount];
{Op1BaseType}[] left = new {Op1BaseType}[Op1ElementCount];
{Op1BaseType}[] falseVal = new {Op1BaseType}[Op1ElementCount];
{RetBaseType}[] falseVal = new {RetBaseType}[Op1ElementCount];
{RetBaseType}[] result = new {RetBaseType}[RetElementCount];

Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref mask[0]), maskOp);
Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref mask[0]), maskOp);
Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref left[0]), leftOp);
Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref falseVal[0]), falseOp);
Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref falseVal[0]), falseOp);
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref result[0]), ref Unsafe.AsRef<byte>(output), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());

bool succeeded = true;