feat(simd): x86_64 baseline of SSE4.2, architecture-aware USE_SIMD - #5411
Open
lgritz wants to merge 1 commit into
Open
feat(simd): x86_64 baseline of SSE4.2, architecture-aware USE_SIMD#5411lgritz wants to merge 1 commit into
lgritz wants to merge 1 commit into
Conversation
USE_SIMD defaulted to empty, so we inherited whatever the compiler chose:
SSE2 for gcc/clang on Linux, penryn (SSE4.1, no 4.2) for Apple clang, and
plain SSE2 for MSVC, which never predefines the __SSE*__ macros that simd.h
keys off and which no Windows CI job overrides. Every x86-64 CPU has had
SSE4.2 since 2008, so we were leaving the 32 OIIO_SIMD_SSE >= 4 fast paths on
the floor for no reason.
Default USE_SIMD to sse4.2 when targeting x86_64, and leave it empty
elsewhere -- NEON is architecturally mandatory on ARMv8-A, so aarch64 needs
no help. USE_SIMD=0 still disables everything.
The block also had no notion of the target architecture at all: -m${feature}
was a blind passthrough, so USE_SIMD=avx2,f16c on ARM emitted -mavx2 and
failed to compile, which is why every ARM CI job leaves USE_SIMD unset. Now
tokens are classified, tokens for the wrong CPU family are skipped with a
status message, ARM tokens (neon, armv8.2-a+fp16, apple-m1, mcpu=...) are
understood, and universal Apple builds qualify the x86 flags with
-Xarch_x86_64 rather than handing -msse4.2 to the arm64 slice.
For MSVC on x64, emit the SSE4 defines unconditionally rather than only when
the user names those tokens, and let simd.h reach the same conclusion on its
own so that downstream users of the installed header benefit too. This is
safe because MSVC exposes every intrinsic through AVX2 regardless of /arch:.
gcc and clang do gate intrinsics on -m flags, so the header cannot do the
same for them; that limitation is now documented in simd.h and INSTALL.md.
Assisted-by: Claude Code / claude-opus-5
Signed-off-by: Larry Gritz <lg@larrygritz.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
USE_SIMD defaulted to empty, so we inherited whatever the compiler chose: SSE2 for gcc/clang on Linux, penryn (SSE4.1, no 4.2) for Apple clang, and plain SSE2 for MSVC, which never predefines the SSE* macros that simd.h keys off and which no Windows CI job overrides. Every x86-64 CPU has had SSE4.2 since 2008, so we were leaving the 32 OIIO_SIMD_SSE >= 4 fast paths on the floor for no reason.
Default USE_SIMD to sse4.2 when targeting x86_64, and leave it empty elsewhere -- NEON is architecturally mandatory on ARMv8-A, so aarch64 needs no help. USE_SIMD=0 still disables everything.
The block also had no notion of the target architecture at all: -m${feature} was a blind passthrough, so USE_SIMD=avx2,f16c on ARM emitted -mavx2 and failed to compile, which is why every ARM CI job leaves USE_SIMD unset. Now tokens are classified, tokens for the wrong CPU family are skipped with a status message, ARM tokens (neon, armv8.2-a+fp16, apple-m1, mcpu=...) are understood, and universal Apple builds qualify the x86 flags with -Xarch_x86_64 rather than handing -msse4.2 to the arm64 slice.
For MSVC on x64, emit the SSE4 defines unconditionally rather than only when the user names those tokens, and let simd.h reach the same conclusion on its own so that downstream users of the installed header benefit too. This is safe because MSVC exposes every intrinsic through AVX2 regardless of /arch:. gcc and clang do gate intrinsics on -m flags, so the header cannot do the same for them; that limitation is now documented in simd.h and INSTALL.md.
Assisted-by: Claude Code / claude-opus-5