From 8aadb13160ec0599291b0add9260bde721375640 Mon Sep 17 00:00:00 2001 From: Vladimir Saraikin Date: Tue, 7 Jul 2026 23:31:44 +0200 Subject: [PATCH 1/2] fix(neon): under-aligned store in generic swizzle kernel --- include/xsimd/arch/xsimd_neon.hpp | 4 +++- test/test_batch_manip.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/xsimd/arch/xsimd_neon.hpp b/include/xsimd/arch/xsimd_neon.hpp index 8ea2756f7..48be9b88e 100644 --- a/include/xsimd/arch/xsimd_neon.hpp +++ b/include/xsimd/arch/xsimd_neon.hpp @@ -3308,7 +3308,9 @@ namespace xsimd requires_arch) noexcept { static_assert(batch::size == sizeof...(idx), "valid swizzle indices"); - std::array::size> data; + // std::array is only aligned to alignof(T), while store_aligned requires + // the full batch alignment + alignas(A::alignment()) std::array::size> data; self.store_aligned(data.data()); return set(batch(), A(), data[idx]...); } diff --git a/test/test_batch_manip.cpp b/test/test_batch_manip.cpp index 93d0e2a46..c864ae5f7 100644 --- a/test/test_batch_manip.cpp +++ b/test/test_batch_manip.cpp @@ -330,6 +330,24 @@ TEST_CASE_TEMPLATE("[swizzle]", B, BATCH_SWIZZLE_TYPES) SUBCASE("rotate_right") { swizzle_test().rotate_right(); } } +#if XSIMD_WITH_NEON +// Regression test for https://github.com/xtensor-stack/xsimd/issues/1260: the generic +// neon swizzle kernel stored to an std::array aligned only to alignof(T), tripping the +// alignment assertion in store_aligned for the 8- and 16-bit batches that use it +TEST_CASE_TEMPLATE("[swizzle generic neon kernel]", B, xsimd::batch, xsimd::batch, xsimd::batch, xsimd::batch) +{ + XSIMD_SWIZZLE_PATTERN_CASE(Reversor); + XSIMD_SWIZZLE_PATTERN_CASE(EvenThenOdd); + XSIMD_SWIZZLE_PATTERN_CASE(RotateRight1); + SUBCASE("reduce_max") + { + auto lhs = swizzle_test::make_lhs(); + auto b = B::load_unaligned(lhs.data()); + CHECK_EQ(xsimd::reduce_max(b), lhs[B::size - 1]); + } +} +#endif + #undef XSIMD_SWIZZLE_PATTERN_CASE #endif /* XSIMD_NO_SUPPORTED_ARCHITECTURE */ From 933a762cee7359c072fe7dd7cd289e377828c152 Mon Sep 17 00:00:00 2001 From: Vladimir Saraikin Date: Wed, 8 Jul 2026 12:02:43 +0200 Subject: [PATCH 2/2] test: run narrow swizzle/reduce_max on every supported architecture --- test/test_batch_manip.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/test/test_batch_manip.cpp b/test/test_batch_manip.cpp index c864ae5f7..8fdc3cfd2 100644 --- a/test/test_batch_manip.cpp +++ b/test/test_batch_manip.cpp @@ -330,23 +330,43 @@ TEST_CASE_TEMPLATE("[swizzle]", B, BATCH_SWIZZLE_TYPES) SUBCASE("rotate_right") { swizzle_test().rotate_right(); } } -#if XSIMD_WITH_NEON // Regression test for https://github.com/xtensor-stack/xsimd/issues/1260: the generic -// neon swizzle kernel stored to an std::array aligned only to alignof(T), tripping the -// alignment assertion in store_aligned for the 8- and 16-bit batches that use it -TEST_CASE_TEMPLATE("[swizzle generic neon kernel]", B, xsimd::batch, xsimd::batch, xsimd::batch, xsimd::batch) +// swizzle kernel stored to an std::array aligned only to alignof(T), tripping the +// alignment assertion in store_aligned for the 8- and 16-bit batches that use it. +// Run on every supported architecture, not just the default one, so the generic +// kernels of the narrower archs are exercised too +struct check_narrow_swizzle_and_reduce { - XSIMD_SWIZZLE_PATTERN_CASE(Reversor); - XSIMD_SWIZZLE_PATTERN_CASE(EvenThenOdd); - XSIMD_SWIZZLE_PATTERN_CASE(RotateRight1); - SUBCASE("reduce_max") + template + void operator()(Arch) const { + if (!Arch::available()) + { + return; + } + check_for(); + check_for(); + check_for(); + check_for(); + } + + template + void check_for() const + { + using B = xsimd::batch; + swizzle_test().template run(); + swizzle_test().template run(); + swizzle_test().template run(); auto lhs = swizzle_test::make_lhs(); auto b = B::load_unaligned(lhs.data()); CHECK_EQ(xsimd::reduce_max(b), lhs[B::size - 1]); } +}; + +TEST_CASE("[narrow swizzle and reduce_max on every supported architecture]") +{ + xsimd::supported_architectures::for_each(check_narrow_swizzle_and_reduce {}); } -#endif #undef XSIMD_SWIZZLE_PATTERN_CASE