Skip to content

AVX2: Improve SIMD portability by replacing non‑portable indexing and casts - #1475

Open
StormBytePP wants to merge 3 commits into
Netflix:masterfrom
StormBytePP:avx_portability
Open

StormBytePP wants to merge 3 commits into
Netflix:masterfrom
StormBytePP:avx_portability

Conversation

@StormBytePP

@StormBytePP StormBytePP commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

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:

  1. 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():

    • x86-64: _mm_extract_epi64 (SSE4.1) — cheap, no stack spill
    • i386: _mm_storeu_si128 into a 2-lane array, then sum

    That covers toolchains on both 32-bit and 64-bit targets without relying on vector subscripting (specially MSVC and possibly others).

  2. 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.

StormBytePP added a commit to StormBytePP/vmaf that referenced this pull request Mar 25, 2026
@StormBytePP
StormBytePP force-pushed the avx_portability branch 2 times, most recently from c6c98c4 to ef0e2bd Compare August 9, 2026 03:32
@StormBytePP

Copy link
Copy Markdown
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant