Skip to content

Add an explicit SSE2 path for batch_bool_constant masks where the three#1372

Merged
serge-sans-paille merged 1 commit into
xtensor-stack:masterfrom
DiamonDinoia:sse2-masked-load-3of4
Jul 7, 2026
Merged

Add an explicit SSE2 path for batch_bool_constant masks where the three#1372
serge-sans-paille merged 1 commit into
xtensor-stack:masterfrom
DiamonDinoia:sse2-masked-load-3of4

Conversation

@DiamonDinoia

Copy link
Copy Markdown
Contributor

Add an explicit SSE2 path for batch_bool_constant masks where the three
low lanes are active and lane 3 is zero ({T,T,T,F} = countr_one()==3).

load_masked: movsd (lanes 0,1) + movss (lane 2) + shufps into
[lo0, lo1, ss0, 0].
store_masked: storel_pi (lanes 0,1) + movehl+store_ss (lane 2).

Without this both paths fell through to the common-arch scalar-buffer
fallback (zero-init std::array + element-wise scatter + aligned reload) (when compiler optimization was < -O3)

@DiamonDinoia DiamonDinoia requested a review from AntoinePrv July 6, 2026 20:34
@DiamonDinoia DiamonDinoia mentioned this pull request Jul 6, 2026
6 tasks
Comment thread include/xsimd/arch/xsimd_sse2.hpp Outdated
}
else XSIMD_IF_CONSTEXPR(mask.countr_one() == 3)
{
__m128 const lo2 = _mm_loadl_pi(_mm_setzero_ps(), reinterpret_cast<__m64 const*>(mem));

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.

looks like _mm_loadl_epi64 would be slightly better.

low lanes are active and lane 3 is zero ({T,T,T,F} = countr_one()==3).

load_masked<float>:  movsd (lanes 0,1) + movss (lane 2) + shufps into
                     [lo0, lo1, ss0, 0].
store_masked<float>: storel_pi (lanes 0,1) + movehl+store_ss (lane 2).

Without this both paths fell through to the common-arch scalar-buffer
fallback (zero-init std::array + element-wise scatter + aligned reload),
@DiamonDinoia DiamonDinoia force-pushed the sse2-masked-load-3of4 branch from e220b07 to 099b5a7 Compare July 6, 2026 21:15
@DiamonDinoia

DiamonDinoia commented Jul 6, 2026 via email

Copy link
Copy Markdown
Contributor Author

@serge-sans-paille serge-sans-paille merged commit 92ca962 into xtensor-stack:master Jul 7, 2026
89 checks passed
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.

2 participants