Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor handling of two immediates in hwintrinsic #102071

Merged
merged 5 commits into from May 13, 2024

Conversation

a74nh
Copy link
Contributor

@a74nh a74nh commented May 10, 2024

Out of all the existing hwintrinsics, only NI_AdvSimd_Arm64_InsertSelectedScalar has two immediate values. This also has the property that both immediates are of the same type, therefore handling of the type information and type checking can be simplified for the second immediate.

For Sve, SaturatingIncrementBy*ElementCount, SaturatingDecrementBy*ElementCount, and MultiplyAddRotateComplexBySelectedScalar all require two immediate values. In addition for the Saturating functions, the immediates have different types.

This PR refactors the existing handling so that it will work for Sve. It does not add any new Sve intrinsics.

  • Move checks for specific intrinsics out of common code into Arm64 files
  • Handle the type the second immediate separately to the type of the first.

The code still feels a little clunky, but I hope impHWIntrinsic() is much easier to parse now.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 10, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 10, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@a74nh a74nh force-pushed the immediate_refactor_github branch from 1fc5007 to b04cc90 Compare May 10, 2024 10:32
@a74nh a74nh force-pushed the immediate_refactor_github branch from b04cc90 to cd42382 Compare May 10, 2024 12:53
@a74nh a74nh marked this pull request as ready for review May 10, 2024 13:08
@a74nh
Copy link
Contributor Author

a74nh commented May 10, 2024

@kunalspathak @tannergooding @dotnet/arm64-contrib This is ready. A perquisite for SaturatingIncrementBy*ElementCount

@kunalspathak kunalspathak added the arm-sve Work related to arm64 SVE/SVE2 support label May 10, 2024
@@ -221,7 +355,7 @@ bool HWIntrinsicInfo::isScalarIsa(CORINFO_InstructionSet isa)
// pImmUpperBound [OUT] - The upper incl. bound for a value of the intrinsic immediate operand
//
void HWIntrinsicInfo::lookupImmBounds(
NamedIntrinsic intrinsic, int simdSize, var_types baseType, int* pImmLowerBound, int* pImmUpperBound)
NamedIntrinsic intrinsic, int simdSize, var_types baseType, int immNumber, int* pImmLowerBound, int* pImmUpperBound)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this method taking immNumber? It doesn't look like its being used anywhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because we don't yet have any intrinsics with two immediates. Next PR will add:

            case NI_Sve_SaturatingDecrementBy16BitElementCount:
            case NI_Sve_SaturatingDecrementBy32BitElementCount:
..etc...
            case NI_Sve_SaturatingIncrementBy64BitElementCountVector:
            case NI_Sve_SaturatingIncrementBy8BitElementCountVector:
                if (immNumber == 1)
                {
                    immLowerBound = 1;
                    immUpperBound = 16;
                }
                else
                {
                    assert(immNumber == 2);
                    immLowerBound = (int)SVE_PATTERN_POW2;
                    immUpperBound = (int)SVE_PATTERN_ALL;
                }
                break;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding the comment about the new argument in method docs. ok to do it in follow-up PR when you add cases to handle NI_Sve_SaturatingDecrementBy*

*immSimdBaseType = JitType2PreciseVarType(otherBaseJitType);
assert(otherBaseJitType == simdBaseJitType);
}
// For imm1 use default simd sizes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be asserting here instead? It seems like there's a presumption about the value of immSimdBaseType and that the caller essentially shouldn't call this function for immNumber == 1 for InsertSelectedScalar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code isn't clear here.

The immSimdSize and immSimdBaseType passed in are the default size and type for the intrinsic. The function can then choose to override them (as it does for HW_Category_SIMDByIndexedElement and imm2 of InsertSelectedScalar). For all other intrinsics (including imm1 of InsertSelectedScalar) it does nothing so that the default size and type can be used.

Updated the block comment so that it's clearer.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, minus a couple small nits

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except nit comments.

src/coreclr/jit/hwintrinsiccodegenarm64.cpp Show resolved Hide resolved
@@ -221,7 +355,7 @@ bool HWIntrinsicInfo::isScalarIsa(CORINFO_InstructionSet isa)
// pImmUpperBound [OUT] - The upper incl. bound for a value of the intrinsic immediate operand
//
void HWIntrinsicInfo::lookupImmBounds(
NamedIntrinsic intrinsic, int simdSize, var_types baseType, int* pImmLowerBound, int* pImmUpperBound)
NamedIntrinsic intrinsic, int simdSize, var_types baseType, int immNumber, int* pImmLowerBound, int* pImmUpperBound)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding the comment about the new argument in method docs. ok to do it in follow-up PR when you add cases to handle NI_Sve_SaturatingDecrementBy*

src/coreclr/jit/hwintrinsicxarch.cpp Show resolved Hide resolved
src/coreclr/jit/hwintrinsicxarch.cpp Outdated Show resolved Hide resolved
src/coreclr/jit/hwintrinsic.cpp Show resolved Hide resolved
@kunalspathak
Copy link
Member

/azp run runtime-coreclr superpmi-replay, runtime-coreclr superpmi-diffs

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kunalspathak kunalspathak merged commit 786b288 into dotnet:main May 13, 2024
110 of 114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI arm-sve Work related to arm64 SVE/SVE2 support community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants