From 556477ec9424e6a6697d625ece9c93da30a107db Mon Sep 17 00:00:00 2001 From: Aman Khalid Date: Fri, 30 Aug 2024 19:42:50 +0000 Subject: [PATCH] ARM-SVE: Fix validation logic for GatherVectorByteOffsetFirstFaulting tests (#107165) --- .../JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs | 10 ++++------ .../SveGatherVectorByteOffsetFirstFaulting.template | 11 +++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs index e5db9378d52417..4f5243c1641319 100644 --- a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs +++ b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs @@ -8958,7 +8958,7 @@ public static bool CheckGatherVectorBasesFirstFaultingBehavior GetGatherVectorBasesResultByIndex(i, mask, data) == result[i]); } - public static bool CheckGatherVectorWithByteOffsetFirstFaultingBehavior(T[] mask, ExtendedElementT[] data, Offset[] offsets, T[] result, Vector faultResult) + public static bool CheckGatherVectorWithByteOffsetFirstFaultingBehavior(T[] mask, byte[] data, Offset[] offsets, T[] result, Vector faultResult) where T : INumberBase where ExtendedElementT : INumberBase where Offset : IBinaryInteger @@ -8971,6 +8971,7 @@ public static bool CheckGatherVectorWithByteOffsetFirstFaultingBehavior(); var hasFaulted = false; var expectedFaultResult = InitVector(i => @@ -8986,8 +8987,7 @@ public static bool CheckGatherVectorWithByteOffsetFirstFaultingBehavior(); - if (offset < 0 || offset >= endOffset) + if (offset < 0 || (offset + elemSize) > data.Length) { hasFaulted = true; return TFault.Zero; @@ -9000,9 +9000,7 @@ public static bool CheckGatherVectorWithByteOffsetFirstFaultingBehavior()]; - Buffer.BlockCopy(data, 0, bytes, 0, bytes.Length); - return CheckFirstFaultingBehaviorCore(result, faultResult, i => GetGatherVectorResultByByteOffset(i, mask, bytes, offsets, result[i])); + return CheckFirstFaultingBehaviorCore(result, faultResult, i => GetGatherVectorResultByByteOffset(i, mask, data, offsets, result[i])); } public static T[] CreateBreakPropagateMask(T[] op1, T[] op2) where T : IBinaryInteger diff --git a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/SveGatherVectorByteOffsetFirstFaulting.template b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/SveGatherVectorByteOffsetFirstFaulting.template index e7b466bfb201a6..acb0ab0fc8103f 100644 --- a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/SveGatherVectorByteOffsetFirstFaulting.template +++ b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/SveGatherVectorByteOffsetFirstFaulting.template @@ -326,7 +326,7 @@ namespace JIT.HardwareIntrinsics.Arm ref var op3Ref = ref op3; Unsafe.Write(_dataTable.outArrayPtr, result); - ValidateFirstFaultingResult(Unsafe.AsPointer(ref op1Ref), ref op2Ref, _dataTable.inBounded.Span.Length, Unsafe.AsPointer(ref op3Ref), _dataTable.outArrayPtr, faultResult); + ValidateFirstFaultingResult(Unsafe.AsPointer(ref op1Ref), Unsafe.AsPointer(ref op3Ref), _dataTable.outArrayPtr, faultResult); } public void RunBasicScenario_FalseMask() @@ -718,24 +718,23 @@ namespace JIT.HardwareIntrinsics.Arm } } - private void ValidateFirstFaultingResult(void* op1, ref byte op2, int op2Size, void* op3, void* result, Vector<{GetFfrType}> faultResult, [CallerMemberName] string method = "") + private void ValidateFirstFaultingResult(void* op1, void* op3, void* result, Vector<{GetFfrType}> faultResult, [CallerMemberName] string method = "") { {Op1BaseType}[] inArray1 = new {Op1BaseType}[Vector<{Op1BaseType}>.Count]; - {Op2BaseType}[] inArray2 = new {Op2BaseType}[op2Size / Unsafe.SizeOf<{Op2BaseType}>()]; + byte[] inArray2 = _dataTable.inBounded.Span.ToArray(); {Op3BaseType}[] inArray3 = new {Op3BaseType}[Vector<{Op3BaseType}>.Count]; {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount]; Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), ref Unsafe.AsRef(op1), (uint)(inArray1.Length * Unsafe.SizeOf<{Op1BaseType}>())); - Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2BaseType}, byte>(ref inArray2[0]), ref op2, (uint)(inArray2.Length * Unsafe.SizeOf<{Op2BaseType}>())); Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op3BaseType}, byte>(ref inArray3[0]), ref Unsafe.AsRef(op3), (uint)(inArray3.Length * Unsafe.SizeOf<{Op3BaseType}>())); Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); ValidateFirstFaultingResult(inArray1, inArray2, inArray3, outArray, faultResult, method); } - private void ValidateFirstFaultingResult({Op1BaseType}[] firstOp, {Op2BaseType}[] secondOp, {Op3BaseType}[] thirdOp, {RetBaseType}[] result, Vector<{GetFfrType}> faultResult, [CallerMemberName] string method = "") + private void ValidateFirstFaultingResult({Op1BaseType}[] firstOp, byte[] secondOp, {Op3BaseType}[] thirdOp, {RetBaseType}[] result, Vector<{GetFfrType}> faultResult, [CallerMemberName] string method = "") { - var succeeded = Helpers.CheckGatherVectorWithByteOffsetFirstFaultingBehavior(firstOp, secondOp, thirdOp, result, faultResult); + var succeeded = Helpers.CheckGatherVectorWithByteOffsetFirstFaultingBehavior<{Op1BaseType}, {Op2BaseType}, {Op3BaseType}, {GetFfrType}>(firstOp, secondOp, thirdOp, result, faultResult); if (!succeeded) {