6#include "argon/argon_full.hpp"
7#include "argon/store.hpp"
14namespace argon::vectorize {
22template <
typename ScalarType,
bool full>
27 static constexpr std::ptrdiff_t
lanes = argon_type::lanes;
29 [[gnu::always_inline]] Step(std::ptrdiff_t
index, std::ptrdiff_t remaining) : index_{
index}, remaining_{remaining} {}
32 [[gnu::always_inline]] std::ptrdiff_t
index()
const {
return index_; }
35 [[gnu::always_inline]] std::ptrdiff_t
count()
const {
39 return remaining_ <
lanes ? remaining_ :
lanes;
47 return predicate_type::True();
49 return predicate_type::FirstN(
static_cast<size_t>(remaining_));
58#ifdef ARGON_PLATFORM_MVE
71#ifdef ARGON_PLATFORM_MVE
86#ifdef ARGON_PLATFORM_MVE
101#ifdef ARGON_PLATFORM_MVE
110 std::ptrdiff_t index_;
111 std::ptrdiff_t remaining_;
131template <
typename ScalarType,
typename Body>
132[[gnu::always_inline]]
inline void for_each(std::ptrdiff_t n, Body&& body) {
133 constexpr std::ptrdiff_t lanes = Argon<ScalarType>::lanes;
134#ifdef ARGON_PLATFORM_MVE
135 for (std::ptrdiff_t i = 0; i < n; i += lanes) {
139 std::ptrdiff_t i = 0;
140 for (; i + lanes <= n; i += lanes) {
155template <
typename ScalarType,
size_t Str
ide,
bool full>
156class InterleavedStep {
161 static constexpr std::ptrdiff_t
lanes = argon_type::lanes;
163 [[gnu::always_inline]] InterleavedStep(std::ptrdiff_t
index, std::ptrdiff_t remaining)
164 : index_{
index}, remaining_{remaining} {}
167 [[gnu::always_inline]] std::ptrdiff_t
index()
const {
return index_; }
170 [[gnu::always_inline]] std::ptrdiff_t
count()
const {
171 if constexpr (full) {
174 return remaining_ <
lanes ? remaining_ :
lanes;
180 if constexpr (full) {
181 return predicate_type::True();
183 return predicate_type::FirstN(
static_cast<size_t>(remaining_));
190 const ScalarType*
ptr = base + index_ * std::ptrdiff_t{Stride};
191 if constexpr (full) {
192 return argon_type::template LoadInterleaved<Stride>(
ptr);
194#ifdef ARGON_PLATFORM_MVE
195 const auto offsets = Offsets();
196 const auto mask =
active();
198 for (
size_t channel = 0; channel < Stride; ++channel) {
210 [[gnu::always_inline]]
void Store(ScalarType* base,
const frame_type& channels)
const {
211 ScalarType*
ptr = base + index_ * std::ptrdiff_t{Stride};
212 if constexpr (full) {
215#ifdef ARGON_PLATFORM_MVE
216 const auto offsets = Offsets();
217 const auto mask =
active();
219 for (
size_t channel = 0; channel < Stride; ++channel) {
220 vectors.data()[channel].StoreScatterOffsetIndex(
ptr + channel, offsets, mask);
232 return offset_type::Iota(0) *
static_cast<typename offset_type::scalar_type
>(Stride);
235 std::ptrdiff_t index_;
236 std::ptrdiff_t remaining_;
256template <
typename ScalarType,
size_t Str
ide,
typename Body>
257 requires(Stride >= 2 && Stride <= 4)
259 constexpr std::ptrdiff_t lanes = Argon<ScalarType>::lanes;
260#ifdef ARGON_PLATFORM_MVE
261 if constexpr (Stride == 3) {
262 for (std::ptrdiff_t i = 0; i < frames; i += lanes) {
268 std::ptrdiff_t i = 0;
269 for (; i + lanes <= frames; i += lanes) {
Definition argon_full.hpp:44
static ace Argon< S > LoadWiden(const N *ptr)
Load lanes elements of the narrower integer type N and extend each to a lane. MVE: vldrb / vldrh.
Definition argon_full.hpp:648
void StoreNarrow(N *ptr) const
Store the low bits of each lane as the narrower integer type N. MVE: vstrb / vstrh.
Definition argon_full.hpp:686
static ace argon_type Load(const scalar_type *ptr)
Definition vector.hpp:1095
ace void StoreTo(scalar_type *ptr) const
Store the vector to a pointer.
Definition vector.hpp:1356
static ace argon_type LoadGatherOffsetIndex(const scalar_type *base, offset_type offsets)
Definition vector.hpp:1152
helpers::ArgonFor_t< simd::make_unsigned_t< Bool_t< simd::Vec128_t< ScalarType > > > > offset_type
Definition vector.hpp:86
Predicate< simd::Vec128_t< ScalarType > > argon_bool_type
Definition vector.hpp:85
One step of vectorize::for_each_interleaved: the frames [index(), index() + count()),...
Definition for_each.hpp:156
typename argon_type::argon_bool_type predicate_type
The predicate type of active().
Definition for_each.hpp:160
std::array< argon_type, Stride > frame_type
One vector per channel.
Definition for_each.hpp:159
predicate_type active() const
The lanes (frames) inside the range.
Definition for_each.hpp:179
frame_type Load(const ScalarType *base) const
Load this step's frames of the interleaved array at base, one vector per channel; lanes past the end ...
Definition for_each.hpp:189
void Store(ScalarType *base, const frame_type &channels) const
Store one vector per channel, interleaved, to this step's frames of the array at base; frames past th...
Definition for_each.hpp:210
std::ptrdiff_t count() const
The number of this step's frames inside the range.
Definition for_each.hpp:170
Argon< ScalarType > argon_type
The vector type of one channel.
Definition for_each.hpp:158
std::ptrdiff_t index() const
The index of this step's first frame.
Definition for_each.hpp:167
static constexpr std::ptrdiff_t lanes
Frames per step.
Definition for_each.hpp:161
One step of vectorize::for_each: the elements [index(), index() + count()) of the range.
Definition for_each.hpp:23
void Store(ScalarType *base, argon_type value) const
Store value to this step's elements of the array at base; out-of-range lanes are not written.
Definition for_each.hpp:67
static constexpr std::ptrdiff_t lanes
Elements per step.
Definition for_each.hpp:27
std::ptrdiff_t index() const
The index of this step's first element.
Definition for_each.hpp:32
Argon< ScalarType > argon_type
The vector type of the loop.
Definition for_each.hpp:25
predicate_type active() const
The lanes inside the range.
Definition for_each.hpp:45
void StoreNarrow(N *base, argon_type value) const
Store the low bits of value to this step's elements of an array of the narrower integer type N.
Definition for_each.hpp:97
std::ptrdiff_t count() const
The number of this step's lanes inside the range.
Definition for_each.hpp:35
typename argon_type::argon_bool_type predicate_type
The predicate type of active().
Definition for_each.hpp:26
argon_type Load(const ScalarType *base) const
Load this step's elements of the array at base; out-of-range lanes are zero and not read.
Definition for_each.hpp:54
argon_type LoadWiden(const N *base) const
Load this step's elements of an array of the narrower integer type N, extending them to lanes.
Definition for_each.hpp:82
Whether lanes of integer type W can be loaded from (and stored as) the narrower integer type N,...
Definition argon_full.hpp:34
NEON loads and stores of a loop's final, partial vector, branching on its scalar lane count.
Argon< S > load_first_n_widen(const N *ptr, size_t count)
Load the first count (0 < count < lanes) elements of the narrower integer type N at ptr,...
Definition first_n.hpp:186
void store_first_n_interleaved(ScalarType *ptr, std::array< Argon< ScalarType >, Stride > value, size_t count)
Store the first count frames (0 < count < lanes) of value, one vector per channel,...
Definition first_n.hpp:164
std::array< Argon< ScalarType >, Stride > load_first_n_interleaved(const ScalarType *ptr, size_t count)
Load the first count frames (0 < count < lanes) of Stride interleaved elements at ptr,...
Definition first_n.hpp:137
Argon< ScalarType > load_first_n(const ScalarType *ptr, size_t count)
Load the first count lanes at ptr (0 < count < lanes); the rest are zero and not read.
Definition first_n.hpp:72
void store_first_n_narrow(N *ptr, Argon< S > value, size_t count)
Store the low bits of the first count (0 < count < lanes) lanes of value as the narrower integer type...
Definition first_n.hpp:207
void store_first_n(ScalarType *ptr, Argon< ScalarType > value, size_t count)
Store the first count lanes of value to ptr (0 < count < lanes); the rest are not written.
Definition first_n.hpp:84
void for_each(std::ptrdiff_t n, Body &&body)
Call body with a Step for each vector's worth of the elements [0, n), the final partial vector includ...
Definition for_each.hpp:132
void for_each_interleaved(std::ptrdiff_t frames, Body &&body)
Call body with an InterleavedStep for each vector's worth of the frames frames of Stride interleaved ...
Definition for_each.hpp:258
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