6#include "arm_simd/helpers/concepts.hpp"
7#include "arm_simd/helpers/multivector.hpp"
8#include "arm_simd/helpers/scalar.hpp"
9#include "arm_simd/helpers/store.hpp"
11#ifdef __ARM_FEATURE_MVE
17#ifdef ARGON_PLATFORM_SIMDE
18#define ace [[gnu::always_inline]] inline
20#define ace [[gnu::always_inline]] constexpr
22#define ace [[gnu::always_inline]] inline
31template <
size_t str
ide,
typename scalar_type,
typename intrinsic_type>
32ace
void store_interleaved(scalar_type* ptr, simd::MultiVector_t<intrinsic_type, stride> multi_vec) {
33 static_assert(stride > 1 && stride < 5,
"Interleaving Stores can only be performed with a stride of 2, 3, or 4");
34 if constexpr (stride == 2) {
35 simd::store2(ptr, multi_vec);
36 }
else if constexpr (stride == 3) {
37#ifdef ARGON_PLATFORM_MVE
38 static_assert(stride != 3,
"MVE has no vst3; store a std::array of vectors instead, which scatters");
40 simd::store3(ptr, multi_vec);
42 }
else if constexpr (stride == 4) {
43 simd::store4(ptr, multi_vec);
51template <
size_t str
ide,
typename scalar_type,
typename argon_type>
53#ifdef ARGON_PLATFORM_MVE
54 if constexpr (stride == 3) {
56 using offset_type =
typename argon_type::offset_type;
57 const auto offsets = offset_type::Iota(0) *
static_cast<typename offset_type::scalar_type
>(3);
58 for (
size_t channel = 0; channel < 3; ++channel) {
59 multi_vec.data()[channel].StoreScatterOffsetIndex(ptr + channel, offsets);
65 using intrinsic_type =
typename argon_type::vector_type;
66 using multivec_type = simd::MultiVector_t<intrinsic_type, stride>;
67 using array_type = std::array<argon_type, stride>;
71 static_assert(std::is_standard_layout_v<array_type>);
72 static_assert(
sizeof(multivec_type) ==
sizeof(array_type),
73 "std::array isn't layout-compatible with this NEON multi-vector.");
82template <
typename scalar_type,
typename... argon_types>
84 static_assert(
sizeof...(vecs) > 1 &&
sizeof...(vecs) < 5,
85 "Interleaving Stores can only be performed with a stride of 2, 3, or 4");
86 static_assert((std::is_same_v<scalar_type, simd::Scalar_t<typename argon_types::vector_type>> && ...),
87 "All vectors must be of the same scalar type.");
90 ptr, std::array<std::common_type_t<argon_types...>,
sizeof...(vecs)>{std::forward<argon_types>(vecs)...});
96template <
typename scalar_type,
typename argon_type>
97 requires std::is_same_v<scalar_type, simd::Scalar_t<typename argon_type::vector_type>>
98ace
void store(scalar_type* ptr, argon_type vector) {
99 simd::store1(ptr, vector);
105template <
typename scalar_type, simd::is_vector_type
intrinsic_type>
106 requires std::is_same_v<scalar_type, simd::Scalar_t<intrinsic_type>>
107ace
void store(scalar_type* ptr, intrinsic_type vector) {
108 simd::store1(ptr, vector);
111#if defined(__clang__) || (__GNUC__ > 13)
121template <
size_t stride = 1,
typename scalar_type,
typename... intrinsic_types>
122 requires(std::is_same_v<scalar_type, simd::Scalar_t<intrinsic_types>> && ...)
123ace
void store(scalar_type* ptr, intrinsic_types... vectors) {
125 using intrinsic_type =
typename std::tuple_element_t<0, std::tuple<intrinsic_types...>>;
127 constexpr size_t size =
sizeof...(vectors);
128 constexpr std::array<intrinsic_type, size> vec_array = {std::move(vectors)...};
131 static_assert(0 < stride && stride < 5,
"Stores can only be performed with a stride of 1, 2, 3, or 4");
132 static_assert(size >= stride,
"You cannot store less vectors than your stride!");
133 static_assert(size % stride == 0,
"The number of vectors being stored must be a multiple of the stride!");
135 if constexpr (stride == 1) {
136 constexpr size_t tail_size = size % 4;
137 constexpr size_t head_size = size - tail_size;
139 if constexpr (head_size > 0) {
140 for (; i < head_size; i += 4) {
141 using multi_type = simd::MultiVector_t<intrinsic_type, 4>;
142 simd::store1_x4(ptr, *(multi_type*)&vec_array[i]);
143 ptr += (
sizeof(intrinsic_type) /
sizeof(*ptr)) * 4;
146 if constexpr (tail_size == 1) {
147 simd::store1(ptr, &vec_array[i]);
148 }
else if constexpr (tail_size == 2) {
149 using tail_multi_type = simd::MultiVector_t<intrinsic_type, 2>;
150 simd::store1_x2(ptr, *(tail_multi_type*)&vec_array[i]);
151 }
else if constexpr (tail_size == 3) {
152 using tail_multi_type = simd::MultiVector_t<intrinsic_type, 3>;
153 simd::store1_x3(ptr, *(tail_multi_type*)&vec_array[i]);
156#if defined(__cpp_lib_ranges_chunk) && __cpp_lib_ranges_chunk >= 202202L
157#pragma GCC unroll size
158 for (
auto v : vec_array | std::views::chunk(stride)) {
159 if constexpr (stride == 2) {
161 }
else if constexpr (stride == 3) {
163 }
else if constexpr (stride == 4) {
166 ptr +=
sizeof(intrinsic_type) /
sizeof(*ptr);
171#pragma GCC unroll size
172 for (
size_t i = 0; i + stride <= vec_array.size(); i += stride) {
173 if constexpr (stride == 2) {
175 }
else if constexpr (stride == 3) {
177 }
else if constexpr (stride == 4) {
180 ptr +=
sizeof(intrinsic_type) /
sizeof(*ptr);
190template <
size_t stride = 1,
typename scalar_type,
typename... argon_types>
191 requires(std::is_same_v<scalar_type, simd::Scalar_t<typename argon_types::vector_type>> && ...)
192ace
void store(scalar_type* ptr, argon_types... vectors) {
193 store<stride>(ptr, std::forward<typename argon_types::vector_type>(vectors)...);
202template <
int lane,
size_t str
ide,
typename scalar_type,
typename argon_type>
204 using intrinsic_type =
typename argon_type::vector_type;
205 using multivec_type = simd::MultiVector_t<intrinsic_type, stride>;
206 using array_type = std::array<argon_type, 2>;
210 static_assert(std::is_standard_layout_v<array_type>);
211 static_assert(std::is_trivial_v<array_type>);
212 static_assert(
sizeof(multivec_type) ==
sizeof(array_type),
213 "std::array isn't layout-compatible with this NEON multi-vector.");
223template <
int lane,
size_t str
ide,
typename scalar_type,
typename intrinsic_type>
225 static_assert(stride > 1 && stride < 5,
"Interleaving Stores can only be performed with a stride of 2, 3, or 4");
226 if constexpr (stride == 2) {
227 simd::store2_lane<lane>(ptr, multi_vec);
228 }
else if constexpr (stride == 3) {
229 simd::store3_lane<lane>(ptr, multi_vec);
230 }
else if constexpr (stride == 4) {
231 simd::store4_lane<lane>(ptr, multi_vec);
A 128-bit SIMD vector wrapping a scalar type, providing arithmetic, logical, and data-movement operat...
Definition argon.hpp:30
ace void store(scalar_type *ptr, argon_type vector)
Store a vector to a location in memory.
Definition store.hpp:98
ace void store_lane_interleaved(scalar_type *ptr, std::array< argon_type, stride > multi_vec)
Store a lane of an array of vectors to a location in memory with interleaving.
Definition store.hpp:203
ace void store_interleaved(scalar_type *ptr, simd::MultiVector_t< intrinsic_type, stride > multi_vec)
Store a multi-vector to a location in memory with interleaving.
Definition store.hpp:32