-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Enable CA1516 Use Cross-Platform Intrinsics #120784
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
Conversation
There was a problem hiding this 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 enables the CA1516 analyzer rule ("Use cross-platform intrinsics") which encourages the use of cross-platform SIMD operator overloads instead of platform-specific intrinsic methods. The changes replace platform-specific intrinsic calls (like AdvSimd.ShiftRightArithmetic, Sse2.Or, Avx2.Add) with their equivalent C# operator overloads (like >>, |, +) that work across multiple platforms.
Key changes:
- Replaced arithmetic and bitwise intrinsic method calls with operator overloads throughout the codebase
- Enabled CA1516 as a warning in source code analysis configuration
- Disabled CA1516 in test code and intrinsics implementation folders where the rule shouldn't apply
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
eng/CodeAnalysis.src.globalconfig |
Enabled CA1516 as a warning for source code |
eng/CodeAnalysis.test.globalconfig |
Disabled CA1516 for test code |
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/.editorconfig |
Disabled CA1516 for intrinsics implementations |
src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs |
Replaced AdvSimd.ShiftRightArithmetic and AdvSimd.And with >> and & operators |
src/libraries/System.Private.CoreLib/src/System/Text/Latin1Utility.cs |
Replaced Sse2.Or with ` |
src/libraries/System.Private.CoreLib/src/System/Text/Ascii.Utility.cs |
Replaced AdvSimd.ShiftRightArithmetic and AdvSimd.And with >> and & operators |
src/libraries/System.Private.CoreLib/src/System/SearchValues/IndexOfAnyAsciiSearcher.cs |
Replaced AdvSimd.ShiftRightArithmetic with >> operator |
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64EncoderHelper.cs |
Replaced Avx2.And, Avx2.MultiplyLow, Avx2.Or, Avx2.Subtract, Avx2.Add, and AdvSimd.ShiftRightLogical with operators |
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs |
Replaced Avx2.And and Avx2.Add with & and + operators |
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.LeadingZeroCount.cs |
Replaced shift and bitwise intrinsics with operator overloads |
src/libraries/Common/src/System/HexConverter.cs |
Replaced AdvSimd.ShiftLeftLogical and PackedSimd.ShiftLeft with << operator |
|
Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see this picking up some cases and simplifying the implementation!
There's more scenarios we'll want to add to the analyzer over time, but this is a great first step!
|
@tannergooding, please also see dotnet/sdk#51299. I hit that while running the analyzer (it fails to show the description in the diagnostic as a result). |
No description provided.