Skip to content

Extend System.Runtime.Intrinsics.Arm to support nint and nuint (ArmBase + Crc32)#127327

Open
Copilot wants to merge 3 commits intomainfrom
copilot/extend-arm-intrinsics-support-nint-nuint
Open

Extend System.Runtime.Intrinsics.Arm to support nint and nuint (ArmBase + Crc32)#127327
Copilot wants to merge 3 commits intomainfrom
copilot/extend-arm-intrinsics-support-nint-nuint

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

Implements the approved API proposal to extend System.Runtime.Intrinsics.Arm with nint/nuint overloads. Per reviewer guidance, this PR is scoped down to Option C: the ArmBase + Crc32 managed surface plus the GenTreeHWIntrinsic auxiliary-type refactor. The bulk of the proposal (AdvSimd + AdvSimd.Arm64) is deferred to follow-up PRs.

Description

Managed surface (implementation, PlatformNotSupported mirror, and ref assembly)

  • ArmBase
    • LeadingZeroCount(nint), LeadingZeroCount(nuint)
    • ReverseElementBits(nint), ReverseElementBits(nuint)
  • ArmBase.Arm64
    • LeadingSignCount(nint)
  • Crc32
    • ComputeCrc32(uint crc, nuint data)
    • ComputeCrc32C(uint crc, nuint data)

No APIs are added beyond the approved proposal. The managed bodies are simple self-call intrinsic stubs; the JIT handles dispatch via the hwintrinsic list (see below).

JIT hwintrinsic list — 64-bit instruction slots for the 32-bit classes

In src/coreclr/jit/hwintrinsiclistarm64.h, the TYP_LONG/TYP_ULONG slots of the 32-bit-class entries are now populated so that nint/nuint overloads (which JitType2PreciseVarType maps to TYP_LONG/TYP_ULONG on 64-bit) dispatch to the correct Arm64 instruction without needing a managed-side redirect to *.Arm64.*:

  • NI_ArmBase_LeadingZeroCount — added INS_clz for TYP_LONG/TYP_ULONG
  • NI_ArmBase_ReverseElementBits — added INS_rbit for TYP_LONG/TYP_ULONG
  • NI_Crc32_ComputeCrc32 — added INS_crc32x for TYP_ULONG
  • NI_Crc32_ComputeCrc32C — added INS_crc32cx for TYP_ULONG

Codegen uses emitActualTypeSize(intrin.baseType) for HW_Category_Scalar, so the 8-byte operand size flows through automatically. On Arm32, nint/nuint is 32-bit and these TYP_LONG/TYP_ULONG slots are never reached.

JIT refactor — GenTreeHWIntrinsic auxiliary type

Switched the tracked auxiliary type from CorInfoType to var_types:

  • gtAuxiliaryJitTypegtAuxiliaryType, default changed from CORINFO_TYPE_UNDEF to TYP_UNKNOWN.
  • GetAuxiliaryJitType() / SetAuxiliaryJitType(CorInfoType) removed. GetAuxiliaryType() now returns the stored var_types directly; new SetAuxiliaryType(var_types) added.
  • All ~18 call sites migrated across hwintrinsic.cpp, hwintrinsicarm64.cpp, hwintrinsicxarch.cpp, gentree.cpp, and valuenum.cpp. Sentinels CORINFO_TYPE_PTR / CORINFO_TYPE_UNDEF are translated at the boundary to TYP_U_IMPL / TYP_UNKNOWN.
  • The now-dead getBaseJitTypeAndSizeOfSIMDType / getBaseJitTypeOfSIMDType helpers are removed from compiler.h and simd.cpp; callers use the existing var_types-returning getBaseTypeAndSizeOfSIMDType / getBaseTypeOfSIMDType.

Tests

New generator inputs added in src/tests/Common/GenerateHWIntrinsicTests/Arm/BaseTests.cs for the nint / nuint overloads of LeadingZeroCount, LeadingSignCount, and ReverseElementBits, with bit-size-aware validation logic that is correct on both 32-bit and 64-bit.

Generator entries for the Crc32 nuint overloads are intentionally not added in this PR: their expected CRC output must be platform-conditional and precomputed per architecture, which the current ScalarBinOpTest template doesn't support cleanly. This can be added as a follow-up once a small cross-platform helper is introduced.

Scope deferred to follow-up PRs

  • AdvSimd and AdvSimd.Arm64 nint / nuint overloads (hundreds of methods in AdvSimd.cs / AdvSimd.PlatformNotSupported.cs).
  • Matching test-generator entries for AdvSimd overloads.
  • Crc32 nuint test-generator entries (see note above).

Testing

  • ./build.sh clr+libs -rc release0 errors, 0 warnings. JIT C++ refactor compiles clean on x64; the managed surface (including the ref assembly) compiles clean.
  • ./build.sh clr.alljits -c release — cross-compiles all JIT targets including libclrjit_universal_arm64_x64.so, exercising the updated hwintrinsiclistarm64.h. 0 errors, 0 warnings.
  • ⚠️ No on-device Arm64 test execution was performed in this sandbox — the generated tests will exercise the new APIs end-to-end once run in the Arm64 test pipeline.

Copilot AI review requested due to automatic review settings April 23, 2026 16:38
Copilot AI linked an issue Apr 23, 2026 that may be closed by this pull request
Copilot AI review requested due to automatic review settings April 23, 2026 16:38
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 23, 2026
Copilot AI changed the title [WIP] Extend System.Runtime.Intrinsics.Arm to support nint and nuint Extend System.Runtime.Intrinsics.Arm to support nint and nuint Apr 23, 2026
Copilot AI requested a review from tannergooding April 23, 2026 16:48
@tannergooding
Copy link
Copy Markdown
Member

@copilot please go with option C. But note that in the full task list that the JIT item is expected to be unnecessary as all APIs should already have correct entries in the intrinsic list.

… type to var_types

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/244a0b75-c1b0-46b3-b53e-23ed8cf7401a

Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 23, 2026 17:51
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot please go with option C. But note that in the full task list that the JIT item is expected to be unnecessary as all APIs should already have correct entries in the intrinsic...

Done in 6f34511 — landed the ArmBase + Crc32 managed surface and the GenTreeHWIntrinsic aux-type refactor (CorInfoTypevar_types, getBaseJitTypeAndSizeOfSIMDType/getBaseJitTypeOfSIMDType removed, callers migrated to the existing var_types-returning helpers). Skipped adding JIT intrinsic list entries as you noted. No new APIs beyond the approval. Baseline ./build.sh clr+libs -rc release is clean (0/0).

AdvSimd is deferred to follow-ups as agreed.

Copilot AI changed the title Extend System.Runtime.Intrinsics.Arm to support nint and nuint Extend System.Runtime.Intrinsics.Arm to support nint and nuint (ArmBase + Crc32) Apr 23, 2026
@tannergooding tannergooding marked this pull request as ready for review April 23, 2026 18:43
Copilot AI review requested due to automatic review settings April 23, 2026 18:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the approved System.Runtime.Intrinsics.Arm API expansion to add nint/nuint overloads for a small, scoped subset (ArmBase + Crc32), and refactors the JIT’s GenTreeHWIntrinsic “auxiliary type” tracking from CorInfoType to var_types to better match existing JIT type plumbing.

Changes:

  • Added nint/nuint overloads to ArmBase (LeadingZeroCount, ReverseElementBits) and ArmBase.Arm64 (LeadingSignCount), plus nuint overloads to Crc32 (ComputeCrc32, ComputeCrc32C).
  • Refactored GenTreeHWIntrinsic auxiliary type storage/accessors to use var_types, updating all impacted JIT call sites and removing now-dead CorInfoType SIMD base-type helpers.
  • Extended the ARM intrinsic test generator inputs to cover the new ArmBase nint/nuint overloads with pointer-size-aware validation.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/tests/Common/GenerateHWIntrinsicTests/Arm/BaseTests.cs Adds generator entries for ArmBase nint/nuint overload coverage.
src/libraries/System.Runtime.Intrinsics/ref/System.Runtime.Intrinsics.cs Updates ref assembly with the new nint/nuint overload signatures.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.cs Adds nint/nuint overloads to the supported implementation surface.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs Mirrors new ArmBase overloads for unsupported platforms.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/Crc32.cs Adds nuint overloads to Crc32 supported implementation surface.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Arm/Crc32.PlatformNotSupported.cs Mirrors new Crc32 overloads for unsupported platforms.
src/coreclr/jit/gentree.h Changes auxiliary type storage to var_types (gtAuxiliaryType) and updates accessors.
src/coreclr/jit/gentree.cpp Updates cloning/folding/memory-load logic to use var_types auxiliary type APIs.
src/coreclr/jit/hwintrinsic.cpp Migrates auxiliary type tracking to var_types and updates affected import paths.
src/coreclr/jit/hwintrinsicarm64.cpp Migrates auxiliary type tracking to var_types for Arm64 intrinsics import paths.
src/coreclr/jit/hwintrinsicxarch.cpp Migrates auxiliary type tracking to var_types for xarch intrinsic import paths.
src/coreclr/jit/valuenum.cpp Migrates auxiliary type checks to var_types for ARM64 constant folding/value numbering.
src/coreclr/jit/simd.cpp Removes the CorInfoType-returning SIMD base-type helper (now unused).
src/coreclr/jit/compiler.h Removes declarations for the deleted CorInfoType SIMD base-type helpers.

Comment thread src/coreclr/jit/gentree.h
… slots for nint/nuint dispatch

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/c2ab4e66-3233-4d8d-b691-668aa5db1675

Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
@tannergooding
Copy link
Copy Markdown
Member

CC. @dotnet/jit-contrib, @EgorBo, @kg for review. This exposes the nint and nuint overloads for some Arm intrinsicsi in the ArmBase and AdvSimd namespace. A follow up PR covering AdvSimd will also be done once this is completed and then same again for the xarch APIs.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend System.Runtime.Intrinsics.Arm to support nint and nuint

3 participants