Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 12 additions & 5 deletions src/coreclr/jit/hwintrinsicarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,14 @@ void HWIntrinsicInfo::lookupImmBounds(
case NI_Sve2_MultiplyDoublingWideningSaturateEvenBySelectedScalar:
case NI_Sve2_MultiplyDoublingWideningSaturateOddBySelectedScalar:
// Index is on the half-width vector, hence double the maximum index.
immUpperBound = Compiler::getSIMDVectorLength(simdSize, baseType) * 2 - 1;
immUpperBound = ((16 / genTypeSize(baseType)) * 2) - 1;
break;
default:
immUpperBound = Compiler::getSIMDVectorLength(simdSize, baseType) - 1;
// For most indexed operations in SVE, the index is relative to each 128-bit
// segment of the vector, not the entire vector. For example, selecting index 2
// of Vector<int> may cause v[2] and v[6] to be used in the operation, when
// VL == 256-bit.
immUpperBound = (16 / genTypeSize(baseType)) - 1;
break;
}
}
Expand All @@ -426,10 +430,13 @@ void HWIntrinsicInfo::lookupImmBounds(
case NI_AdvSimd_Arm64_StoreSelectedScalar:
case NI_AdvSimd_Arm64_DuplicateSelectedScalarToVector128:
case NI_AdvSimd_Arm64_InsertSelectedScalar:
case NI_Sve_FusedMultiplyAddBySelectedScalar:
case NI_Sve_FusedMultiplySubtractBySelectedScalar:
immUpperBound = (simdSize / genTypeSize(baseType)) - 1;
break;

case NI_Sve_ExtractVector:
immUpperBound = Compiler::getSIMDVectorLength(simdSize, baseType) - 1;
// Maximum index is 255 in terms of bytes, the node will
// hold the index in terms of T and scale it up to bytes.
immUpperBound = (256 / genTypeSize(baseType)) - 1;
break;

case NI_Sve_CreateTrueMaskByte:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
// static
int Compiler::getSIMDVectorLength(unsigned simdSize, var_types baseType)
{
assert(simdSize != SIZE_UNKNOWN);
return simdSize / genTypeSize(baseType);
}

Expand Down
20 changes: 10 additions & 10 deletions src/tests/Common/GenerateHWIntrinsicTests/Arm/SveTests.cs

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4333,7 +4333,8 @@ public static float[] MultiplyAddRotateComplexBySelectedScalar(float[] op1, floa
{
int real = i;
int img = i + 1;
(float op3Real, float op3Img) = (op3[index * 2], op3[(index * 2) + 1]);
int segmentBase = (i / 4) * 4;
(float op3Real, float op3Img) = (op3[segmentBase + index * 2], op3[segmentBase + (index * 2) + 1]);
(float ans1, float ans2) = imm switch
{
0 => (FusedMultiplyAdd(op1[real], op2[real], op3Real), FusedMultiplyAdd(op1[img], op2[real], op3Img)),
Expand All @@ -4352,11 +4353,14 @@ public static float[] MultiplyAddRotateComplexBySelectedScalar(float[] op1, floa

public static T[] MultiplyAddRotateComplexBySelectedScalar<T>(T[] op1, T[] op2, T[] op3, byte index, byte imm) where T : INumber<T>
{
int elementsPerSegment = 16 / Unsafe.SizeOf<T>();

for (int i = 0; i < op1.Length; i += 2)
{
int real = i;
int img = i + 1;
(T op3Real, T op3Img) = (op3[index * 2], op3[(index * 2) + 1]);
int segmentBase = (i / elementsPerSegment) * elementsPerSegment;
(T op3Real, T op3Img) = (op3[segmentBase + index * 2], op3[segmentBase + (index * 2) + 1]);
(T ans1, T ans2) = imm switch
{
0 => (op1[real] + op2[real] * op3Real, op1[img] + op2[real] * op3Img),
Expand Down Expand Up @@ -6941,6 +6945,28 @@ public static bool CheckLoadVectorBehavior<TMem, TElem>(TElem[] mask, TMem[] dat
return CheckLoadVectorBehaviorCore(mask, data, result, (_, loadResult) => loadResult);
}

public static bool CheckLoadVector128AndReplicateToVectorBehavior<TMem, TElem>(
TElem[] mask, TMem[] data, TElem[] result)
where TMem : INumberBase<TMem>, IConvertible
where TElem : INumberBase<TElem>
{
int elementsPerSegment = 16 / Unsafe.SizeOf<TMem>();

for (var i = 0; i < result.Length; i++)
{
TElem expectedResult = IsMaskInactive(mask[i])
? TElem.Zero
: TElem.CreateTruncating(data[i % elementsPerSegment]);

if (result[i] != expectedResult)
{
return false;
}
}

return true;
}

public static bool CheckLoadVectorBehavior<TMem, TElem>(TMem[] data, TElem[] result)
where TMem : INumberBase<TMem>, IConvertible
where TElem : INumberBase<TElem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ namespace {Namespace}

private void ValidateResult({Op1BaseType}[] firstOp, {Op2BaseType}[] secondOp, {RetBaseType}[] result, [CallerMemberName] string method = "")
{
bool succeeded = Helpers.CheckLoadVectorBehavior(firstOp, secondOp, result);
bool succeeded = nameof({Isa}.{Method}) == nameof(Sve.LoadVector128AndReplicateToVector)
? Helpers.CheckLoadVector128AndReplicateToVectorBehavior(firstOp, secondOp, result)
: Helpers.CheckLoadVectorBehavior(firstOp, secondOp, result);
if (!succeeded)
{
TestLibrary.TestFramework.LogInformation($"{nameof({Isa})}.{nameof({Isa}.{Method})}<{RetBaseType}>({Op1VectorType}<{Op1BaseType}>, {Op2BaseType}): {method} failed:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ namespace {Namespace}
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _mask), ref Unsafe.As<{RetBaseType}, byte>(ref _maskData[0]), (uint)sizeof({Op1VectorType}<{Op1BaseType}>));
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)sizeof({Op1VectorType}<{Op1BaseType}>));
for (var i = 0; i < Op1ElementCount; i++) { _data2[i] = {NextValueOp2}; }
for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref _fld2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)sizeof({Op2VectorType}<{Op2BaseType}>));
for (var i = 0; i < Op1ElementCount; i++) { _data3[i] = {NextValueOp3}; }
for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = {NextValueOp3}; }
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op3VectorType}<{Op3BaseType}>, byte>(ref _fld3), ref Unsafe.As<{Op3BaseType}, byte>(ref _data3[0]), (uint)sizeof({Op3VectorType}<{Op3BaseType}>));
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _falseFld), ref Unsafe.As<{Op3BaseType}, byte>(ref _data3[0]), (uint)sizeof({RetVectorType}<{RetBaseType}>));
Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _trueFld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)sizeof({RetVectorType}<{RetBaseType}>));
Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Regression_ro_1/Runtime_124511.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ public unsafe class Runtime_124511
[ConditionalFact(typeof(Sve), nameof(Sve.IsSupported))]
public static void TestEntryPoint()
{
Assert.True(MainTest() == -3);
Assert.True(MainTest() == (sbyte)(1 - Vector<uint>.Count));
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static sbyte MainTest()
{
// [1, 1, 1, 1, ...]
var vr8 = Vector.Create<uint>(1);
// [K, K, 0, 0, ...]
var vr9 = Vector128.CreateScalar(4701966028735610216UL).AsVector();
// [0, 0, 1, 1, ...]
var vr10 = Sve.ShiftLeftLogical(vr8, vr9);
// [2, 0, 0, 0, ...]
var vr11 = Vector128.CreateScalar(2U).AsVector();
// [-2, 0, 1, 1, ...]
var vr12 = Sve.Subtract(vr10, vr11);
// [1, 1, 1, 1, ...]
var vr13 = Vector.Create<uint>(1);
// [0, 0, 0, 0, ...]
var vr14 = Vector128.CreateScalar(0U).AsVector();
// [-1, 0, -1, -1, ...] ;; BRKP(pred, AllTrue, AllFalse) == pred
var vr15 = Sve.CreateBreakBeforePropagateMask(vr12, vr13, vr14);
// 0 - (1 - Vector<uint>.Count) == 1 - Vector<uint>.Count
sbyte vr16 = (sbyte)Sve.SaturatingDecrementByActiveElementCount(0, vr15);
return vr16;
}
Expand Down
73 changes: 9 additions & 64 deletions src/tests/JIT/opt/SVE/ConditionalSelectConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,19 @@ public class ConditionalSelectConstants
{
[MethodImpl(MethodImplOptions.NoInlining)]
[Fact]
public static int TestConditionalSelectConstants()
public static void TestConditionalSelectConstants()
{
bool fail = false;

if (Sve.IsSupported)
{
var smoke = Smoke();
Console.WriteLine(smoke);
if (smoke != Vector.Create<int>(-1))
{
fail = true;
}

var r1 = Sve.AddAcross(ConditionalSelect1CC());
Console.WriteLine(r1[0]);
if (r1[0] != 15)
{
fail = true;
}

var r2 = Sve.AddAcross(ConditionalSelect1FT());
Console.WriteLine(r2[0]);
if (r2[0] != -3)
{
fail = true;
}

var r3 = Sve.AddAcross(ConditionalSelect16TF());
Console.WriteLine(r3[0]);
if (r3[0] != 4080)
{
fail = true;
}

var r4 = Sve.AddAcross(ConditionalSelect2CT());
Console.WriteLine(r4[0]);
if (r4[0] != 16)
{
fail = true;
}

var r5 = ConditionalSelectConsts();
Console.WriteLine(r5);
if (r5 != 5)
{
fail = true;
}

var r6 = ConditionalSelectConstsNoMaskPattern();
Console.WriteLine(r6);
if (r6 != false)
{
fail = true;
}

var r7 = ConditionalSelectConstsNoMaskPattern2();
Console.WriteLine(r7);
if (r7 != 0)
{
fail = true;
}
}

if (fail)
{
return 101;
Assert.Equal(Vector.Create<int>(-1), Smoke());
Assert.Equal((Vector<int>.Count - 1) * 4 + 3, (int)Sve.AddAcross(ConditionalSelect1CC())[0]);
Assert.Equal((Vector<int>.Count - 1) * -1, (int)Sve.AddAcross(ConditionalSelect1FT())[0]);
Assert.Equal(4080, (int)Sve.AddAcross(ConditionalSelect16TF())[0]);
Assert.Equal((Vector<int>.Count - 2) * -1 + 2 * 9, (int)Sve.AddAcross(ConditionalSelect2CT())[0]);
Assert.Equal(5, ConditionalSelectConsts());
Assert.False(ConditionalSelectConstsNoMaskPattern());
Assert.Equal(0, ConditionalSelectConstsNoMaskPattern2());
}
return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
Loading