From 18eb965ed0453073978a888aefef3eeede728def Mon Sep 17 00:00:00 2001 From: Marco Barbone Date: Tue, 10 Nov 2026 13:14:00 -0500 Subject: [PATCH] Fix spurious double-register instantiation in emulated batch_bool value ctors The emulated set overloads named a template parameter A that no argument deduces. The explicit kernel::set calls could instantiate an unrelated emulated register type. The overloads drop A, and the callers let deduction pick the overload. Assisted-by: Qwen3.8-27B-FP8 --- include/xsimd/arch/xsimd_emulated.hpp | 5 +++-- include/xsimd/types/xsimd_batch.hpp | 11 ++++++----- test/test_batch_bool.cpp | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/include/xsimd/arch/xsimd_emulated.hpp b/include/xsimd/arch/xsimd_emulated.hpp index e2cd04c91..c754894dd 100644 --- a/include/xsimd/arch/xsimd_emulated.hpp +++ b/include/xsimd/arch/xsimd_emulated.hpp @@ -690,14 +690,15 @@ namespace xsimd } // set - template + // no A parameter on either set overload: callers pass no explicit template argument, so deduction stays constrained + template XSIMD_INLINE batch> set(batch> const&, requires_arch>, Values... values) noexcept { static_assert(sizeof...(Values) == batch>::size, "consistent init"); return { typename batch>::register_type { static_cast(values)... } }; } - template + template XSIMD_INLINE batch_bool> set(batch_bool> const&, requires_arch>, Values... values) noexcept { static_assert(sizeof...(Values) == batch>::size, "consistent init"); diff --git a/include/xsimd/types/xsimd_batch.hpp b/include/xsimd/types/xsimd_batch.hpp index 448928f02..88ada3f8a 100644 --- a/include/xsimd/types/xsimd_batch.hpp +++ b/include/xsimd/types/xsimd_batch.hpp @@ -679,7 +679,7 @@ namespace xsimd template template XSIMD_INLINE batch::batch(T val0, T val1, Ts... vals) noexcept - : batch(kernel::set(batch {}, A {}, val0, val1, static_cast(vals)...)) + : batch(kernel::set(batch {}, A {}, val0, val1, static_cast(vals)...)) { detail::static_check_supported_config(); static_assert(sizeof...(Ts) + 2 == size, "The constructor requires as many arguments as batch elements."); @@ -1215,7 +1215,7 @@ namespace xsimd template template XSIMD_INLINE batch_bool::batch_bool(bool val0, bool val1, Ts... vals) noexcept - : batch_bool(kernel::set(batch_bool {}, A {}, val0, val1, static_cast(vals)...)) + : batch_bool(make_register(std::index_sequence<> {}, val0, val1, static_cast(vals)...)) { static_assert(sizeof...(Ts) + 2 == size, "The constructor requires as many arguments as batch elements."); } @@ -1387,7 +1387,8 @@ namespace xsimd template XSIMD_INLINE auto batch_bool::make_register(std::index_sequence<>, V... v) noexcept -> register_type { - return kernel::set(batch_bool(), A {}, v...).data; + // no explicit template argument here: kernel::set would instantiate unrelated register types + return kernel::set(batch_bool(), A {}, v...).data; } /******************************* @@ -1425,7 +1426,7 @@ namespace xsimd template template XSIMD_INLINE batch, A>::batch(value_type val0, value_type val1, Ts... vals) noexcept - : batch(kernel::set(batch {}, A {}, val0, val1, static_cast(vals)...)) + : batch(kernel::set(batch {}, A {}, val0, val1, static_cast(vals)...)) { static_assert(sizeof...(Ts) + 2 == size, "as many arguments as batch elements"); } @@ -1657,7 +1658,7 @@ namespace xsimd template template XSIMD_INLINE batch, A>::batch(xtl::xcomplex val0, xtl::xcomplex val1, Ts... vals) noexcept - : batch(kernel::set(batch {}, A {}, val0, val1, static_cast>(vals)...)) + : batch(kernel::set(batch {}, A {}, val0, val1, static_cast>(vals)...)) { static_assert(sizeof...(Ts) + 2 == size, "as many arguments as batch elements"); } diff --git a/test/test_batch_bool.cpp b/test/test_batch_bool.cpp index 8f7b941fe..e97acf313 100644 --- a/test/test_batch_bool.cpp +++ b/test/test_batch_bool.cpp @@ -1002,4 +1002,25 @@ TEST_CASE_TEMPLATE("batch_bool mask hygiene", B, BATCH_TYPES) } } +#if XSIMD_WITH_EMULATED +TEST_CASE("emulated batch_bool construction") +{ + using M = xsimd::batch_bool>; + + M const all_true(true); + CHECK(all_true.get(0)); + CHECK(all_true.get(M::size - 1)); + + M const lanes(true, false, true); + CHECK(lanes.get(0)); + CHECK_FALSE(lanes.get(1)); + CHECK(lanes.get(2)); + + xsimd::batch> const values(1.f, 2.f, 3.f); + CHECK(values.get(0) == 1.f); + CHECK(values.get(1) == 2.f); + CHECK(values.get(2) == 3.f); +} +#endif + #endif