Skip to content

[mono] Handle nint/nuint in Crc32 and ArmBase intrinsic dispatch#127787

Open
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:fix/mono-aot-crc32-nuint
Open

[mono] Handle nint/nuint in Crc32 and ArmBase intrinsic dispatch#127787
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:fix/mono-aot-crc32-nuint

Conversation

@kotlarmilos
Copy link
Copy Markdown
Member

Description

The Mono SIMD intrinsic dispatch in simd-intrinsics.c did not match MONO_TYPE_I/U, so the new nint/nuint overloads added by #127327 (Crc32.ComputeCrc32(uint, nuint), Crc32.ComputeCrc32C(uint, nuint), ArmBase.ReverseElementBits(nint/nuint)) tripped g_assert_not_reached() at line 4981 during AOT of System.Private.CoreLib.dll on tvos-arm64 (build 1406826).

This unblocks AOT precompilation of System.Private.CoreLib.dll on 64-bit ARM Mono targets and recovers four tvos appletv work items (System.Configuration.ConfigurationManager.Tests, System.Reflection.MetadataLoadContext.Tests, System.Security.Cryptography.Xml.Tests, System.Text.Json.Tests) that previously exited 21 before any test ran.

PR dotnet#127327 added new nint/nuint overloads for System.Runtime.Intrinsics.Arm
(Crc32.ComputeCrc32(uint, nuint), ComputeCrc32C(uint, nuint), and
ArmBase.ReverseElementBits(nint/nuint)). The Mono SIMD intrinsic dispatch
in src/mono/mono/mini/simd-intrinsics.c only matched MONO_TYPE_U1/U2/U4/U8
and tripped g_assert_not_reached at line 4981 during AOT compilation of
System.Private.CoreLib.dll on tvos-arm64 (and any 64-bit ARM AOT target).

Changes:
- MONO_CPU_ARM64_CRC switch now maps MONO_TYPE_I/U to U4 or U8 by pointer
  size and selects OP_XOP_I4_I4_I4 vs OP_XOP_I4_I4_I8 based on the actual
  data type rather than the enclosing-class is_64bit flag (since the new
  Crc32.ComputeCrc32(uint, nuint) overload lives on Crc32, not Crc32.Arm64).
- ArmBase.ReverseElementBits now keys op selection off arg0_i32 so the new
  ArmBase.ReverseElementBits(nuint) overload picks the correct 32/64-bit
  intrinsic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@kotlarmilos kotlarmilos added this to the 11.0.0 milestone May 5, 2026
@kotlarmilos kotlarmilos requested a review from tannergooding May 5, 2026 10:52
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 fixes Mono ARM64 intrinsic dispatch for newly-added nint/nuint overloads by selecting the instruction/opcode based on the actual argument type (and pointer size), instead of relying on whether the method is in a nested *.Arm64 class. This prevents g_assert_not_reached() during AOT when compiling methods like Crc32.ComputeCrc32(uint, nuint) and ArmBase.ReverseElementBits(nint/nuint).

Changes:

  • Update ArmBase.ReverseElementBits dispatch to choose 32-bit vs 64-bit lowering based on the argument’s underlying type.
  • Update Crc32.ComputeCrc32/ComputeCrc32C dispatch to recognize MONO_TYPE_I/U and select CRC32W vs CRC32X lowering based on pointer size / operand width.
Show a summary per file
File Description
src/mono/mono/mini/simd-intrinsics.c Fixes ARM64 intrinsic opcode selection for nint/nuint signatures to avoid AOT-time asserts and ensure correct 32/64-bit instruction choice.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Copy link
Copy Markdown
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.

Sorry that I missed this!

Had taken a glance and it had looked like it was generally supported since we already handled Vector128<nint> for the xplat APIs, missed that we had individual paths that needed to check for TYPE_I/U as well

@kotlarmilos
Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants