diff options
Diffstat (limited to 'tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs')
-rw-r--r-- | tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs | 250 |
1 files changed, 220 insertions, 30 deletions
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs b/tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs index 365f1d0202..3adebd7bb8 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Fma_Vector256/MultiplySubtractNegated.Double.cs @@ -52,6 +52,12 @@ namespace JIT.HardwareIntrinsics.X86 // Validates passing a static member works test.RunClsVarScenario(); + if (Avx.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 (Avx.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 (Avx.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 (Avx.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 (Avx.IsSupported) + { + // Validates passing an instance member of a struct works, using pinning and Load + test.RunStructFldScenario_Load(); + } } else { @@ -91,6 +121,67 @@ namespace JIT.HardwareIntrinsics.X86 public sealed unsafe class SimpleTernaryOpTest__MultiplySubtractNegatedDouble { + private struct DataTable + { + private byte[] inArray1; + private byte[] inArray2; + private byte[] inArray3; + private byte[] outArray; + + private GCHandle inHandle1; + private GCHandle inHandle2; + private GCHandle inHandle3; + private GCHandle outHandle; + + private ulong alignment; + + public DataTable(Double[] inArray1, Double[] inArray2, Double[] inArray3, Double[] outArray, int alignment) + { + int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<Double>(); + int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<Double>(); + int sizeOfinArray3 = inArray3.Length * Unsafe.SizeOf<Double>(); + int sizeOfoutArray = outArray.Length * Unsafe.SizeOf<Double>(); + if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2 || (alignment * 2) < sizeOfinArray3 || (alignment * 2) < sizeOfoutArray) + { + throw new ArgumentException("Invalid value of alignment"); + } + + this.inArray1 = new byte[alignment * 2]; + this.inArray2 = new byte[alignment * 2]; + this.inArray3 = 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.inHandle3 = GCHandle.Alloc(this.inArray3, GCHandleType.Pinned); + this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned); + + this.alignment = (ulong)alignment; + + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<Double, byte>(ref inArray1[0]), (uint)sizeOfinArray1); + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<Double, byte>(ref inArray2[0]), (uint)sizeOfinArray2); + Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray3Ptr), ref Unsafe.As<Double, byte>(ref inArray3[0]), (uint)sizeOfinArray3); + } + + public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment); + public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment); + public void* inArray3Ptr => Align((byte*)(inHandle3.AddrOfPinnedObject().ToPointer()), alignment); + public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), alignment); + + public void Dispose() + { + inHandle1.Free(); + inHandle2.Free(); + inHandle3.Free(); + outHandle.Free(); + } + + private static unsafe void* Align(byte* buffer, ulong expectedAlignment) + { + return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1)); + } + } + private struct TestStruct { public Vector256<Double> _fld1; @@ -106,7 +197,7 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector256<Double>>()); for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = TestLibrary.Generator.GetDouble(); } - Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _clsVar3), ref Unsafe.As<Double, byte>(ref _data3[0]), (uint)Unsafe.SizeOf<Vector256<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld3), ref Unsafe.As<Double, byte>(ref _data3[0]), (uint)Unsafe.SizeOf<Vector256<Double>>()); return testStruct; } @@ -118,6 +209,23 @@ namespace JIT.HardwareIntrinsics.X86 Unsafe.Write(testClass._dataTable.outArrayPtr, result); testClass.ValidateResult(_fld1, _fld2, _fld3, testClass._dataTable.outArrayPtr); } + + public void RunStructFldScenario_Load(SimpleTernaryOpTest__MultiplySubtractNegatedDouble testClass) + { + fixed (Vector256<Double>* pFld1 = &_fld1) + fixed (Vector256<Double>* pFld2 = &_fld2) + fixed (Vector256<Double>* pFld3 = &_fld3) + { + var result = Fma.MultiplySubtractNegated( + Avx.LoadVector256((Double*)(pFld1)), + Avx.LoadVector256((Double*)(pFld2)), + Avx.LoadVector256((Double*)(pFld3)) + ); + + Unsafe.Write(testClass._dataTable.outArrayPtr, result); + testClass.ValidateResult(_fld1, _fld2, _fld3, testClass._dataTable.outArrayPtr); + } + } } private static readonly int LargestVectorSize = 32; @@ -139,7 +247,7 @@ namespace JIT.HardwareIntrinsics.X86 private Vector256<Double> _fld2; private Vector256<Double> _fld3; - private SimpleTernaryOpTest__DataTable<Double, Double, Double, Double> _dataTable; + private DataTable _dataTable; static SimpleTernaryOpTest__MultiplySubtractNegatedDouble() { @@ -165,7 +273,7 @@ namespace JIT.HardwareIntrinsics.X86 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = TestLibrary.Generator.GetDouble(); } - _dataTable = new SimpleTernaryOpTest__DataTable<Double, Double, Double, Double>(_data1, _data2, _data3, new Double[RetElementCount], LargestVectorSize); + _dataTable = new DataTable(_data1, _data2, _data3, new Double[RetElementCount], LargestVectorSize); } public bool IsSupported => Fma.IsSupported; @@ -273,43 +381,62 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_clsVar1, _clsVar2, _clsVar3, _dataTable.outArrayPtr); } + public void RunClsVarScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load)); + + fixed (Vector256<Double>* pClsVar1 = &_clsVar1) + fixed (Vector256<Double>* pClsVar2 = &_clsVar2) + fixed (Vector256<Double>* pClsVar3 = &_clsVar3) + { + var result = Fma.MultiplySubtractNegated( + Avx.LoadVector256((Double*)(pClsVar1)), + Avx.LoadVector256((Double*)(pClsVar2)), + Avx.LoadVector256((Double*)(pClsVar3)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_clsVar1, _clsVar2, _clsVar3, _dataTable.outArrayPtr); + } + } + public void RunLclVarScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); - var firstOp = Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr); - var secondOp = Unsafe.Read<Vector256<Double>>(_dataTable.inArray2Ptr); - var thirdOp = Unsafe.Read<Vector256<Double>>(_dataTable.inArray3Ptr); - var result = Fma.MultiplySubtractNegated(firstOp, secondOp, thirdOp); + var op1 = Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr); + var op2 = Unsafe.Read<Vector256<Double>>(_dataTable.inArray2Ptr); + var op3 = Unsafe.Read<Vector256<Double>>(_dataTable.inArray3Ptr); + var result = Fma.MultiplySubtractNegated(op1, op2, op3); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, secondOp, thirdOp, _dataTable.outArrayPtr); + ValidateResult(op1, op2, op3, _dataTable.outArrayPtr); } public void RunLclVarScenario_Load() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load)); - var firstOp = Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)); - var secondOp = Avx.LoadVector256((Double*)(_dataTable.inArray2Ptr)); - var thirdOp = Avx.LoadVector256((Double*)(_dataTable.inArray3Ptr)); - var result = Fma.MultiplySubtractNegated(firstOp, secondOp, thirdOp); + var op1 = Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)); + var op2 = Avx.LoadVector256((Double*)(_dataTable.inArray2Ptr)); + var op3 = Avx.LoadVector256((Double*)(_dataTable.inArray3Ptr)); + var result = Fma.MultiplySubtractNegated(op1, op2, op3); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, secondOp, thirdOp, _dataTable.outArrayPtr); + ValidateResult(op1, op2, op3, _dataTable.outArrayPtr); } public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); - var firstOp = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)); - var secondOp = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray2Ptr)); - var thirdOp = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray3Ptr)); - var result = Fma.MultiplySubtractNegated(firstOp, secondOp, thirdOp); + var op1 = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)); + var op2 = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray2Ptr)); + var op3 = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray3Ptr)); + var result = Fma.MultiplySubtractNegated(op1, op2, op3); Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateResult(firstOp, secondOp, thirdOp, _dataTable.outArrayPtr); + ValidateResult(op1, op2, op3, _dataTable.outArrayPtr); } public void RunClassLclFldScenario() @@ -323,6 +450,27 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(test._fld1, test._fld2, test._fld3, _dataTable.outArrayPtr); } + public void RunClassLclFldScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load)); + + var test = new SimpleTernaryOpTest__MultiplySubtractNegatedDouble(); + + fixed (Vector256<Double>* pFld1 = &test._fld1) + fixed (Vector256<Double>* pFld2 = &test._fld2) + fixed (Vector256<Double>* pFld3 = &test._fld3) + { + var result = Fma.MultiplySubtractNegated( + Avx.LoadVector256((Double*)(pFld1)), + Avx.LoadVector256((Double*)(pFld2)), + Avx.LoadVector256((Double*)(pFld3)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, test._fld3, _dataTable.outArrayPtr); + } + } + public void RunClassFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario)); @@ -333,6 +481,25 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(_fld1, _fld2, _fld3, _dataTable.outArrayPtr); } + public void RunClassFldScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load)); + + fixed (Vector256<Double>* pFld1 = &_fld1) + fixed (Vector256<Double>* pFld2 = &_fld2) + fixed (Vector256<Double>* pFld3 = &_fld3) + { + var result = Fma.MultiplySubtractNegated( + Avx.LoadVector256((Double*)(pFld1)), + Avx.LoadVector256((Double*)(pFld2)), + Avx.LoadVector256((Double*)(pFld3)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(_fld1, _fld2, _fld3, _dataTable.outArrayPtr); + } + } + public void RunStructLclFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); @@ -344,6 +511,21 @@ namespace JIT.HardwareIntrinsics.X86 ValidateResult(test._fld1, test._fld2, test._fld3, _dataTable.outArrayPtr); } + public void RunStructLclFldScenario_Load() + { + TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load)); + + var test = TestStruct.Create(); + var result = Fma.MultiplySubtractNegated( + Avx.LoadVector256((Double*)(&test._fld1)), + Avx.LoadVector256((Double*)(&test._fld2)), + Avx.LoadVector256((Double*)(&test._fld3)) + ); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateResult(test._fld1, test._fld2, test._fld3, _dataTable.outArrayPtr); + } + public void RunStructFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario)); @@ -352,6 +534,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)); @@ -373,31 +563,31 @@ namespace JIT.HardwareIntrinsics.X86 } } - private void ValidateResult(Vector256<Double> firstOp, Vector256<Double> secondOp, Vector256<Double> thirdOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(Vector256<Double> op1, Vector256<Double> op2, Vector256<Double> op3, void* result, [CallerMemberName] string method = "") { Double[] inArray1 = new Double[Op1ElementCount]; Double[] inArray2 = new Double[Op2ElementCount]; Double[] inArray3 = new Double[Op3ElementCount]; Double[] outArray = new Double[RetElementCount]; - Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), firstOp); - Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), secondOp); - Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray3[0]), thirdOp); + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), op1); + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), op2); + Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray3[0]), op3); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>()); ValidateResult(inArray1, inArray2, inArray3, outArray, method); } - private void ValidateResult(void* firstOp, void* secondOp, void* thirdOp, void* result, [CallerMemberName] string method = "") + private void ValidateResult(void* op1, void* op2, void* op3, void* result, [CallerMemberName] string method = "") { Double[] inArray1 = new Double[Op1ElementCount]; Double[] inArray2 = new Double[Op2ElementCount]; Double[] inArray3 = new Double[Op3ElementCount]; Double[] outArray = new Double[RetElementCount]; - Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Double>>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(secondOp), (uint)Unsafe.SizeOf<Vector256<Double>>()); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray3[0]), ref Unsafe.AsRef<byte>(thirdOp), (uint)Unsafe.SizeOf<Vector256<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(op1), (uint)Unsafe.SizeOf<Vector256<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(op2), (uint)Unsafe.SizeOf<Vector256<Double>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray3[0]), ref Unsafe.AsRef<byte>(op3), (uint)Unsafe.SizeOf<Vector256<Double>>()); Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>()); ValidateResult(inArray1, inArray2, inArray3, outArray, method); @@ -426,10 +616,10 @@ namespace JIT.HardwareIntrinsics.X86 if (!succeeded) { TestLibrary.TestFramework.LogInformation($"{nameof(Fma)}.{nameof(Fma.MultiplySubtractNegated)}<Double>(Vector256<Double>, Vector256<Double>, Vector256<Double>): {method} failed:"); - TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); - TestLibrary.TestFramework.LogInformation($" secondOp: ({string.Join(", ", secondOp)})"); - TestLibrary.TestFramework.LogInformation($" thirdOp: ({string.Join(", ", thirdOp)})"); - TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($"secondOp: ({string.Join(", ", secondOp)})"); + TestLibrary.TestFramework.LogInformation($" thirdOp: ({string.Join(", ", thirdOp)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); TestLibrary.TestFramework.LogInformation(string.Empty); Succeeded = false; |