Uh oh!
There was an error while loading. Please reload this page.
Refactor the various System.Numerics Vector/Matrix/Quaternion/Plane types to require less inlining - #130274
Conversation
…ypes to require less inlining
Tagging subscribers to this area: @dotnet/area-system-numerics |
There was a problem hiding this comment.
Pull request overview
This PR refactors several System.Numerics vector/matrix/quaternion/plane implementations to rely less on multi-layer wrapper inlining by routing more operations directly through Vector128<T> helpers and by moving some previously “Impl-file” logic inline.
Changes:
- Adds
Vector128<float>-level helpers (e.g.,Distance,Length,Normalize) and updatesVector2/3/4APIs to call them directly. - Refactors
Vector2/3/4,Quaternion, andPlaneoperations to useVector128<T>plumbing more consistently (and adds/adjusts inlining attributes). - Removes
Matrix3x2.Impl.cs/Matrix4x4.Impl.csfrom compilation inputs, moving needed implementation into the primary source files.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.Numerics.cs | Adds internal Vector128<float> Numerics helpers (distance/length/normalize). |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs | Refactors many ops to Vector128; changes span create/copy and ToString implementation. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.Extensions.cs | Adjusts Vector3 pointer store and AsVector2 path; simplifies unaligned stores. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs | Refactors ops to Vector128; adds internal helpers; updates ToString implementation. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.Extensions.cs | Adjusts Vector2 pointer store paths and unaligned stores. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs | Refactors ops to Vector128; adds internal transform helpers; updates ToString implementation. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs | Refactors quaternion ops to Vector128 and adds internal helpers/overloads. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs | Refactors plane ops to Vector128 and updates transform/normalize logic. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.Impl.cs | Removes the standalone Impl file (implementation expected elsewhere). |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.Impl.cs | Removes the standalone Impl file (implementation moved into Matrix3x2.cs). |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.cs | Moves/rewrites Impl logic inline; refactors operators and helpers. |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Stops compiling removed Impl files; minor formatting normalization. |
Copilot's findings
- Files reviewed: 12/13 changed files
- Comments generated: 7
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MichalPetryka
commented
Jul 7, 2026
@MihuBot -nuget |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs:430
- Quaternion.Slerp changed the sign check from
cosOmega < 0.0ftofloat.IsNegative(cosOmega). Those are not equivalent:IsNegativetreats -0 as negative and can treat NaN with the sign bit set as negative, which changes the branch behavior and can flip the sign of the returned quaternion components. If the intent is to preserve previous comparison semantics, use the original< 0.0fcheck.
float sign = 1.0f;
if (float.IsNegative(cosOmega))
{
cosOmega = -cosOmega;
sign = -1.0f;
}
- Files reviewed: 12/13 changed files
- Comments generated: 3
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs:430
- Quaternion.Slerp changed from
cosOmega < 0.0ftofloat.IsNegative(cosOmega), which changes the branching behavior for -0.0 (and for some NaN sign-bit cases). If this semantic change is intentional, it should be covered by a targeted regression test (e.g., construct quaternions that yield cosOmega == -0.0f and verify the expected interpolation result) so the behavior is locked in.
float cosOmega = Dot(quaternion1, quaternion2);
float sign = 1.0f;
if (float.IsNegative(cosOmega))
{
cosOmega = -cosOmega;
sign = -1.0f;
}
- Files reviewed: 12/13 changed files
- Comments generated: 1
Uh oh!
There was an error while loading. Please reload this page.
…ypes to require less inlining (#130274) The existing code was heavily reliant on often 3-4 layers of inlining per call and was inlining some larger functions which didn't need to be inlined while missing some smaller functions that were just above the "always inline" threshold. This refactors the code to be less reliant on the inliner, by ensuring the core functions are doing direct handling where applicable. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The existing code was heavily reliant on often 3-4 layers of inlining per call and was inlining some larger functions which didn't need to be inlined while missing some smaller functions that were just above the "always inline" threshold.
This refactors the code to be less reliant on the inliner, by ensuring the core functions are doing direct handling where applicable.