1818#include < ostream>
1919
2020#include " ../types/xsimd_batch.hpp"
21+ #include " ../types/xsimd_traits.hpp"
2122#include " ../arch/xsimd_isa.hpp"
2223
2324namespace xsimd {
@@ -323,6 +324,23 @@ batch<T, A> broadcast(T v) {
323324 return kernel::broadcast<A>(v, A{});
324325}
325326
327+ /* *
328+ * @ingroup batch_data_transfer
329+ *
330+ * Creates a batch from the single value \c v and
331+ * the specified batch value type \c To.
332+ * @param v the value used to initialize the batch
333+ * @return a new batch instance
334+ */
335+ template <class To , class A =default_arch, class From >
336+ simd_return_type<From, To> broadcast_as (From v) {
337+ using batch_value_type = typename simd_return_type<From, To>::value_type;
338+ using value_type = typename std::conditional<std::is_same<From, bool >::value,
339+ bool ,
340+ batch_value_type>::type;
341+ return simd_return_type<From, To>(value_type (v));
342+ }
343+
326344/* *
327345 * @ingroup batch_math
328346 *
@@ -959,6 +977,58 @@ batch<From, A> load_unaligned(From const* ptr) {
959977 return kernel::load_unaligned<A>(ptr, kernel::convert<From>{}, A{});
960978}
961979
980+ /* *
981+ * @ingroup batch_data_transfer
982+ *
983+ * Creates a batch from the buffer \c ptr and the specifed
984+ * batch value type \c To. The memory needs to be aligned.
985+ * @param ptr the memory buffer to read
986+ * @return a new batch instance
987+ */
988+ template <class To , class A =default_arch, class From >
989+ simd_return_type<From, To> load_as (From const * ptr, aligned_mode) {
990+ using batch_value_type = typename simd_return_type<From, To>::value_type;
991+ return kernel::load_aligned<A>(ptr, kernel::convert<batch_value_type>{}, A{});
992+ }
993+
994+ template <class To , class A = default_arch>
995+ simd_return_type<bool , To> load_as (bool const * ptr, aligned_mode) {
996+ return simd_return_type<bool , To>::load_aligned (ptr);
997+ }
998+
999+ template <class To , class A =default_arch, class From >
1000+ simd_return_type<std::complex <From>, To> load_as (std::complex <From> const * ptr, aligned_mode)
1001+ {
1002+ using batch_value_type = typename simd_return_type<std::complex <From>, To>::value_type;
1003+ return kernel::load_complex_aligned<A>(ptr, kernel::convert<batch_value_type>{}, A{});
1004+ }
1005+
1006+ /* *
1007+ * @ingroup batch_data_transfer
1008+ *
1009+ * Creates a batch from the buffer \c ptr and the specifed
1010+ * batch value type \c To. The memory does not need to be aligned.
1011+ * @param ptr the memory buffer to read
1012+ * @return a new batch instance
1013+ */
1014+ template <class To , class A =default_arch, class From >
1015+ simd_return_type<From, To> load_as (From const * ptr, unaligned_mode) {
1016+ using batch_value_type = typename simd_return_type<From, To>::value_type;
1017+ return kernel::load_unaligned<A>(ptr, kernel::convert<batch_value_type>{}, A{});
1018+ }
1019+
1020+ template <class To , class A = default_arch>
1021+ simd_return_type<bool , To> load_as (bool const * ptr, unaligned_mode) {
1022+ return simd_return_type<bool , To>::load_unaligned (ptr);
1023+ }
1024+
1025+ template <class To , class A =default_arch, class From >
1026+ simd_return_type<std::complex <From>, To> load_as (std::complex <From> const * ptr, unaligned_mode)
1027+ {
1028+ using batch_value_type = typename simd_return_type<std::complex <From>, To>::value_type;
1029+ return kernel::load_complex_unaligned<A>(ptr, kernel::convert<batch_value_type>{}, A{});
1030+ }
1031+
9621032/* *
9631033 * @ingroup batch_math
9641034 *
@@ -1423,8 +1493,8 @@ auto ssub(T const& x, Tp const& y) -> decltype(x - y) {
14231493 * @param mem the memory buffer to write to
14241494 * @param val the batch to copy from
14251495 */
1426- template <class To , class A , class From >
1427- void store (From * mem, batch<To , A> const & val, aligned_mode={}) {
1496+ template <class A , class T >
1497+ void store (T * mem, batch<T , A> const & val, aligned_mode={}) {
14281498 return kernel::store_aligned<A>(mem, val, A{});
14291499}
14301500
@@ -1436,8 +1506,8 @@ void store(From* mem, batch<To, A> const& val, aligned_mode={}) {
14361506 * @param mem the memory buffer to write to
14371507 * @param val the batch to copy from
14381508 */
1439- template <class To , class A , class From >
1440- void store (To * mem, batch<From , A> const & val, unaligned_mode) {
1509+ template <class A , class T >
1510+ void store (T * mem, batch<T , A> const & val, unaligned_mode) {
14411511 return kernel::store_unaligned<A>(mem, val, A{});
14421512}
14431513
@@ -1449,8 +1519,8 @@ void store(To* mem, batch<From, A> const& val, unaligned_mode) {
14491519 * @param mem the memory buffer to write to
14501520 * @param val the batch to copy from
14511521 */
1452- template <class To , class A , class From >
1453- void store_aligned (To * mem, batch<From , A> const & val) {
1522+ template <class A , class T >
1523+ void store_aligned (T * mem, batch<T , A> const & val) {
14541524 return kernel::store_aligned<A>(mem, val, A{});
14551525}
14561526
@@ -1462,11 +1532,82 @@ void store_aligned(To* mem, batch<From, A> const& val) {
14621532 * @param mem the memory buffer to write to
14631533 * @param val the batch to copy
14641534 */
1465- template <class To , class A , class From >
1466- void store_unaligned (To * mem, batch<From , A> const & val) {
1535+ template <class A , class T >
1536+ void store_unaligned (T * mem, batch<T , A> const & val) {
14671537 return kernel::store_unaligned<A>(mem, val, A{});
14681538}
14691539
1540+ /* *
1541+ * @ingroup batch_data_transfer
1542+ *
1543+ * Copy content of batch \c src to the buffer \c dst. The
1544+ * memory needs to be aligned.
1545+ * @param mem the memory buffer to write to
1546+ * @param val the batch to copy
1547+ */
1548+ template <class To , class A =default_arch, class From >
1549+ void store_as (To* dst, batch<From, A> const & src, aligned_mode) {
1550+ kernel::store_aligned (dst, src, A{});
1551+ }
1552+
1553+ template <class A =default_arch, class From >
1554+ void store_as (bool * dst, batch_bool<From, A> const & src, aligned_mode) {
1555+ kernel::store (src, dst, A{});
1556+ }
1557+
1558+ template <class To , class A =default_arch, class From >
1559+ void store_as (std::complex <To>* dst, batch<std::complex <From>,A> const & src, aligned_mode) {
1560+ kernel::store_complex_aligned (dst, src, A{});
1561+ }
1562+
1563+ /* *
1564+ * @ingroup batch_data_transfer
1565+ *
1566+ * Copy content of batch \c src to the buffer \c dst. The
1567+ * memory does not need to be aligned.
1568+ * @param mem the memory buffer to write to
1569+ * @param val the batch to copy
1570+ */
1571+ template <class To , class A =default_arch, class From >
1572+ void store_as (To* dst, batch<From, A> const & src, unaligned_mode) {
1573+ kernel::store_unaligned (dst, src, A{});
1574+ }
1575+
1576+ template <class A =default_arch, class From >
1577+ void store_as (bool * dst, batch_bool<From, A> const & src, unaligned_mode) {
1578+ kernel::store (src, dst, A{});
1579+ }
1580+
1581+ template <class To , class A =default_arch, class From >
1582+ void store_as (std::complex <To>* dst, batch<std::complex <From>, A> const & src, unaligned_mode) {
1583+ kernel::store_complex_unaligned (dst, src, A{});
1584+ }
1585+
1586+ /* *
1587+ * @ingroup batch_data_transfer
1588+ *
1589+ * Copy content of batch of boolean \c src to the buffer \c dst. The
1590+ * memory needs to be aligned.
1591+ * @param mem the memory buffer to write to
1592+ * @param val the batch to copy
1593+ */
1594+ template <class To , class A =default_arch, class From >
1595+ void store_batch (To* dst, batch_bool<From, A> const & src, aligned_mode) {
1596+ kernel::store (src, dst, A{});
1597+ }
1598+
1599+ /* *
1600+ * @ingroup batch_data_transfer
1601+ *
1602+ * Copy content of batch of boolean \c src to the buffer \c dst. The
1603+ * memory does not need to be aligned.
1604+ * @param mem the memory buffer to write to
1605+ * @param val the batch to copy
1606+ */
1607+ template <class To , class A =default_arch, class From >
1608+ void store_batch (To* dst, batch_bool<From, A> const & src, unaligned_mode) {
1609+ kernel::store (src, dst, A{});
1610+ }
14701611/* *
14711612 * @ingroup batch_arithmetic
14721613 *
0 commit comments