diff --git a/include/xsimd/arch/generic/xsimd_generic_memory.hpp b/include/xsimd/arch/generic/xsimd_generic_memory.hpp index 01aa48c65..22d3505a0 100644 --- a/include/xsimd/arch/generic/xsimd_generic_memory.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_memory.hpp @@ -32,6 +32,34 @@ namespace xsimd using namespace types; + // broadcast + namespace detail + { + template + struct broadcaster + { + using value_type = T; + using return_type = batch; + + static return_type run(T v) noexcept + { + return return_type::broadcast(v); + } + }; + + template + struct broadcaster + { + using value_type = uint8_t; + using return_type = batch_bool; + + static return_type run(bool b) noexcept + { + return return_type(b); + } + }; + } + // compress namespace detail { diff --git a/include/xsimd/types/xsimd_api.hpp b/include/xsimd/types/xsimd_api.hpp index a9c61244c..74191068f 100644 --- a/include/xsimd/types/xsimd_api.hpp +++ b/include/xsimd/types/xsimd_api.hpp @@ -491,10 +491,11 @@ namespace xsimd * @return a new batch instance */ template - XSIMD_INLINE batch broadcast(T v) noexcept + XSIMD_INLINE typename kernel::detail::broadcaster::return_type broadcast(T v) noexcept { - detail::static_check_supported_config(); - return batch::broadcast(v); + using value_type = typename kernel::detail::broadcaster::value_type; + detail::static_check_supported_config(); + return kernel::detail::broadcaster::run(v); } /** diff --git a/test/test_api.cpp b/test/test_api.cpp index 9a32db2eb..a5e933f4a 100644 --- a/test/test_api.cpp +++ b/test/test_api.cpp @@ -23,6 +23,7 @@ struct xsimd_api_test { using batch_type = B; using batch_bool_type = typename B::batch_bool_type; + using arch_type = typename B::arch_type; using value_type = typename B::value_type; static constexpr size_t size = B::size; using array_type = std::array; @@ -100,6 +101,7 @@ struct xsimd_api_test void test_set() { + test_set_bool("set bool"); test_set_impl("set int8_t"); test_set_impl("set uint8_t"); test_set_impl("set int16_t"); @@ -171,6 +173,15 @@ struct xsimd_api_test CHECK_BATCH_EQ(res, expected); } + void test_set_bool(const std::string& name) + { + bool v = true; + xsimd::batch_bool expected(v); + xsimd::batch_bool res = xsimd::broadcast(v); + INFO(name); + CHECK_BATCH_EQ(res, expected); + } + template void init_test_vector(V& vec) {