From 68a2f02fdeb68d6206c4ce77a2849ba8f073cc79 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Fri, 28 Mar 2025 15:52:40 +0100 Subject: [PATCH] Reorder make_batch_constant and make_batch_bool_constant template arguments So that we can use a default architecture, which is consistent with other API. This is an API breaking change --- .../xsimd/arch/generic/xsimd_generic_math.hpp | 2 +- .../arch/generic/xsimd_generic_memory.hpp | 6 +-- include/xsimd/types/xsimd_batch_constant.hpp | 16 ++++---- test/test_batch_constant.cpp | 40 +++++++++---------- test/test_batch_manip.cpp | 6 +-- test/test_select.cpp | 2 +- test/test_shuffle.cpp | 18 ++++----- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/include/xsimd/arch/generic/xsimd_generic_math.hpp b/include/xsimd/arch/generic/xsimd_generic_math.hpp index b8db7f805..4dc9c3878 100644 --- a/include/xsimd/arch/generic/xsimd_generic_math.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_math.hpp @@ -2087,7 +2087,7 @@ namespace xsimd XSIMD_INLINE T reduce(Op op, batch const& self, std::integral_constant) noexcept { using index_type = as_unsigned_integer_t; - batch split = swizzle(self, make_batch_constant>()); + batch split = swizzle(self, make_batch_constant, A>()); return reduce(op, op(split, self), std::integral_constant()); } } diff --git a/include/xsimd/arch/generic/xsimd_generic_memory.hpp b/include/xsimd/arch/generic/xsimd_generic_memory.hpp index 7377881d7..af884c185 100644 --- a/include/xsimd/arch/generic/xsimd_generic_memory.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_memory.hpp @@ -207,7 +207,7 @@ namespace xsimd } }; batch tmp(val); - return select(make_batch_bool_constant(), self, tmp); + return select(make_batch_bool_constant(), self, tmp); } // get @@ -341,7 +341,7 @@ namespace xsimd } }; - return swizzle(self, make_batch_constant, A, rotate_generator>(), A {}); + return swizzle(self, make_batch_constant, rotate_generator, A>(), A {}); } template @@ -362,7 +362,7 @@ namespace xsimd } }; - return swizzle(self, make_batch_constant, A, rotate_generator>(), A {}); + return swizzle(self, make_batch_constant, rotate_generator, A>(), A {}); } template diff --git a/include/xsimd/types/xsimd_batch_constant.hpp b/include/xsimd/types/xsimd_batch_constant.hpp index 3d9603277..35cc5d3af 100644 --- a/include/xsimd/types/xsimd_batch_constant.hpp +++ b/include/xsimd/types/xsimd_batch_constant.hpp @@ -245,13 +245,13 @@ namespace xsimd namespace detail { - template + template XSIMD_INLINE constexpr auto make_batch_constant(detail::index_sequence) noexcept -> batch_constant { return {}; } - template + template XSIMD_INLINE constexpr auto make_batch_bool_constant(detail::index_sequence) noexcept -> batch_bool_constant { @@ -280,18 +280,18 @@ namespace xsimd * }; * @endcode */ - template - XSIMD_INLINE constexpr auto make_batch_constant() noexcept -> decltype(detail::make_batch_constant(detail::make_index_sequence::size>())) + template + XSIMD_INLINE constexpr auto make_batch_constant() noexcept -> decltype(detail::make_batch_constant(detail::make_index_sequence::size>())) { - return detail::make_batch_constant(detail::make_index_sequence::size>()); + return detail::make_batch_constant(detail::make_index_sequence::size>()); } - template + template XSIMD_INLINE constexpr auto make_batch_bool_constant() noexcept - -> decltype(detail::make_batch_bool_constant( + -> decltype(detail::make_batch_bool_constant( detail::make_index_sequence::size>())) { - return detail::make_batch_bool_constant( + return detail::make_batch_bool_constant( detail::make_index_sequence::size>()); } diff --git a/test/test_batch_constant.cpp b/test/test_batch_constant.cpp index 3989280a7..7cc036020 100644 --- a/test/test_batch_constant.cpp +++ b/test/test_batch_constant.cpp @@ -40,14 +40,14 @@ struct constant_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return generator::get(i++, size); }); - constexpr auto b = xsimd::make_batch_constant(); + constexpr auto b = xsimd::make_batch_constant(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } void test_cast() const { - constexpr auto cst_b = xsimd::make_batch_constant(); + constexpr auto cst_b = xsimd::make_batch_constant(); auto b0 = cst_b.as_batch(); auto b1 = (batch_type)cst_b; CHECK_BATCH_EQ(b0, b1); @@ -69,7 +69,7 @@ struct constant_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return arange::get(i++, size); }); - constexpr auto b = xsimd::make_batch_constant(); + constexpr auto b = xsimd::make_batch_constant(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } @@ -87,34 +87,34 @@ struct constant_batch_test { array_type expected; std::fill(expected.begin(), expected.end(), constant<3>::get(0, 0)); - constexpr auto b = xsimd::make_batch_constant>(); + constexpr auto b = xsimd::make_batch_constant, arch_type>(); INFO("batch(value_type)"); CHECK_BATCH_EQ((batch_type)b, expected); } void test_ops() const { - constexpr auto n12 = xsimd::make_batch_constant>(); - constexpr auto n3 = xsimd::make_batch_constant>(); + constexpr auto n12 = xsimd::make_batch_constant, arch_type>(); + constexpr auto n3 = xsimd::make_batch_constant, arch_type>(); constexpr auto n12_add_n3 = n12 + n3; - constexpr auto n15 = xsimd::make_batch_constant>(); + constexpr auto n15 = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "n12 + n3 == n15"); constexpr auto n12_sub_n3 = n12 - n3; - constexpr auto n9 = xsimd::make_batch_constant>(); + constexpr auto n9 = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "n12 - n3 == n9"); constexpr auto n12_mul_n3 = n12 * n3; - constexpr auto n36 = xsimd::make_batch_constant>(); + constexpr auto n36 = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "n12 * n3 == n36"); constexpr auto n12_div_n3 = n12 / n3; - constexpr auto n4 = xsimd::make_batch_constant>(); + constexpr auto n4 = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "n12 / n3 == n4"); constexpr auto n12_mod_n3 = n12 % n3; - constexpr auto n0 = xsimd::make_batch_constant>(); + constexpr auto n0 = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "n12 % n3 == n0"); constexpr auto n12_land_n3 = n12 & n3; @@ -130,11 +130,11 @@ struct constant_batch_test static_assert(std::is_same::value, "+n12 == n12"); constexpr auto n12_inv = ~n12; - constexpr auto n12_inv_ = xsimd::make_batch_constant>(); + constexpr auto n12_inv_ = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "~n12 == n12_inv"); constexpr auto n12_usub = -n12; - constexpr auto n12_usub_ = xsimd::make_batch_constant>(); + constexpr auto n12_usub_ = xsimd::make_batch_constant, arch_type>(); static_assert(std::is_same::value, "-n12 == n12_usub"); } }; @@ -185,7 +185,7 @@ struct constant_bool_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return generator::get(i++, size); }); - constexpr auto b = xsimd::make_batch_bool_constant(); + constexpr auto b = xsimd::make_batch_bool_constant(); INFO("batch_bool_constant(value_type)"); CHECK_BATCH_EQ((batch_bool_type)b, expected); } @@ -205,7 +205,7 @@ struct constant_bool_batch_test std::generate(expected.begin(), expected.end(), [&i]() { return split::get(i++, size); }); - constexpr auto b = xsimd::make_batch_bool_constant(); + constexpr auto b = xsimd::make_batch_bool_constant(); INFO("batch_bool_constant(value_type)"); CHECK_BATCH_EQ((batch_bool_type)b, expected); } @@ -229,7 +229,7 @@ struct constant_bool_batch_test void test_cast() const { - constexpr auto all_true = xsimd::make_batch_bool_constant>(); + constexpr auto all_true = xsimd::make_batch_bool_constant, arch_type>(); auto b0 = all_true.as_batch_bool(); auto b1 = (batch_bool_type)all_true; CHECK_BATCH_EQ(b0, batch_bool_type(true)); @@ -238,11 +238,11 @@ struct constant_bool_batch_test void test_ops() const { - constexpr auto all_true = xsimd::make_batch_bool_constant>(); - constexpr auto all_false = xsimd::make_batch_bool_constant>(); + constexpr auto all_true = xsimd::make_batch_bool_constant, arch_type>(); + constexpr auto all_false = xsimd::make_batch_bool_constant, arch_type>(); - constexpr auto x = xsimd::make_batch_bool_constant(); - constexpr auto y = xsimd::make_batch_bool_constant(); + constexpr auto x = xsimd::make_batch_bool_constant(); + constexpr auto y = xsimd::make_batch_bool_constant(); constexpr auto x_or_y = x | y; static_assert(std::is_same::value, "x | y == true"); diff --git a/test/test_batch_manip.cpp b/test/test_batch_manip.cpp index d7b220e1a..000491cd8 100644 --- a/test/test_batch_manip.cpp +++ b/test/test_batch_manip.cpp @@ -187,7 +187,7 @@ struct swizzle_test B b_exped = B::load_unaligned(v_exped.data()); using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + auto index_batch = xsimd::make_batch_constant, arch_type>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); @@ -207,7 +207,7 @@ struct swizzle_test B b_exped = B::load_unaligned(v_exped.data()); using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + auto index_batch = xsimd::make_batch_constant, arch_type>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); @@ -227,7 +227,7 @@ struct swizzle_test B b_exped = B::load_unaligned(v_exped.data()); using index_type = typename as_index::type; - auto index_batch = xsimd::make_batch_constant>(); + auto index_batch = xsimd::make_batch_constant, arch_type>(); B b_res = xsimd::swizzle(b_lhs, index_batch); CHECK_BATCH_EQ(b_res, b_exped); diff --git a/test/test_select.cpp b/test/test_select.cpp index 436ea647e..f7e941753 100644 --- a/test/test_select.cpp +++ b/test/test_select.cpp @@ -68,7 +68,7 @@ struct select_test void test_select_static() { - constexpr auto mask = xsimd::make_batch_bool_constant(); + constexpr auto mask = xsimd::make_batch_bool_constant(); for (size_t i = 0; i < nb_input; ++i) { diff --git a/test/test_shuffle.cpp b/test/test_shuffle.cpp index 4b698a138..df4bf783d 100644 --- a/test/test_shuffle.cpp +++ b/test/test_shuffle.cpp @@ -498,7 +498,7 @@ struct shuffle_test }; INFO("no op lhs"); - B b_res_lhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_lhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_lhs, b_lhs); struct no_op_rhs_generator @@ -510,7 +510,7 @@ struct shuffle_test }; INFO("no op rhs"); - B b_res_rhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_rhs = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_rhs, b_rhs); } @@ -535,7 +535,7 @@ struct shuffle_test } B b_ref = B::load_unaligned(ref.data()); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -557,7 +557,7 @@ struct shuffle_test ref[i] = (i > 2) ? lhs[0] : rhs[0]; B b_ref = B::load_unaligned(ref.data()); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -581,7 +581,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("swizzle first batch"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -600,7 +600,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("swizzle second batch"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } } @@ -643,7 +643,7 @@ struct shuffle_test B b_ref = B::load_unaligned(ref.data()); INFO("select"); - B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res, b_ref); } @@ -666,7 +666,7 @@ struct shuffle_test B b_ref_lo = B::load_unaligned(ref_lo.data()); INFO("zip_lo"); - B b_res_lo = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_lo = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_lo, b_ref_lo); struct zip_hi_generator @@ -685,7 +685,7 @@ struct shuffle_test B b_ref_hi = B::load_unaligned(ref_hi.data()); INFO("zip_hi"); - B b_res_hi = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); + B b_res_hi = xsimd::shuffle(b_lhs, b_rhs, xsimd::make_batch_constant()); CHECK_BATCH_EQ(b_res_hi, b_ref_hi); } };