A loop over n elements a vector at a time, final partial vector included, shaped so that Helium compilers turn it into a low-overhead tail-predicated loop.
More...
#include <algorithm>
#include <array>
#include <cstddef>
#include <type_traits>
#include "argon/argon_full.hpp"
#include "argon/store.hpp"
#include "argon/vectorize/first_n.hpp"
Go to the source code of this file.
|
| namespace | argon |
| | A 128-bit SIMD vector wrapping a scalar type, providing arithmetic, logical, and data-movement operations.
|
|
| template<typename ScalarType, typename Body> |
| void | argon::vectorize::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 included.
|
| template<typename ScalarType, size_t Stride, typename Body> |
| void | argon::vectorize::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 elements, the final partial group included.
|
A loop over n elements a vector at a time, final partial vector included, shaped so that Helium compilers turn it into a low-overhead tail-predicated loop.
◆ for_each()
template<typename ScalarType, typename Body>
| void argon::vectorize::for_each |
( |
std::ptrdiff_t | n, |
|
|
Body && | body ) |
|
inline |
Call body with a Step for each vector's worth of the elements [0, n), the final partial vector included.
- Template Parameters
-
| ScalarType | The lane type of the loop. |
- Parameters
-
| n | The number of elements. |
| body | A callable taking a Step by value, generic in it ([&](auto step) { ... }): on NEON it is called with full steps and then once with a partial one. |
On Helium, GCC and clang compile this into a low-overhead tail-predicated loop (dlstp/letp), with no scalar epilogue: the loop is a signed counter, a vctp of the remaining count, and predicated accesses, the shape they recognise. (GCC does so for float loops only with -fno-trapping-math, since the inactive lanes compute too.) On NEON the whole vectors use plain loads and stores, and the last step loads and stores only its in-range lanes, branching on their count: active() is built only if the body asks for it.
step.Store(out, step.Load(a) + (step.Load(b) - step.Load(a)) * t);
});
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
◆ for_each_interleaved()
template<typename ScalarType, size_t Stride, typename Body>
| void argon::vectorize::for_each_interleaved |
( |
std::ptrdiff_t | frames, |
|
|
Body && | body ) |
|
inline |
Call body with an InterleavedStep for each vector's worth of the frames frames of Stride interleaved elements, the final partial group included.
- Template Parameters
-
| ScalarType | The element type. |
| Stride | 2, 3 or 4 elements per frame. |
- Parameters
-
| body | A callable taking an InterleavedStep by value, generic in it ([&](auto step) { ... }). |
Whole groups use vld2-vld4 / vst2-vst4 in a low-overhead loop. The structured loads can't be predicated, so on NEON the last, partial group moves only its in-range frames with them, and on MVE it gathers and scatters each channel under a predicate (a dls/le loop rather than dlstp/letp). On MVE, which has no vld3, stride 3 gathers every group under a predicate instead, which can become a tail-predicated dlstp/letp loop. If every channel gets the same treatment, for_each over the interleaved data as flat elements is simpler and faster.
auto [left, right] = step.Load(stereo);
step.Store(stereo, {right, left});
});
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