Skip to content

Cleanup some of the intrinsic fallback implementations to make it easier to add support for new types#128454

Merged
tannergooding merged 6 commits into
dotnet:mainfrom
tannergooding:vector-shuffle
May 22, 2026
Merged

Cleanup some of the intrinsic fallback implementations to make it easier to add support for new types#128454
tannergooding merged 6 commits into
dotnet:mainfrom
tannergooding:vector-shuffle

Conversation

@tannergooding

@tannergooding tannergooding commented May 21, 2026

Copy link
Copy Markdown
Member

This adds a couple helpers to the internal Scalar<T> type making it easier to centralize type classification and simplifies various implementations to use those, making it easier to add new types (char and Half) in the future.

It also simplifies the Shuffle/ShuffleNative implementation to go through a single centralized internal method, ensuring we don't have a bunch of complex logic unnecessarily duplicated and that all types are properly supported. This last part means that it adds the missing nint/nuint shuffle overloads which were approved as part of the general expansion to support those types. The two proposals (shuffle and nint/nuint) went up at similar times and we had done a blanket approval for the latter (across 3 proposals), so it was just missed.

The ref assembly sources had also been manually updated on a number of occasions, so this regenerates them (which also alphabetized some of the entries).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors several SIMD intrinsic fallback implementations to centralize scalar type classification (via Scalar<T>) and to de-duplicate Shuffle / ShuffleNative fallback logic across the Vector64/128/256/512 and Vector<T> APIs. It also regenerates the System.Numerics.Vectors ref source.

Changes:

  • Introduce Scalar<T>.IsSupported, IsUnsigned, and IsFloatingPoint helpers and update multiple intrinsic fallbacks to use them.
  • Consolidate Shuffle / ShuffleNative fallback implementations via shared generic helpers (per vector width) to reduce duplicated per-type code.
  • Regenerate System.Numerics.Vectors ref sources (mostly formatting/alphabetization).

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Scalar.cs Adds centralized scalar type classification helpers and simplifies some scalar ops to reuse existing helpers.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs Uses Scalar<T> helpers for classification and centralizes Shuffle / ShuffleNative fallback logic.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs Switches IsSupported to Scalar<T>.IsSupported.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs Uses Scalar<T> helpers and consolidates Shuffle / ShuffleNative logic through shared helpers.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs Switches IsSupported to Scalar<T>.IsSupported.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs Uses Scalar<T> helpers and centralizes Shuffle / ShuffleNative fallback logic.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs Switches IsSupported to Scalar<T>.IsSupported.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs Uses Scalar<T> helpers and centralizes Shuffle / ShuffleNative fallback logic.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512_1.cs Switches IsSupported to Scalar<T>.IsSupported.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/ISimdVector_2.cs Removes an unused CodeAnalysis using.
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/SimdVectorExtensions.cs Removes unused usings.
src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs Replaces repeated typeof(T) classification checks with Scalar<T> helpers in multiple ops.
src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs Switches IsSupported to Scalar<T>.IsSupported.
src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs Regenerated ref source (primarily type name formatting / ordering).

Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs Outdated
Comment thread src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs
@tannergooding tannergooding enabled auto-merge (squash) May 21, 2026 19:18
Copilot AI review requested due to automatic review settings May 21, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs Outdated
Copilot AI review requested due to automatic review settings May 21, 2026 21:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs Outdated
Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs Outdated
Copilot AI review requested due to automatic review settings May 21, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs Outdated
Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tannergooding

Copy link
Copy Markdown
Member Author

Sometimes copilot suggestions are a space off and it just tries to correct itself after the fact -.-

Ended up fixing the indentation manually to be correct.

Copilot AI review requested due to automatic review settings May 22, 2026 03:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Copilot AI review requested due to automatic review settings May 22, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

@tannergooding tannergooding enabled auto-merge (squash) May 22, 2026 06:27
@tannergooding

Copy link
Copy Markdown
Member Author

Figured out the mono interpreter failure. Will do a follow up PR to resolve the problem so that IsSupported can still be centralized, have undone that part of the change for getting the bigger simplification in.

@tannergooding tannergooding merged commit d2161b7 into dotnet:main May 22, 2026
154 checks passed
@tannergooding tannergooding deleted the vector-shuffle branch May 22, 2026 14:48
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 23, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants