AVX2: Improve SIMD portability by replacing non‑portable indexing and casts - #1475
Open
StormBytePP wants to merge 3 commits into
Open
StormBytePP wants to merge 3 commits into
StormBytePP wants to merge 3 commits into
Conversation
StormBytePP
added a commit
to StormBytePP/vmaf
that referenced
this pull request
Mar 25, 2026
10 tasks
StormBytePP
force-pushed
the
avx_portability
branch
2 times, most recently
from
August 9, 2026 03:32
c6c98c4 to
ef0e2bd
Compare
Contributor
Author
|
Update: Rebased and fixed i686 intrinsics. It is working again. |
StormBytePP
added a commit
to StormBytePP/vmaf
that referenced
this pull request
Aug 9, 2026
Signed-off-by: David C. Manuelda <StormByte@gmail.com>
Signed-off-by: David C. Manuelda <StormByte@gmail.com>
Replace non-portable __m128i lane indexing (v[0]+v[1]) with mm_hadd_epi64(): extract on x86-64, store on 32-bit. Signed-off-by: David C. Manuelda <StormByte@gmail.com>
Signed-off-by: David C. Manuelda <StormByte@gmail.com>
StormBytePP
force-pushed
the
avx_portability
branch
from
August 13, 2026 22:56
ef0e2bd to
ecd8420
Compare
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.
This PR improves the portability of the AVX2 (and AVX-512) implementation by removing two GCC/Clang-specific behaviors that are not supported by other compilers:
Non-portable SIMD vector indexing
Direct indexing of
__m128i(e.g.v[0] + v[1]) is a compiler extension and is not part of the standard Intel intrinsic API.It is replaced with a small helper,
mm_hadd_epi64():_mm_extract_epi64(SSE4.1) — cheap, no stack spill_mm_storeu_si128into a 2-lane array, then sumThat covers toolchains on both 32-bit and 64-bit targets without relying on vector subscripting (specially MSVC and possibly others).
Non-standard casts between SIMD types (
__m256→__m256i)Some compilers allow a direct cast between float and integer vector types; that is not universal.
Those casts are replaced with
_mm256_castps_si256, a zero-cost bit reinterpretation defined by the intrinsic API.These changes do not alter the algorithm or performance characteristics on x86-64.
They make the AVX2/AVX-512 backend consistent across toolchains and usable on pure x86 as well.