Skip to content

Fix Vector2 and Vector3 comparison reductions - #133044

Open
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-vector-any-all-comparisons
Open

Fix Vector2 and Vector3 comparison reductions#133044
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-vector-any-all-comparisons

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Vector2 and Vector3 strict Any comparisons incorrectly returned true when no logical lanes matched because zero-filled padding lanes matched zero entries in the validity mask. Use the direct Vector128 comparison reductions, which the JIT expands to the canonical comparison forms, and simplify the inclusive All reductions similarly.

Add coverage for padding-sensitive outcomes and NaN in every valid lane.

Note

This pull request was created with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 20:46
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics
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.

Copilot review overview

🟢 Approval recommended

Review tier: Lite
Findings: None

What changed in this PR

This PR corrects Vector2/Vector3 strict GreaterThanAny/LessThanAny reductions to avoid false positives caused by comparing a full Vector128 result against a mask that includes zero padding lanes. It switches to the dedicated Vector128.*Any/*All reduction helpers and adds regression tests to ensure padding lanes and NaN behavior don’t corrupt results.

Changes:

  • Fix Vector2/Vector3 strict GreaterThanAny and LessThanAny to use Vector128.GreaterThanAny / Vector128.LessThanAny.
  • Simplify inclusive GreaterThanOrEqualAll / LessThanOrEqualAll to use Vector128.*All reductions directly.
  • Add/extend unit tests to cover padding-lane-sensitive false positives and NaN behavior for inclusive All.
File Description
src/​libraries/​System.Private.CoreLib/​src/​System/​Numerics/​Vector3.cs Uses Vector128.*Any/*All reduction helpers to avoid padding-lane false positives.
src/​libraries/​System.Private.CoreLib/​src/​System/​Numerics/​Vector2.cs Same reduction change for Vector2 comparisons.
src/​libraries/​System.Numerics.Vectors/​tests/​Vector3Tests.cs Adds regression coverage for strict Any and extends inclusive All tests with padding/NaN cases.
src/​libraries/​System.Numerics.Vectors/​tests/​Vector2Tests.cs Adds regression coverage for strict Any and extends inclusive All tests with padding/NaN cases.

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