Skip to content

minmax / minmax_element: avoid synthesizing _Min / _Max in traits - #6472

Open
Alex Guteniev (AlexGuteniev) wants to merge 5 commits into
microsoft:mainfrom
AlexGuteniev:more-minmax-clarity
Open

Alex Guteniev (AlexGuteniev) wants to merge 5 commits into
microsoft:mainfrom
AlexGuteniev:more-minmax-clarity

Conversation

@AlexGuteniev

Copy link
Copy Markdown
Contributor

Follow up to #6459

SSE4.2, AVX2, and Neon all lack 64-bit min/max instructions. We have to use blending instead with comparison result in minmax_element, and produce such a result in minmax.

Instead of synthesizing _Min and _Max in traits, let's do this in a lambda directly in the implementation. The traits now have _Has_min_max bool constant, and only have _Min and _Max if there are instructions. The traits don't need overloads or default parameters to have 3-arg _Min and _Max. The trick of using blending is now transparent,

There isn't significant code reduction, it is mostly for clarity.
And also anticipation of future AVX-512, which does have 64-bit min/max instructions.

Hari Limaye (@hazzlim) please check if I didn't regress Neon.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:00
@AlexGuteniev
Alex Guteniev (AlexGuteniev) requested a review from a team as a code owner October 1, 2026 16:00
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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

🔵 Needs a closer look

Cross-architecture SIMD behavior, particularly Neon, requires platform-specific compilation and testing.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors vectorized minmax and minmax_element to synthesize 64-bit min/max operations at call sites when SIMD instructions are unavailable.

Changes:

  • Adds _Has_min_max capability flags to SIMD traits.
  • Replaces synthesized 64-bit trait operations with comparison-and-blend wrappers.
  • Simplifies native min/max trait signatures.
File Description
stl/​src/​vector_algorithms.cpp Refactors SIMD min/max traits and implementations across SSE, AVX2, and Neon.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the enhancement Something can be improved label Oct 1, 2026
Copilot AI balanced review requested due to automatic review settings October 3, 2026 05:52

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

The refactor preserves comparison direction, unsigned ordering, blending, and reduction behavior, with no unresolved findings.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings October 3, 2026 06: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.

Copilot review overview

🔵 Needs a closer look

The cross-architecture SIMD refactor merits target-specific human validation, particularly for Neon.

Review effort: Balanced
Findings: None

This branch has not been deployed

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

Labels

enhancement Something can be improved

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

3 participants