8#include "argon/argon_full.hpp"
9#include "argon/store.hpp"
15namespace argon::vectorize {
25template <
typename ScalarType,
size_t Str
ide = 1>
30 using vector_type = std::conditional_t<Stride == 1, argon_type, std::array<argon_type, Stride>>;
32 static constexpr size_t lanes = argon_type::lanes;
55 size_t count()
const {
return std::min(remaining_,
lanes); }
66 size_t remaining_ = 0;
72template <
typename ScalarType,
size_t Str
ide>
75 return offset_type::Iota(0) *
static_cast<typename offset_type::scalar_type
>(Stride);
80template <
size_t Str
ide,
typename ScalarType>
83#ifdef ARGON_PLATFORM_MVE
84 using predicate_type =
typename argon_type::argon_bool_type;
86 if constexpr (Stride == 1) {
87#ifdef ARGON_PLATFORM_MVE
89 return argon_type::Load(
ptr, predicate_type::FirstN(count));
94 if (count >= argon_type::lanes) {
95 return argon_type::template LoadInterleaved<Stride>(
ptr);
97#ifdef ARGON_PLATFORM_MVE
100 const auto active = predicate_type::FirstN(count);
101 std::array<argon_type, Stride> out;
102 for (
size_t channel = 0; channel < Stride; ++channel) {
103 out[channel] = argon_type::LoadGatherOffsetIndex(
ptr + channel, offsets, active);
114template <
size_t Str
ide,
typename ScalarType>
117#ifdef ARGON_PLATFORM_MVE
118 using predicate_type =
typename argon_type::argon_bool_type;
120 if constexpr (Stride == 1) {
121#ifdef ARGON_PLATFORM_MVE
122 value.StoreTo(
ptr, predicate_type::FirstN(count));
124 if (count >= argon_type::lanes) {
131 if (count >= argon_type::lanes) {
135#ifdef ARGON_PLATFORM_MVE
138 const auto active = predicate_type::FirstN(count);
139 for (
size_t channel = 0; channel < Stride; ++channel) {
140 value[channel].StoreScatterOffsetIndex(
ptr + channel, offsets, active);
150template <
typename Po
interType,
size_t Str
ide>
154 PointerType* base =
nullptr;
158 PointerType* ptr()
const {
return base +
index * Stride; }
167template <
typename ScalarType,
size_t Str
ide = 1>
168class load_tail :
public std::ranges::view_interface<load_tail<ScalarType, Stride>> {
169 static constexpr size_t lanes = Argon<ScalarType>::lanes;
177 Iterator() =
default;
187 cursor_.
index += lanes;
190 Iterator operator++(
int) {
191 Iterator tmp = *
this;
196 friend bool operator==(
const Iterator& a,
const Iterator& b) {
return a.cursor_.index == b.cursor_.index; }
197 friend bool operator==(
const Iterator& it, std::default_sentinel_t) {
return it.cursor_.done(); }
200 detail::TailCursor<const ScalarType, Stride> cursor_;
202 static_assert(std::forward_iterator<Iterator>);
204 load_tail() =
default;
206 load_tail(
const ScalarType* start,
size_t count) : start_{start}, count_{count} {}
208 Iterator begin()
const {
return Iterator{{start_, 0, count_}}; }
209 std::default_sentinel_t end()
const {
return {}; }
211 size_t size()
const {
return (count_ + lanes - 1) / lanes; }
214 const ScalarType* start_ =
nullptr;
221template <
typename ScalarType,
size_t Str
ide = 1>
222class store_tail :
public std::ranges::view_interface<store_tail<ScalarType, Stride>> {
223 static constexpr size_t lanes = Argon<ScalarType>::lanes;
231 Iterator() =
default;
234 value_type& operator*() {
return current_; }
235 const value_type& operator*()
const {
return current_; }
240 cursor_.index += lanes;
243 current_ =
value_type{{}, cursor_.remaining()};
246 void operator++(
int) { ++*
this; }
248 friend bool operator==(
const Iterator& it, std::default_sentinel_t) {
return it.cursor_.done(); }
251 detail::TailCursor<ScalarType, Stride> cursor_;
254 static_assert(std::input_or_output_iterator<Iterator>);
256 store_tail() =
default;
258 store_tail(ScalarType* start,
size_t count) : start_{start}, count_{count} {}
260 Iterator begin()
const {
return Iterator{{start_, 0, count_}}; }
261 std::default_sentinel_t end()
const {
return {}; }
263 size_t size()
const {
return (count_ + lanes - 1) / lanes; }
266 ScalarType* start_ =
nullptr;
274template <
typename ScalarType,
size_t Str
ide = 1>
275class load_store_tail :
public std::ranges::view_interface<load_store_tail<ScalarType, Stride>> {
276 static constexpr size_t lanes = Argon<ScalarType>::lanes;
284 Iterator() =
default;
287 value_type& operator*() {
292 const value_type& operator*()
const {
302 cursor_.index += lanes;
303 loaded_ = dirty_ =
false;
306 void operator++(
int) { ++*
this; }
308 friend bool operator==(
const Iterator& it, std::default_sentinel_t) {
return it.cursor_.done(); }
313 const size_t n = cursor_.remaining();
314 current_ = value_type{detail::load_partial<Stride>(
static_cast<const ScalarType*
>(cursor_.ptr()), n), n};
319 detail::TailCursor<ScalarType, Stride> cursor_;
320 mutable value_type current_;
321 mutable bool loaded_ =
false;
324 static_assert(std::input_or_output_iterator<Iterator>);
326 load_store_tail() =
default;
330 Iterator begin()
const {
return Iterator{{start_, 0, count_}}; }
331 std::default_sentinel_t end()
const {
return {}; }
333 size_t size()
const {
return (count_ + lanes - 1) / lanes; }
336 ScalarType* start_ =
nullptr;
Definition argon_full.hpp:44
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 vector (or, for interleaved views, one group of Stride vectors) of a range, and how many of its l...
Definition tail.hpp:26
std::conditional_t< Stride==1, argon_type, std::array< argon_type, Stride > > vector_type
The value: a vector, or for interleaved views an array of one vector per channel.
Definition tail.hpp:30
Argon< ScalarType > argon_type
The type of one vector.
Definition tail.hpp:28
static constexpr size_t lanes
Definition tail.hpp:32
Partial(vector_type value, size_t remaining)
A value whose first remaining lanes are in the range (lanes or more means all of them).
Definition tail.hpp:37
vector_type * operator->()
Member access on the value.
Definition tail.hpp:44
Partial & operator=(vector_type value)
Replace the value; only the lanes inside the range are stored.
Definition tail.hpp:49
size_t count() const
The number of leading lanes inside the range.
Definition tail.hpp:55
size_t remaining() const
Definition tail.hpp:62
const vector_type * operator->() const
Member access on the value.
Definition tail.hpp:46
const vector_type & operator*() const
The value. Lanes past the end of the range are zero after a load.
Definition tail.hpp:42
predicate_type active() const
The lanes inside the range, as a predicate.
Definition tail.hpp:59
vector_type & operator*()
The value. Lanes past the end of the range are zero after a load.
Definition tail.hpp:40
bool full() const
Whether every lane is inside the range.
Definition tail.hpp:57
typename argon_type::argon_bool_type predicate_type
The predicate type for active().
Definition tail.hpp:31
load_store_tail(ScalarType *start, size_t count)
View count lanes (frames, for interleaved views) starting at start.
Definition tail.hpp:328
size_t size() const
The number of vectors, counting a final partial one.
Definition tail.hpp:333
load_tail(const ScalarType *start, size_t count)
View count lanes (frames, for interleaved views) starting at start.
Definition tail.hpp:206
size_t size() const
The number of vectors, counting a final partial one.
Definition tail.hpp:211
size_t size() const
The number of vectors, counting a final partial one.
Definition tail.hpp:263
store_tail(ScalarType *start, size_t count)
View count lanes (frames, for interleaved views) starting at start.
Definition tail.hpp:258
NEON loads and stores of a loop's final, partial vector, branching on its scalar lane count.
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(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
ace Argon< T > load(const T *ptr)
Load a quad-word vector from a pointer.
Definition argon.hpp:143
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
Shared position-keeping for the tail iterators.
Definition tail.hpp:151
size_t index
The current lane (frame) of the range.
Definition tail.hpp:155
size_t remaining() const
Lanes left from the current position (not clamped to the lane count; FirstN saturates).
Definition tail.hpp:160
size_t count
The number of lanes (frames) in the range.
Definition tail.hpp:156
Partial< ScalarType, Stride > value_type
The value type of the iterator.
Definition tail.hpp:281
Iterator & operator++()
Store the current vector if it was modified, then move to the next vector.
Definition tail.hpp:298
std::ptrdiff_t difference_type
The difference type of the iterator.
Definition tail.hpp:282
Iterator over the vectors of the range; dereferences to a Partial.
Definition tail.hpp:173
std::ptrdiff_t difference_type
The difference type of the iterator.
Definition tail.hpp:175
value_type operator*() const
Load the current vector; lanes past the end of the range are zero and not read.
Definition tail.hpp:181
Partial< ScalarType, Stride > value_type
The value type of the iterator.
Definition tail.hpp:174
A view that loads data from a contiguous range into SIMD vectors.
Definition load.hpp:37
Partial< ScalarType, Stride > value_type
The value type of the iterator.
Definition tail.hpp:228
Iterator & operator++()
Store the current vector's lanes inside the range, then move to the next vector.
Definition tail.hpp:238
std::ptrdiff_t difference_type
The difference type of the iterator.
Definition tail.hpp:229
Partial< ScalarType, Stride >::vector_type load_partial(const ScalarType *ptr, size_t count)
Load the first count lanes at ptr (all lanes when count >= lanes); the rest are zero and not read.
Definition tail.hpp:81
Argon< ScalarType >::offset_type frame_offsets()
Lane offsets {0, Stride, 2*Stride, ...}: where each frame's first element lies, in elements.
Definition tail.hpp:73
void store_partial(ScalarType *ptr, const typename Partial< ScalarType, Stride >::vector_type &value, size_t count)
Store the first count lanes of value to ptr (all lanes when count >= lanes).
Definition tail.hpp:115