File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed
Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,34 @@ namespace xsimd
3232
3333 using namespace types ;
3434
35+ // broadcast
36+ namespace detail
37+ {
38+ template <class T , class A >
39+ struct broadcaster
40+ {
41+ using value_type = T;
42+ using return_type = batch<T, A>;
43+
44+ static return_type run (T v) noexcept
45+ {
46+ return return_type::broadcast (v);
47+ }
48+ };
49+
50+ template <class A >
51+ struct broadcaster <bool , A>
52+ {
53+ using value_type = uint8_t ;
54+ using return_type = batch_bool<uint8_t , A>;
55+
56+ static return_type run (bool b) noexcept
57+ {
58+ return return_type (b);
59+ }
60+ };
61+ }
62+
3563 // compress
3664 namespace detail
3765 {
Original file line number Diff line number Diff line change @@ -491,10 +491,11 @@ namespace xsimd
491491 * @return a new batch instance
492492 */
493493 template <class T , class A = default_arch>
494- XSIMD_INLINE batch <T, A> broadcast (T v) noexcept
494+ XSIMD_INLINE typename kernel::detail::broadcaster <T, A>::return_type broadcast (T v) noexcept
495495 {
496- detail::static_check_supported_config<T, A>();
497- return batch<T, A>::broadcast (v);
496+ using value_type = typename kernel::detail::broadcaster<T, A>::value_type;
497+ detail::static_check_supported_config<value_type, A>();
498+ return kernel::detail::broadcaster<T, A>::run (v);
498499 }
499500
500501 /* *
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ struct xsimd_api_test
2323{
2424 using batch_type = B;
2525 using batch_bool_type = typename B::batch_bool_type;
26+ using arch_type = typename B::arch_type;
2627 using value_type = typename B::value_type;
2728 static constexpr size_t size = B::size;
2829 using array_type = std::array<value_type, size>;
@@ -100,6 +101,7 @@ struct xsimd_api_test
100101
101102 void test_set ()
102103 {
104+ test_set_bool (" set bool" );
103105 test_set_impl<int8_t >(" set int8_t" );
104106 test_set_impl<uint8_t >(" set uint8_t" );
105107 test_set_impl<int16_t >(" set int16_t" );
@@ -171,6 +173,15 @@ struct xsimd_api_test
171173 CHECK_BATCH_EQ (res, expected);
172174 }
173175
176+ void test_set_bool (const std::string& name)
177+ {
178+ bool v = true ;
179+ xsimd::batch_bool<uint8_t , arch_type> expected (v);
180+ xsimd::batch_bool<uint8_t , arch_type> res = xsimd::broadcast (v);
181+ INFO (name);
182+ CHECK_BATCH_EQ (res, expected);
183+ }
184+
174185 template <class V >
175186 void init_test_vector (V& vec)
176187 {
You can’t perform that action at this time.
0 commit comments