8#include "arm_simd/helpers/scalar.hpp"
10#include "helpers/argon_for.hpp"
11#include "helpers/bool.hpp"
12#include "helpers/mve_compare.hpp"
14#ifdef __ARM_FEATURE_MVE
20#ifdef ARGON_PLATFORM_SIMDE
21#define ace [[gnu::always_inline]] inline
23#define ace [[gnu::always_inline]] constexpr
25#define ace [[gnu::always_inline]] inline
38template <
typename VectorType>
40 using scalar_type = simd::Scalar_t<VectorType>;
47#ifdef ARGON_PLATFORM_MVE
54 static constexpr size_t lanes =
sizeof(VectorType) /
sizeof(scalar_type);
61 template <
typename OtherVectorType>
63 sizeof(OtherVectorType) ==
sizeof(VectorType))
68#ifdef ARGON_PLATFORM_MVE
77#ifdef ARGON_PLATFORM_MVE
88#ifdef ARGON_PLATFORM_MVE
89 if constexpr (
sizeof(scalar_type) == 1) {
90 return Predicate{mve::create_tail_predicate8(
static_cast<uint32_t
>(n))};
91 }
else if constexpr (
sizeof(scalar_type) == 2) {
92 return Predicate{mve::create_tail_predicate16(
static_cast<uint32_t
>(n))};
93 }
else if constexpr (
sizeof(scalar_type) == 4) {
94 return Predicate{mve::create_tail_predicate32(
static_cast<uint32_t
>(n))};
96 return Predicate{mve::create_tail_predicate64(
static_cast<uint32_t
>(n))};
102 const auto index = argon_mask_type::Iota(0);
110#ifdef ARGON_PLATFORM_MVE
119#ifdef ARGON_PLATFORM_MVE
127 [[deprecated(
"Comparisons now return argon::Predicate; use ToMask() or the Predicate interface")]]
137#ifdef ARGON_PLATFORM_MVE
146#ifdef ARGON_PLATFORM_MVE
155#ifdef ARGON_PLATFORM_MVE
164#ifdef ARGON_PLATFORM_MVE
165 return Predicate{mve::predicate_not(p_)};
187 template <
typename ArgType>
188 requires(ArgType::lanes ==
lanes &&
sizeof(
typename ArgType::vector_type) ==
sizeof(VectorType))
189 ace ArgType
Select(ArgType true_value, ArgType false_value)
const {
190#ifdef ARGON_PLATFORM_MVE
191 const auto t = std::bit_cast<mask_type>(true_value.vec());
192 const auto f = std::bit_cast<mask_type>(false_value.vec());
193 return ArgType{std::bit_cast<typename ArgType::vector_type>(mve::predicate_select(t, f, p_))};
201#ifdef ARGON_PLATFORM_MVE
204 for (uint64_t word : words()) {
205 if (word != 0)
return true;
213#ifdef ARGON_PLATFORM_MVE
216 for (uint64_t word : words()) {
217 if (word != ~uint64_t{0})
return false;
228#ifdef ARGON_PLATFORM_MVE
229 if constexpr (
sizeof(scalar_type) < 8) {
231 return mve::reduce_add(mve::duplicate(
mask_scalar{1}), p_);
233 return std::popcount(
static_cast<uint16_t
>(p_)) /
sizeof(scalar_type);
237 for (uint64_t word : words()) {
238 bits += std::popcount(word);
240 return bits / (8 *
sizeof(scalar_type));
247#ifdef ARGON_PLATFORM_MVE
248 return (p_ >> (i *
sizeof(scalar_type))) & 1;
250 return std::bit_cast<std::array<mask_scalar, lanes>>(p_)[i] != 0;
256 std::array<bool, lanes> out{};
257 for (
size_t i = 0; i <
lanes; ++i) {
264#ifndef ARGON_PLATFORM_MVE
266 ace std::array<uint64_t,
sizeof(
mask_type) / 8> words()
const {
267 return std::bit_cast<std::array<uint64_t,
sizeof(
mask_type) / 8>>(p_);
static ace Predicate False()
A predicate with no lanes active.
Definition predicate.hpp:76
ace Predicate operator~() const
Invert every lane.
Definition predicate.hpp:163
static ace Predicate True()
A predicate with every lane active.
Definition predicate.hpp:67
helpers::ArgonFor_t< mask_type > argon_mask_type
The Argon type of the mask vector.
Definition predicate.hpp:46
ace std::array< bool, lanes > to_array() const
The active state of every lane, in lane order.
Definition predicate.hpp:255
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
ace Predicate operator||(Predicate b) const
Lanes active in either predicate; the same as |.
Definition predicate.hpp:177
ace argon_mask_type ToMask() const
Expand the predicate into a mask vector: every bit set in active lanes, clear in inactive ones.
Definition predicate.hpp:118
ace Predicate(Predicate< OtherVectorType > other)
Convert from the predicate of another vector type with the same lanes, e.g.
Definition predicate.hpp:64
ace Predicate operator&(Predicate b) const
Lanes active in both predicates.
Definition predicate.hpp:136
simd::Scalar_t< mask_type > mask_scalar
The lane type of the mask vector.
Definition predicate.hpp:45
ace Predicate(storage_type p)
Construct from the native predicate representation (see storage_type).
Definition predicate.hpp:57
ace bool None() const
Whether no lane is active.
Definition predicate.hpp:224
Bool_t< VectorType > mask_type
The equivalent mask vector type.
Definition predicate.hpp:44
ace bool Any() const
Whether any lane is active.
Definition predicate.hpp:200
ace Predicate operator|(Predicate b) const
Lanes active in either predicate.
Definition predicate.hpp:145
ace Predicate operator!() const
Invert every lane; the same as ~.
Definition predicate.hpp:180
ace size_t Count() const
The number of active lanes.
Definition predicate.hpp:227
ace bool All() const
Whether every lane is active.
Definition predicate.hpp:212
static ace Predicate FromMask(argon_mask_type mask)
Construct from a mask vector, treating any nonzero lane as active.
Definition predicate.hpp:109
static constexpr size_t lanes
The number of lanes the predicate covers.
Definition predicate.hpp:54
ace Predicate operator^(Predicate b) const
Lanes active in exactly one of the predicates.
Definition predicate.hpp:154
ace Predicate operator&&(Predicate b) const
Lanes active in both predicates; the same as &.
Definition predicate.hpp:173
VectorType vector_type
The vector type the predicate applies to.
Definition predicate.hpp:43
mask_type storage_type
The native predicate representation.
Definition predicate.hpp:50
static ace Predicate FirstN(size_t n)
A predicate with the first n lanes active, and the rest inactive.
Definition predicate.hpp:87
ace bool Active(size_t i) const
Whether a single lane is active.
Definition predicate.hpp:246
Header file for SIMD features and platform detection.
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
A 128-bit SIMD vector wrapping a scalar type, providing arithmetic, logical, and data-movement operat...
Definition argon.hpp:30
Bool< T >::type Bool_t
Helper alias to get the boolean type of a SIMD operation.
Definition bool.hpp:49