-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict ConvertToDouble(Vector128<UInt64>) tests to inputs no more t…
…han long.MaxValue
- Loading branch information
1 parent
a6edef2
commit 391d177
Showing
29 changed files
with
2,378 additions
and
187 deletions.
There are no files selected for viewing
50 changes: 25 additions & 25 deletions
50
src/tests/JIT/HardwareIntrinsics/General/Shared/GenerateTests.csx
Large diffs are not rendered by default.
Oops, something went wrong.
313 changes: 313 additions & 0 deletions
313
src/tests/JIT/HardwareIntrinsics/General/Shared/VectorConvertToTest.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,313 @@ | ||
// 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; | ||
|
||
namespace JIT.HardwareIntrinsics.General | ||
{ | ||
public static partial class Program | ||
{ | ||
private static void {Method}{Op1BaseType}() | ||
{ | ||
var test = new VectorUnaryOpTest__{Method}{Op1BaseType}(); | ||
|
||
// Validates basic functionality works, using Unsafe.Read | ||
test.RunBasicScenario_UnsafeRead(); | ||
|
||
// Validates calling via reflection works, using Unsafe.Read | ||
test.RunReflectionScenario_UnsafeRead(); | ||
|
||
// Validates passing a static member works | ||
test.RunClsVarScenario(); | ||
|
||
// Validates passing a local works, using Unsafe.Read | ||
test.RunLclVarScenario_UnsafeRead(); | ||
|
||
// Validates passing the field of a local class works | ||
test.RunClassLclFldScenario(); | ||
|
||
// 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(); | ||
|
||
if (!test.Succeeded) | ||
{ | ||
throw new Exception("One or more scenarios did not complete as expected."); | ||
} | ||
} | ||
} | ||
|
||
public sealed unsafe class VectorUnaryOpTest__{Method}{Op1BaseType} | ||
{ | ||
private struct DataTable | ||
{ | ||
private byte[] inArray1; | ||
private byte[] outArray; | ||
|
||
private GCHandle inHandle1; | ||
private GCHandle outHandle; | ||
|
||
private ulong alignment; | ||
|
||
public DataTable({Op1BaseType}[] inArray1, {RetBaseType}[] outArray, int alignment) | ||
{ | ||
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<{Op1BaseType}>(); | ||
int sizeOfoutArray = outArray.Length * Unsafe.SizeOf<{RetBaseType}>(); | ||
if ((alignment != 32 && alignment != 16 && alignment != 8) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfoutArray) | ||
{ | ||
throw new ArgumentException("Invalid value of alignment"); | ||
} | ||
|
||
this.inArray1 = new byte[alignment * 2]; | ||
this.outArray = new byte[alignment * 2]; | ||
|
||
this.inHandle1 = GCHandle.Alloc(this.inArray1, 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); | ||
} | ||
|
||
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); | ||
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), alignment); | ||
|
||
public void Dispose() | ||
{ | ||
inHandle1.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 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}>>()); | ||
|
||
return testStruct; | ||
} | ||
|
||
public void RunStructFldScenario(VectorUnaryOpTest__{Method}{Op1BaseType} testClass) | ||
{ | ||
var result = {Isa}.{Method}(_fld1); | ||
|
||
Unsafe.Write(testClass._dataTable.outArrayPtr, result); | ||
testClass.ValidateResult(_fld1, testClass._dataTable.outArrayPtr); | ||
} | ||
} | ||
|
||
private static readonly int LargestVectorSize = {LargestVectorSize}; | ||
|
||
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}[] _data1 = new {Op1BaseType}[Op1ElementCount]; | ||
|
||
private static {Op1VectorType}<{Op1BaseType}> _clsVar1; | ||
|
||
private {Op1VectorType}<{Op1BaseType}> _fld1; | ||
|
||
private DataTable _dataTable; | ||
|
||
static VectorUnaryOpTest__{Method}{Op1BaseType}() | ||
{ | ||
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _clsVar1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); | ||
} | ||
|
||
public VectorUnaryOpTest__{Method}{Op1BaseType}() | ||
{ | ||
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 < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } | ||
_dataTable = new DataTable(_data1, new {RetBaseType}[RetElementCount], LargestVectorSize); | ||
} | ||
|
||
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.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunReflectionScenario_UnsafeRead() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead)); | ||
|
||
var method = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { | ||
typeof({Op1VectorType}<{Op1BaseType}>) | ||
}); | ||
|
||
if (method is null) | ||
{ | ||
method = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), 1, new Type[] { | ||
typeof({Op1VectorType}<>).MakeGenericType(Type.MakeGenericMethodParameter(0)) | ||
}); | ||
} | ||
|
||
if (method.IsGenericMethodDefinition) | ||
{ | ||
method = method.MakeGenericMethod(typeof({RetBaseType})); | ||
} | ||
|
||
var result = method.Invoke(null, new object[] { | ||
Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr) | ||
}); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result)); | ||
ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunClsVarScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); | ||
|
||
var result = {Isa}.{Method}( | ||
_clsVar1 | ||
); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_clsVar1, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunLclVarScenario_UnsafeRead() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); | ||
|
||
var op1 = Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr); | ||
var result = {Isa}.{Method}(op1); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(op1, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunClassLclFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); | ||
|
||
var test = new VectorUnaryOpTest__{Method}{Op1BaseType}(); | ||
var result = {Isa}.{Method}(test._fld1); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(test._fld1, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunClassFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); | ||
|
||
var result = {Isa}.{Method}(_fld1); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(_fld1, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunStructLclFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); | ||
|
||
var test = TestStruct.Create(); | ||
var result = {Isa}.{Method}(test._fld1); | ||
|
||
Unsafe.Write(_dataTable.outArrayPtr, result); | ||
ValidateResult(test._fld1, _dataTable.outArrayPtr); | ||
} | ||
|
||
public void RunStructFldScenario() | ||
{ | ||
TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); | ||
|
||
var test = TestStruct.Create(); | ||
test.RunStructFldScenario(this); | ||
} | ||
|
||
private void ValidateResult({Op1VectorType}<{Op1BaseType}> op1, void* result, [CallerMemberName] string method = "") | ||
{ | ||
{Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount]; | ||
{RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; | ||
|
||
Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), op1); | ||
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); | ||
|
||
ValidateResult(inArray1, outArray, method); | ||
} | ||
|
||
private void ValidateResult(void* op1, void* result, [CallerMemberName] string method = "") | ||
{ | ||
{Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount]; | ||
{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<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); | ||
|
||
ValidateResult(inArray1, outArray, method); | ||
} | ||
|
||
private void ValidateResult({Op1BaseType}[] firstOp, {RetBaseType}[] result, [CallerMemberName] string method = "") | ||
{ | ||
bool succeeded = true; | ||
|
||
if ({ValidateFirstResult}) | ||
{ | ||
succeeded = false; | ||
} | ||
else | ||
{ | ||
for (var i = 1; i < RetElementCount; i++) | ||
{ | ||
if ({ValidateRemainingResults}) | ||
{ | ||
succeeded = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!succeeded) | ||
{ | ||
TestLibrary.TestFramework.LogInformation($"{nameof({Isa})}.{nameof({Isa}.{Method})}<{RetBaseType}>({Op1VectorType}<{Op1BaseType}>): {method} failed:"); | ||
TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); | ||
TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); | ||
TestLibrary.TestFramework.LogInformation(string.Empty); | ||
|
||
Succeeded = false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.