8#include "argon/argon_full.hpp"
9#include "argon/argon_half.hpp"
10#include "argon/helpers/argon_for.hpp"
11#include "argon/store.hpp"
12#include "argon/vector.hpp"
13#include "arm_simd/helpers/multivector.hpp"
14#include "arm_simd/helpers/scalar.hpp"
16#ifdef __ARM_FEATURE_MVE
22#ifdef ARGON_PLATFORM_SIMDE
23#define ace [[gnu::always_inline]] inline
25#define ace [[gnu::always_inline]] constexpr
27#define ace [[gnu::always_inline]] inline
37template <
typename T,
typename V>
39 if constexpr (simd::is_quadword_v<V>) {
40 return Argon<T>{simd::reinterpret<typename Argon<T>::vector_type>(in.
vec())};
41 }
else if constexpr (simd::is_doubleword_v<V>) {
42 return ArgonHalf<T>{simd::reinterpret<typename ArgonHalf<T>::vector_type>(in.
vec())};
51template <
typename argon_type, simd::is_vector_type V>
53 static_assert(!std::is_same_v<typename argon_type::vector_type, V>);
54 return argon_type{simd::reinterpret<typename argon_type::vector_type>(in)};
62template <
typename ScalarType,
typename ArgonType>
64 return in.template As<ScalarType>();
74template <
size_t lane,
size_t str
ide,
typename argon_type>
75ace
static std::array<argon_type, stride> load_to_lane_interleaved(
76 simd::MultiVector_t<typename argon_type::vector_type, stride> multi,
77 typename argon_type::scalar_type
const* ptr) {
78 return argon_type::LoadToLaneInterleaved(multi, ptr);
83template <
size_t lane,
size_t str
ide,
typename argon_type>
84ace
static std::array<argon_type, stride> load_to_lane_interleaved(std::array<argon_type, stride> multi,
85 typename argon_type::scalar_type
const* ptr) {
86 return argon_type::LoadToLaneInterleaved(multi, ptr);
96template <
typename argon_type>
97ace std::array<argon_type, 2>
zip(argon_type a, argon_type b) {
108template <
typename argon_type>
109ace std::array<argon_type, 2>
unzip(argon_type a, argon_type b) {
110 return a.UnzipWith(b);
121template <
typename argon_type>
122ace std::array<argon_type, 2>
transpose(argon_type a, argon_type b) {
123 return a.TransposeWith(b);
126#ifndef ARGON_PLATFORM_MVE
134 return simd::combine(low, high);
160template <
typename VectorType,
typename ScalarType>
161using LaneFor_t = std::conditional_t<std::is_integral_v<ScalarType> && std::is_integral_v<simd::Scalar_t<VectorType>> &&
162 sizeof(ScalarType) ==
sizeof(simd::Scalar_t<VectorType>) &&
163 std::is_signed_v<ScalarType> == std::is_signed_v<simd::Scalar_t<VectorType>>,
164 simd::Scalar_t<VectorType>, ScalarType>;
168template <
typename VectorType,
typename ScalarType>
183template <
typename VectorType,
typename BranchType>
186#ifndef ARGON_PLATFORM_MVE
187 if constexpr (BranchType::extension_arithmetic) {
188 return condition.
native() ? true_value.vec() : false_value.vec();
191 return condition.
Select(true_value, false_value);
196template <
typename MaskType,
typename BranchType>
197 requires std::is_unsigned_v<typename MaskType::scalar_type> && (MaskType::lanes == BranchType::lanes) &&
198 (
sizeof(
typename MaskType::vector_type) ==
sizeof(
typename BranchType::vector_type))
199ace BranchType
ternary(MaskType mask, BranchType true_value, BranchType false_value) {
200 if constexpr (BranchType::extension_arithmetic) {
201 return mask.vec() ? true_value.vec() : false_value.vec();
203 return mask.Select(true_value, false_value);
208template <
typename MaskType,
typename ValueType>
209 requires std::is_unsigned_v<typename MaskType::scalar_type> && lane_scalar<ValueType> &&
210 (
sizeof(ValueType) ==
sizeof(
typename MaskType::scalar_type))
211ace
auto ternary(MaskType mask, ValueType true_value, ValueType false_value) {
213 return ternary(mask, result_type{true_value}, result_type{false_value});
216template <
typename BranchType,
typename CondType>
218ace BranchType
ternary(CondType condition, BranchType true_value, BranchType false_value) {
219 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
220 return condition ? true_value.vec() : false_value.vec();
227template <
typename VectorType,
typename ValueType>
231 return ternary(condition, result_type{true_value}, result_type{false_value});
239template <
typename VectorType,
typename ValueType>
243 using scalar_type =
typename ValueType::scalar_type;
250 ace predicate_type
condition()
const {
return condition_; }
253 ace ValueType
value()
const {
return value_; }
257 return {condition_ | new_condition, condition_.
Select(value_, new_value)};
262 return else_if_(new_condition, ValueType{new_value});
266 template <std::invocable FunctionType>
268 return else_if_(new_condition, ValueType{func()});
272 ace ValueType
else_(ValueType new_value)
const {
return condition_.Select(value_, new_value); }
275 ace ValueType
else_(scalar_type new_value)
const {
return else_(ValueType{new_value}); }
278 template <std::invocable FunctionType>
279 ace ValueType
else_(FunctionType func)
const {
280 return else_(ValueType{func()});
284 predicate_type condition_;
290template <
typename VectorType,
typename ValueType>
293 return {condition, value};
297template <
typename VectorType,
typename ScalarType>
298 requires lane_scalar<ScalarType> && (
sizeof(ScalarType) ==
sizeof(simd::Scalar_t<VectorType>))
305template <
typename VectorType, std::invocable FunctionType>
307 return if_(condition, func());
Definition argon_half.hpp:11
Definition argon_full.hpp:44
The result of if_(...) and each else_if_(...): a value chosen per lane by a chain of conditions.
Definition argon.hpp:241
ace CondMonad(predicate_type condition, ValueType value)
Start a chain: value where condition holds.
Definition argon.hpp:247
ace ValueType else_(scalar_type new_value) const
new_value in the lanes no condition claimed; ends the chain.
Definition argon.hpp:275
ace CondMonad else_if_(predicate_type new_condition, FunctionType func) const
new_value in the lanes where new_condition holds and no earlier condition did.
Definition argon.hpp:267
ace ValueType else_(ValueType new_value) const
new_value in the lanes no condition claimed; ends the chain.
Definition argon.hpp:272
ace predicate_type condition() const
The lanes some condition in the chain has claimed so far.
Definition argon.hpp:250
ace CondMonad else_if_(predicate_type new_condition, ValueType new_value) const
new_value in the lanes where new_condition holds and no earlier condition did.
Definition argon.hpp:256
ace CondMonad else_if_(predicate_type new_condition, scalar_type new_value) const
new_value in the lanes where new_condition holds and no earlier condition did.
Definition argon.hpp:261
ace ValueType value() const
The values chosen so far; lanes no condition has claimed are unspecified until else_.
Definition argon.hpp:253
ace ValueType else_(FunctionType func) const
new_value in the lanes no condition claimed; ends the chain.
Definition argon.hpp:279
A per-lane boolean for vectors of type VectorType, as returned by comparisons.
Definition predicate.hpp:39
ace storage_type native() const
The native predicate representation: a mask vector on NEON, an mve_pred16_t on MVE.
Definition predicate.hpp:133
ace ArgType Select(ArgType true_value, ArgType false_value) const
Choose each lane from true_value where the predicate is active, and from false_value otherwise.
Definition predicate.hpp:189
static constexpr size_t lanes
The number of lanes the predicate covers.
Definition predicate.hpp:54
Represents a SIMD vector with various operations.
Definition vector.hpp:53
constexpr VectorType vec() const
Get the underlying SIMD vector.
Definition vector.hpp:312
static ace argon_type Load(const scalar_type *ptr)
Definition vector.hpp:1095
A scalar type a vector lane can hold: an arithmetic type, or float16_t where half-float vectors exist...
Definition lane_scalar.hpp:31
Concept to check if a type is a vector type (either double-word or quad-word).
Definition concepts.hpp:109
Contains helper templates and concepts for type manipulation and compile-time utilities.
Definition argon.hpp:156
typename ArgonFor< std::remove_cv_t< T > >::type ArgonFor_t
Helper alias to get the Argon type for a given vector type.
Definition argon_for.hpp:46
std::conditional_t< std::is_integral_v< ScalarType > &&std::is_integral_v< simd::Scalar_t< VectorType > > && sizeof(ScalarType)==sizeof(simd::Scalar_t< VectorType >) && std::is_signed_v< ScalarType >==std::is_signed_v< simd::Scalar_t< VectorType > >, simd::Scalar_t< VectorType >, ScalarType > LaneFor_t
The lane type for a ScalarType value used alongside VectorType's lanes.
Definition argon.hpp:161
A 128-bit SIMD vector wrapping a scalar type, providing arithmetic, logical, and data-movement operat...
Definition argon.hpp:30
ace Argon< T > combine(ArgonHalf< T > low, ArgonHalf< T > high)
Combine two double-word vectors into a single quad-word vector.
Definition argon.hpp:133
ace Argon< T > load(const T *ptr)
Load a quad-word vector from a pointer.
Definition argon.hpp:143
ace ScalarType bit_cast(ArgonType in)
Reinterpret a vector of one type to another.
Definition argon.hpp:63
ace std::array< argon_type, 2 > zip(argon_type a, argon_type b)
Zip two vectors together into a pair of output vectors.
Definition argon.hpp:97
std::conditional_t< sizeof(VectorType)==16, Argon< helpers::LaneFor_t< VectorType, ScalarType > >, ArgonHalf< helpers::LaneFor_t< VectorType, ScalarType > > > VectorFor_t
The Argon type holding ScalarType values with the same width as VectorType (Argon or ArgonHalf).
Definition argon.hpp:169
ace std::array< argon_type, 2 > unzip(argon_type a, argon_type b)
Unzip vectors into a pair of output vectors.
Definition argon.hpp:109
ace CondMonad< VectorType, ValueType > if_(Predicate< VectorType > condition, ValueType value)
Start a per-lane if / else-if / else chain: value in the lanes where condition holds.
Definition argon.hpp:292
ace ArgonHalf< T > load_half(const T *ptr)
Load a double-word vector from a pointer.
Definition argon.hpp:152
ace std::array< argon_type, 2 > transpose(argon_type a, argon_type b)
Treats the lanes of its inputs as elements of a 2x2 matrix and transposes the matrices.
Definition argon.hpp:122
ace BranchType ternary(Predicate< VectorType > condition, BranchType true_value, BranchType false_value)
Create a new vector depending on the result of a conditional.
Definition argon.hpp:185
ace auto reinterpret(Vector< V > in)
Reinterpret a vector of one type to another.
Definition argon.hpp:38