Skip to content

Vector algorithms: Add compile time checks for ISA features - #6098

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
matbech:patch-1
Feb 28, 2026
Merged

Vector algorithms: Add compile time checks for ISA features#6098
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
matbech:patch-1

Conversation

@matbech

Copy link
Copy Markdown
Contributor

When the STL is compiled with /arch:SSE4.2 or /arch:AVX2, the runtime checks for the respective ISA features (SSE42, AVX2) are unnecessary. This change adds a compile time check using __check_arch_support to avoid the runtime cost.

When the STL is compiled with /arch:SSE4.2 or /arch:AVX2, the runtime checks for the respective ISA features (SSE42, AVX2) are unnecessary. This change adds a compile time check using __check_arch_support to avoid the runtime cost.
@AlexGuteniev

Copy link
Copy Markdown
Contributor

But what is the purpose?

For end users, the STL comes precompiled, so /arch flag passed by users, only affects public headers, but not separately compiled code. And when it is compiled for shipping it is always the same /arch option, which is SSE2 for x86, and baseline for x64.

@matbech

Copy link
Copy Markdown
Contributor Author

For custom built binaries (msvcp140_oss.dll) with modern /arch compiler flags where performance is important.

@StephanTLavavej

Copy link
Copy Markdown
Member

For reference, __check_arch_support:

The __check_arch_support intrinsic can always be evaluated at compile time, so using it in optimized code adds no extra instructions to execute. Support for these intrinsics was added in Visual Studio 2022 version 17.10.

Comment thread stl/src/vector_algorithms.cpp Outdated
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Feb 25, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Feb 26, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit f25bfb5 into microsoft:main Feb 28, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Feb 28, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

🎉 🚀 🦖

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

Labels

performance Must go faster

3 participants