summaryrefslogtreecommitdiff
path: root/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs')
-rw-r--r--tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs251
1 files changed, 202 insertions, 49 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs
index 9687b275c0..a7dcd0a0e8 100644
--- a/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs
+++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse41/TestNotZAndNotC.UInt16.cs
@@ -21,7 +21,7 @@ namespace JIT.HardwareIntrinsics.X86
{
private static void TestNotZAndNotCUInt16()
{
- var test = new BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16();
+ var test = new BooleanBinaryOpTest__TestNotZAndNotCUInt16();
if (test.IsSupported)
{
@@ -52,6 +52,12 @@ namespace JIT.HardwareIntrinsics.X86
// Validates passing a static member works
test.RunClsVarScenario();
+ if (Sse2.IsSupported)
+ {
+ // Validates passing a static member works, using pinning and Load
+ test.RunClsVarScenario_Load();
+ }
+
// Validates passing a local works, using Unsafe.Read
test.RunLclVarScenario_UnsafeRead();
@@ -67,14 +73,38 @@ namespace JIT.HardwareIntrinsics.X86
// Validates passing the field of a local class works
test.RunClassLclFldScenario();
+ if (Sse2.IsSupported)
+ {
+ // Validates passing the field of a local class works, using pinning and Load
+ test.RunClassLclFldScenario_Load();
+ }
+
// Validates passing an instance member of a class works
test.RunClassFldScenario();
+ if (Sse2.IsSupported)
+ {
+ // Validates passing an instance member of a class works, using pinning and Load
+ test.RunClassFldScenario_Load();
+ }
+
// Validates passing the field of a local struct works
test.RunStructLclFldScenario();
+ if (Sse2.IsSupported)
+ {
+ // Validates passing the field of a local struct works, using pinning and Load
+ test.RunStructLclFldScenario_Load();
+ }
+
// Validates passing an instance member of a struct works
test.RunStructFldScenario();
+
+ if (Sse2.IsSupported)
+ {
+ // Validates passing an instance member of a struct works, using pinning and Load
+ test.RunStructFldScenario_Load();
+ }
}
else
{
@@ -89,8 +119,54 @@ namespace JIT.HardwareIntrinsics.X86
}
}
- public sealed unsafe class BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16
+ public sealed unsafe class BooleanBinaryOpTest__TestNotZAndNotCUInt16
{
+ private struct DataTable
+ {
+ private byte[] inArray1;
+ private byte[] inArray2;
+
+ private GCHandle inHandle1;
+ private GCHandle inHandle2;
+
+ private ulong alignment;
+
+ public DataTable(UInt16[] inArray1, UInt16[] inArray2, int alignment)
+ {
+ int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<UInt16>();
+ int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<UInt16>();
+ if ((alignment != 32 && 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<byte>(inArray1Ptr), ref Unsafe.As<UInt16, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
+ Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<UInt16, 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 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<UInt16> _fld1;
@@ -108,11 +184,25 @@ namespace JIT.HardwareIntrinsics.X86
return testStruct;
}
- public void RunStructFldScenario(BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16 testClass)
+ public void RunStructFldScenario(BooleanBinaryOpTest__TestNotZAndNotCUInt16 testClass)
{
var result = Sse41.TestNotZAndNotC(_fld1, _fld2);
testClass.ValidateResult(_fld1, _fld2, result);
}
+
+ public void RunStructFldScenario_Load(BooleanBinaryOpTest__TestNotZAndNotCUInt16 testClass)
+ {
+ fixed (Vector128<UInt16>* pFld1 = &_fld1)
+ fixed (Vector128<UInt16>* pFld2 = &_fld2)
+ {
+ var result = Sse41.TestNotZAndNotC(
+ Sse2.LoadVector128((UInt16*)(pFld1)),
+ Sse2.LoadVector128((UInt16*)(pFld2))
+ );
+
+ testClass.ValidateResult(_fld1, _fld2, result);
+ }
+ }
}
private static readonly int LargestVectorSize = 16;
@@ -129,9 +219,9 @@ namespace JIT.HardwareIntrinsics.X86
private Vector128<UInt16> _fld1;
private Vector128<UInt16> _fld2;
- private BooleanTwoComparisonOpTest__DataTable<UInt16, UInt16> _dataTable;
+ private DataTable _dataTable;
- static BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16()
+ static BooleanBinaryOpTest__TestNotZAndNotCUInt16()
{
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
@@ -139,7 +229,7 @@ namespace JIT.HardwareIntrinsics.X86
Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
}
- public BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16()
+ public BooleanBinaryOpTest__TestNotZAndNotCUInt16()
{
Succeeded = true;
@@ -150,7 +240,7 @@ namespace JIT.HardwareIntrinsics.X86
for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- _dataTable = new BooleanTwoComparisonOpTest__DataTable<UInt16, UInt16>(_data1, _data2, LargestVectorSize);
+ _dataTable = new DataTable(_data1, _data2, LargestVectorSize);
}
public bool IsSupported => Sse41.IsSupported;
@@ -197,51 +287,39 @@ namespace JIT.HardwareIntrinsics.X86
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
- var method = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) });
-
- if (method != null)
- {
- var result = method.Invoke(null, new object[] {
+ var result = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) })
+ .Invoke(null, new object[] {
Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray1Ptr),
Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray2Ptr)
});
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
- }
+ ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
}
public void RunReflectionScenario_Load()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
- var method = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) });
-
- if (method != null)
- {
- var result = method.Invoke(null, new object[] {
+ var result = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) })
+ .Invoke(null, new object[] {
Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr)),
Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr))
});
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
- }
+ ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
}
public void RunReflectionScenario_LoadAligned()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
- var method = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) });
-
- if (method != null)
- {
- var result = method.Invoke(null, new object[] {
+ var result = typeof(Sse41).GetMethod(nameof(Sse41.TestNotZAndNotC), new Type[] { typeof(Vector128<UInt16>), typeof(Vector128<UInt16>) })
+ .Invoke(null, new object[] {
Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr)),
Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr))
});
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
- }
+ ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
}
public void RunClsVarScenario()
@@ -256,49 +334,83 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_clsVar1, _clsVar2, result);
}
+ public void RunClsVarScenario_Load()
+ {
+ TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load));
+
+ fixed (Vector128<UInt16>* pClsVar1 = &_clsVar1)
+ fixed (Vector128<UInt16>* pClsVar2 = &_clsVar2)
+ {
+ var result = Sse41.TestNotZAndNotC(
+ Sse2.LoadVector128((UInt16*)(pClsVar1)),
+ Sse2.LoadVector128((UInt16*)(pClsVar2))
+ );
+
+ ValidateResult(_clsVar1, _clsVar2, result);
+ }
+ }
+
public void RunLclVarScenario_UnsafeRead()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
- var left = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray1Ptr);
- var right = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray2Ptr);
- var result = Sse41.TestNotZAndNotC(left, right);
+ var op1 = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray1Ptr);
+ var op2 = Unsafe.Read<Vector128<UInt16>>(_dataTable.inArray2Ptr);
+ var result = Sse41.TestNotZAndNotC(op1, op2);
- ValidateResult(left, right, result);
+ ValidateResult(op1, op2, result);
}
public void RunLclVarScenario_Load()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
- var left = Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr));
- var right = Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr));
- var result = Sse41.TestNotZAndNotC(left, right);
+ var op1 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray1Ptr));
+ var op2 = Sse2.LoadVector128((UInt16*)(_dataTable.inArray2Ptr));
+ var result = Sse41.TestNotZAndNotC(op1, op2);
- ValidateResult(left, right, result);
+ ValidateResult(op1, op2, result);
}
public void RunLclVarScenario_LoadAligned()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
- var left = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr));
- var right = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr));
- var result = Sse41.TestNotZAndNotC(left, right);
+ var op1 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray1Ptr));
+ var op2 = Sse2.LoadAlignedVector128((UInt16*)(_dataTable.inArray2Ptr));
+ var result = Sse41.TestNotZAndNotC(op1, op2);
- ValidateResult(left, right, result);
+ ValidateResult(op1, op2, result);
}
public void RunClassLclFldScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
- var test = new BooleanTwoComparisonOpTest__TestNotZAndNotCUInt16();
+ var test = new BooleanBinaryOpTest__TestNotZAndNotCUInt16();
var result = Sse41.TestNotZAndNotC(test._fld1, test._fld2);
ValidateResult(test._fld1, test._fld2, result);
}
+ public void RunClassLclFldScenario_Load()
+ {
+ TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load));
+
+ var test = new BooleanBinaryOpTest__TestNotZAndNotCUInt16();
+
+ fixed (Vector128<UInt16>* pFld1 = &test._fld1)
+ fixed (Vector128<UInt16>* pFld2 = &test._fld2)
+ {
+ var result = Sse41.TestNotZAndNotC(
+ Sse2.LoadVector128((UInt16*)(pFld1)),
+ Sse2.LoadVector128((UInt16*)(pFld2))
+ );
+
+ ValidateResult(test._fld1, test._fld2, result);
+ }
+ }
+
public void RunClassFldScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
@@ -308,6 +420,22 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(_fld1, _fld2, result);
}
+ public void RunClassFldScenario_Load()
+ {
+ TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load));
+
+ fixed (Vector128<UInt16>* pFld1 = &_fld1)
+ fixed (Vector128<UInt16>* pFld2 = &_fld2)
+ {
+ var result = Sse41.TestNotZAndNotC(
+ Sse2.LoadVector128((UInt16*)(pFld1)),
+ Sse2.LoadVector128((UInt16*)(pFld2))
+ );
+
+ ValidateResult(_fld1, _fld2, result);
+ }
+ }
+
public void RunStructLclFldScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
@@ -317,6 +445,19 @@ namespace JIT.HardwareIntrinsics.X86
ValidateResult(test._fld1, test._fld2, result);
}
+ public void RunStructLclFldScenario_Load()
+ {
+ TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load));
+
+ var test = TestStruct.Create();
+ var result = Sse41.TestNotZAndNotC(
+ Sse2.LoadVector128((UInt16*)(&test._fld1)),
+ Sse2.LoadVector128((UInt16*)(&test._fld2))
+ );
+
+ ValidateResult(test._fld1, test._fld2, result);
+ }
+
public void RunStructFldScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
@@ -325,6 +466,14 @@ namespace JIT.HardwareIntrinsics.X86
test.RunStructFldScenario(this);
}
+ public void RunStructFldScenario_Load()
+ {
+ TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario_Load));
+
+ var test = TestStruct.Create();
+ test.RunStructFldScenario_Load(this);
+ }
+
public void RunUnsupportedScenario()
{
TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
@@ -346,30 +495,32 @@ namespace JIT.HardwareIntrinsics.X86
}
}
- private void ValidateResult(Vector128<UInt16> left, Vector128<UInt16> right, bool result, [CallerMemberName] string method = "")
+ private void ValidateResult(Vector128<UInt16> op1, Vector128<UInt16> op2, bool result, [CallerMemberName] string method = "")
{
UInt16[] inArray1 = new UInt16[Op1ElementCount];
UInt16[] inArray2 = new UInt16[Op2ElementCount];
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), left);
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), right);
+ Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), op1);
+ Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), op2);
ValidateResult(inArray1, inArray2, result, method);
}
- private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "")
+ private void ValidateResult(void* op1, void* op2, bool result, [CallerMemberName] string method = "")
{
UInt16[] inArray1 = new UInt16[Op1ElementCount];
UInt16[] inArray2 = new UInt16[Op2ElementCount];
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(op1), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(op2), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
ValidateResult(inArray1, inArray2, result, method);
}
private void ValidateResult(UInt16[] left, UInt16[] right, bool result, [CallerMemberName] string method = "")
{
+ bool succeeded = true;
+
var expectedResult1 = true;
for (var i = 0; i < Op1ElementCount; i++)
@@ -384,12 +535,14 @@ namespace JIT.HardwareIntrinsics.X86
expectedResult2 &= (((~left[i] & right[i]) == 0));
}
- if (((expectedResult1 == false) && (expectedResult2 == false)) != result)
+ succeeded = (((expectedResult1 == false) && (expectedResult2 == false)) == result);
+
+ if (!succeeded)
{
TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.TestNotZAndNotC)}<UInt16>(Vector128<UInt16>, Vector128<UInt16>): {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($" result: ({result})");
TestLibrary.TestFramework.LogInformation(string.Empty);
Succeeded = false;