18
18
#include < ostream>
19
19
20
20
#include " ../types/xsimd_batch.hpp"
21
+ #include " ../types/xsimd_traits.hpp"
21
22
#include " ../arch/xsimd_isa.hpp"
22
23
23
24
namespace xsimd {
@@ -323,6 +324,23 @@ batch<T, A> broadcast(T v) {
323
324
return kernel::broadcast<A>(v, A{});
324
325
}
325
326
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
+
326
344
/* *
327
345
* @ingroup batch_math
328
346
*
@@ -959,6 +977,58 @@ batch<From, A> load_unaligned(From const* ptr) {
959
977
return kernel::load_unaligned<A>(ptr, kernel::convert<From>{}, A{});
960
978
}
961
979
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
+
962
1032
/* *
963
1033
* @ingroup batch_math
964
1034
*
@@ -1423,8 +1493,8 @@ auto ssub(T const& x, Tp const& y) -> decltype(x - y) {
1423
1493
* @param mem the memory buffer to write to
1424
1494
* @param val the batch to copy from
1425
1495
*/
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={}) {
1428
1498
return kernel::store_aligned<A>(mem, val, A{});
1429
1499
}
1430
1500
@@ -1436,8 +1506,8 @@ void store(From* mem, batch<To, A> const& val, aligned_mode={}) {
1436
1506
* @param mem the memory buffer to write to
1437
1507
* @param val the batch to copy from
1438
1508
*/
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) {
1441
1511
return kernel::store_unaligned<A>(mem, val, A{});
1442
1512
}
1443
1513
@@ -1449,8 +1519,8 @@ void store(To* mem, batch<From, A> const& val, unaligned_mode) {
1449
1519
* @param mem the memory buffer to write to
1450
1520
* @param val the batch to copy from
1451
1521
*/
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) {
1454
1524
return kernel::store_aligned<A>(mem, val, A{});
1455
1525
}
1456
1526
@@ -1462,11 +1532,82 @@ void store_aligned(To* mem, batch<From, A> const& val) {
1462
1532
* @param mem the memory buffer to write to
1463
1533
* @param val the batch to copy
1464
1534
*/
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) {
1467
1537
return kernel::store_unaligned<A>(mem, val, A{});
1468
1538
}
1469
1539
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
+ }
1470
1611
/* *
1471
1612
* @ingroup batch_arithmetic
1472
1613
*
0 commit comments