Argon 0.1.0
Loading...
Searching...
No Matches
vector.hpp
1#pragma once
2#include <array>
3#include <bit>
4#include <cmath>
5#include <functional>
6#include <tuple>
7#include <type_traits>
8#include <utility>
9#include "arm_simd.hpp"
10#include "arm_simd/helpers.hpp"
11#include "arm_simd/helpers/multivector.hpp"
12#include "arm_simd/helpers/scalar.hpp"
13#include "arm_simd/helpers/vec64.hpp"
14#include "features.h"
15#include "helpers.hpp"
16#include "helpers/bool.hpp"
17#include "helpers/float_fixups.hpp"
18#include "helpers/mve_compare.hpp"
19#include "helpers/to_array.hpp"
20#include "lane.hpp"
21#include "predicate.hpp"
22
23#ifdef __ARM_FEATURE_MVE
24#define simd mve
25#else
26#define simd neon
27#endif
28
29#ifdef ARGON_PLATFORM_SIMDE
30#define ace [[gnu::always_inline]] inline
31#elifdef __clang__
32#define ace [[gnu::always_inline]] constexpr
33#else
34#define ace [[gnu::always_inline]] inline
35#endif
36
37namespace argon {
38template <typename T>
40
45template <typename T, typename... Ts>
46inline constexpr bool is_one_of = std::disjunction_v<std::is_same<T, Ts>...>;
47
52template <typename VectorType>
53class Vector {
54 public:
55 template <size_t LaneIndex>
58 using scalar_type = simd::Scalar_t<VectorType>;
59
61 static constexpr bool extension_arithmetic =
62 ARGON_USE_COMPILER_EXTENSIONS && !(ARGON_GCC_AARCH32_FLOAT && std::is_floating_point_v<scalar_type>);
63#ifdef ARGON_PLATFORM_MVE
64 static constexpr bool mve_platform = true;
65#else
66 static constexpr bool mve_platform = false;
67#endif
77 static constexpr bool fixup_float_compare = ARGON_GCC_AARCH32_FLOAT && std::is_same_v<scalar_type, float>;
78 using vector_type = VectorType;
80 using mask_type =
82 using predicate_type
83 [[deprecated("predicate_type is the mask vector type; use mask_type, or argon_bool_type for "
84 "the Predicate comparisons return")]] = mask_type;
88
90 static constexpr size_t lanes = (simd::is_quadword_v<VectorType> ? 16 : 8) / sizeof(scalar_type);
91
93 constexpr Vector() = default;
94
95 constexpr Vector(Vector&& other) = default;
96 constexpr Vector(const Vector& other) = default;
97 constexpr Vector& operator=(Vector&& other) = default;
98 constexpr Vector& operator=(const Vector& other) = default;
99
102 ace Vector(VectorType vector) : vec_{std::move(vector)} {};
103
109 ace Vector(scalar_type scalar)
110 requires(!std::is_same_v<scalar_type, VectorType>)
111 : vec_(FromScalar(scalar)) {};
112
116 ace Vector(argon::Lane<VectorType> lane) : vec_(FromLane(lane)) {};
117
122 template <size_t LaneIndex>
124
128 template <typename... ArgTypes>
129 requires(sizeof...(ArgTypes) > 1)
130 ace Vector(ArgTypes... args) : vec_{LaneValue(std::forward<ArgTypes>(args))...} {}
131
137 ace static argon_type LoadScalar(const scalar_type* ptr) { return LoadCopy(ptr); }
138
143 ace static argon_type FromScalar(scalar_type scalar) {
144#ifdef ARGON_PLATFORM_MVE
145 return simd::duplicate(scalar);
146#else
147 return simd::duplicate<VectorType>(scalar);
148#endif
149 }
150
155 template <simd::is_vector_type IntrinsicType>
157#ifdef ARGON_PLATFORM_MVE
158 return simd::duplicate(lane.Get());
159#else
160 return simd::duplicate_lane<vector_type>(lane.vec(), lane.lane());
161#endif
162 }
163
168 template <size_t LaneIndex>
170#ifdef ARGON_PLATFORM_MVE
171 return simd::duplicate(lane.Get());
172#else
173 if constexpr (simd::is_quadword_v<VectorType>) {
174#if __ARM_ARCH >= 8
175 return simd::duplicate_lane_quad<LaneIndex>(lane.vec());
176#else
177 // On A32, vec() returns the 64-bit half-register (low or high).
178 // The template arg must be the lane index within that half-vector.
179 constexpr size_t local_lane = LaneIndex >= (lanes / 2) ? LaneIndex - (lanes / 2) : LaneIndex;
180 return simd::duplicate_lane_quad<local_lane>(lane.vec());
181#endif
182 } else {
183 return simd::duplicate_lane<LaneIndex>(lane.vec());
184 }
185#endif
186 }
187
194 ace static argon_type Iota(scalar_type start) {
195 // TODO: Remove this once MSVC 19.44 is released.
196#if __cpp_if_consteval >= 202106L
197 return IotaHelper(start, std::make_index_sequence<lanes>{});
198#else
199 return Argon{start}.Add(VectorType{0, 1, 2, 3});
200#endif
201 }
202
207 template <typename FuncType>
208 requires std::convertible_to<FuncType, std::function<scalar_type()>>
209 ace static argon_type Generate(FuncType body) {
210 // Build via a scalar array + Load rather than subscripting the raw vector:
211 // MSVC's SIMDe vector types are structs with no operator[].
212 std::array<scalar_type, lanes> out;
213 utility::constexpr_for<0, lanes, 1>([&]<size_t i>() { //
214 out[i] = body();
215 });
216 return Load(out.data());
217 }
218
224 template <typename FuncType>
225 requires std::convertible_to<FuncType, std::function<scalar_type(scalar_type)>>
226 ace static argon_type GenerateWithIndex(FuncType body) {
227 // Build via a scalar array + Load rather than subscripting the raw vector:
228 // MSVC's SIMDe vector types are structs with no operator[].
229 std::array<scalar_type, lanes> out;
230 utility::constexpr_for<0, lanes, 1>([&]<size_t i>() { //
231 out[i] = body(i);
232 });
233 return Load(out.data());
234 }
235
237 ace argon_type operator-() const { return Negate(); }
238
240 ace argon_type operator+(argon_type b) const { return Add(b); }
241
243 ace argon_type operator-(argon_type b) const { return Subtract(b); }
244
246 ace argon_type operator*(argon_type b) const { return Multiply(b); }
247
249 ace argon_type operator/(argon_type b) const { return Divide(b); }
250
252 ace argon_bool_type operator==(argon_type b) const { return Equal(b); }
253
255 ace argon_bool_type operator!=(argon_type b) const { return ~Equal(b); }
256
258 ace argon_bool_type operator<(argon_type b) const { return LessThan(b); }
259
262
265
268
270 ace argon_type operator++() const { return Add(1); }
271
273 ace argon_type operator--() const { return Subtract(1); }
274
276 ace argon_type operator&(argon_type b) const { return BitwiseAnd(b); }
277
279 ace argon_type operator|(argon_type b) const { return BitwiseOr(b); }
280
282 ace argon_type operator^(argon_type b) const { return BitwiseXor(b); }
283
285 ace argon_type operator~() const { return BitwiseNot(); }
286
288 ace Lane<const VectorType> operator[](const size_t i) const { return GetLane(i); }
289
291 ace lane_type operator[](const size_t i) { return GetLane(i); }
292
294 ace argon_type operator>>(const int i) const {
295#if ARGON_USE_COMPILER_EXTENSIONS
296 return vec_ >> i;
297#else
298 return ShiftRight(i);
299#endif
300 }
301
303 ace argon_type operator<<(const int i) const {
304#if ARGON_USE_COMPILER_EXTENSIONS
305 return vec_ << i;
306#else
307 return ShiftLeft(i);
308#endif
309 }
310
312 [[gnu::always_inline]] constexpr VectorType vec() const { return vec_; }
313
315 [[gnu::always_inline]] constexpr operator VectorType() const { return vec_; }
316
319 ace std::array<scalar_type, lanes> to_array() const {
320 std::array<scalar_type, lanes> out;
321 simd::store1(out.data(), vec_);
322 return out;
323 }
324
329 ace Lane<const VectorType> GetLane(const size_t i) const { return {vec_, static_cast<int>(i)}; }
330 ace lane_type GetLane(const size_t i) { return {vec_, static_cast<int>(i)}; }
331
335 ace Lane<const VectorType> GetLane(const int i) const { return {vec_, i}; }
336
337 ace lane_type GetLane(const int i) { return {vec_, i}; }
338
342 template <size_t LaneIndex>
344 return vec_;
345 }
346
347 template <size_t LaneIndex>
349 return vec_;
350 }
351
353 ace const_lane_type<lanes - 1> LastLane() { return vec_; }
354
358 ace argon_type ShiftRight(const int i) const {
359 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
360 return vec_ >> i;
361 } else {
362 return ShiftByVector(-i);
363 }
364 }
365
367 ace argon_type ShiftLeft(const int i) const {
368 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
369 return vec_ << i;
370 } else {
371 return ShiftByVector(i);
372 }
373 }
374
376 ace argon_type Negate() const {
377 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
378 return -vec_;
379 } else if constexpr (std::is_unsigned_v<scalar_type>) {
380 return argon_type{scalar_type{0}}.Subtract(argon_type{vec_}); // NEON has no unsigned vneg: 0 - a wraps
381 } else {
382 return simd::negate(vec_);
383 }
384 }
385
387 ace argon_type Add(argon_type b) const {
388 if constexpr (extension_arithmetic) {
389 return vec_ + b.vec_;
390 } else {
391 return simd::add(vec_, b);
392 }
393 }
394
397 ace argon_type AddHalve(argon_type b) const { return simd::add_halve(vec_, b); }
398
401 ace argon_type AddHalveRound(argon_type b) const { return simd::add_halve_round(vec_, b); }
402
406 ace argon_type AddSaturate(argon_type b) const { return simd::add_saturate(vec_, b); }
407
410 if constexpr (extension_arithmetic) {
411 return vec_ - b.vec_;
412 } else {
413 return simd::subtract(vec_, b);
414 }
415 }
416
419 ace argon_type SubtractHalve(argon_type b) const { return simd::subtract_halve(vec_, b); }
420
422 ace argon_type SubtractSaturate(argon_type b) const { return simd::subtract_saturate(vec_, b); }
423
426 ace argon_type SubtractAbs(argon_type b) const { return simd::subtract_absolute(vec_, b); }
427
431#ifdef ARGON_PLATFORM_MVE
432 return mve::add(vec_, mve::subtract_absolute(b, c));
433#else
434 return neon::subtract_absolute_add(vec_, b, c);
435#endif
436 }
437
440 if constexpr (extension_arithmetic) {
441 return vec_ * b.vec_;
442 } else if constexpr (std::is_integral_v<scalar_type> && sizeof(scalar_type) == 8) {
443 // NEON has no 64-bit lane multiply: lane by lane.
444 auto x = argon_type{vec_}.to_array();
445 const auto y = b.to_array();
446 for (size_t i = 0; i < x.size(); ++i)
447 x[i] *= y[i];
448 return argon_type::Load(x.data());
449 } else {
450 return simd::multiply(vec_, b);
451 }
452 }
453
456 if constexpr (extension_arithmetic) {
457 return vec_ * b;
458 } else {
459 return simd::multiply(vec_, b);
460 }
461 }
462
463#ifndef ARGON_PLATFORM_MVE
465 ace argon_type Multiply(lane_type b) const { return neon::multiply_lane(vec_, b.vec(), b.lane()); }
466
468 template <size_t LaneIndex>
470 return neon::multiply_lane(vec_, b.vec(), b.lane());
471 }
472#endif
473
478#ifdef ARGON_PLATFORM_MVE
479 if constexpr (mve_float) {
480 return simd::multiply_add_fused(vec_, b.vec_, c.vec_);
481 } else
482#endif
483 if constexpr (extension_arithmetic) {
484 return vec_ + b.vec_ * c.vec_;
485 } else {
486 return simd::multiply_add(vec_, b, c);
487 }
488 }
489
493#ifdef ARGON_PLATFORM_MVE
494 if constexpr (mve_float) {
495 return simd::multiply_add_fused(vec_, b.vec_, c);
496 } else
497#endif
498 if constexpr (extension_arithmetic) {
499 if constexpr (is_half_float_v<scalar_type>) {
500 return vec_ + b.vec_ * argon_type{c}.vec_; // a half scalar promotes to float against the vector
501 } else {
502 return vec_ + b.vec_ * c;
503 }
504 } else {
505 return simd::multiply_add(vec_, b, c);
506 }
507 }
508
511 ace argon_type MultiplyAdd(scalar_type b, argon_type c) const { return MultiplyAdd(c, b); }
512
513#ifndef ARGON_PLATFORM_MVE
517 return simd::multiply_add_lane(vec_, b.vec(), c.vec(), c.lane());
518 }
519
522 ace argon_type MultiplyAdd(lane_type b, argon_type c) const { return MultiplyAdd(c, b); }
523
526 template <size_t LaneIndex>
528 return simd::multiply_add_lane(vec_, b.vec(), c.vec(), c.lane());
529 }
530
532 template <size_t LaneIndex>
534 return MultiplyAdd(c, b);
535 }
536#endif
537
541#ifdef ARGON_PLATFORM_MVE
542 if constexpr (mve_float) {
543 return simd::multiply_subtract_fused(vec_, b.vec_, c.vec_);
544 } else {
545 return vec_ - b.vec_ * c.vec_; // MVE has no integer vector multiply-subtract
546 }
547#else
548 if constexpr (extension_arithmetic) {
549 return vec_ - b.vec_ * c.vec_;
550 } else {
551 return simd::multiply_subtract(vec_, b, c);
552 }
553#endif
554 }
555
559#ifdef ARGON_PLATFORM_MVE
560 if constexpr (mve_float) {
561 return simd::multiply_subtract_fused(vec_, b.vec_, simd::duplicate(c)); // MVE has no vfms by a scalar
562 } else {
563 return vec_ - b.vec_ * c; // MVE has no integer vector multiply-subtract
564 }
565#else
566 if constexpr (extension_arithmetic) {
567 if constexpr (is_half_float_v<scalar_type>) {
568 return vec_ - b.vec_ * argon_type{c}.vec_; // a half scalar promotes to float against the vector
569 } else {
570 return vec_ - b.vec_ * c;
571 }
572 } else {
573 return simd::multiply_subtract(vec_, b, c);
574 }
575#endif
576 }
577
581
582#if ARGON_HAS_FUSED_MULTIPLY_ADD
587 ace argon_type MultiplyAddFused(argon_type b, argon_type c) const
588 requires std::same_as<scalar_type, float>
589 {
590 return simd::multiply_add_fused(vec_, b.vec_, c.vec_);
591 }
592
595 ace argon_type MultiplyAddFused(argon_type b, scalar_type c) const
596 requires std::same_as<scalar_type, float>
597 {
598 return simd::multiply_add_fused(vec_, b.vec_, c);
599 }
600
603 ace argon_type MultiplySubtractFused(argon_type b, argon_type c) const
604 requires std::same_as<scalar_type, float>
605 {
606 return simd::multiply_subtract_fused(vec_, b.vec_, c.vec_);
607 }
608
611 ace argon_type MultiplySubtractFused(argon_type b, scalar_type c) const
612 requires std::same_as<scalar_type, float>
613 {
614#ifdef ARGON_PLATFORM_MVE
615 return simd::multiply_subtract_fused(vec_, b.vec_, simd::duplicate(c)); // MVE has no vfms by a scalar
616#else
617 return simd::multiply_subtract_fused(vec_, b.vec_, c);
618#endif
619 }
620#endif
621
622#ifndef ARGON_PLATFORM_MVE
626 return simd::multiply_subtract_lane(vec_, b.vec(), c.vec(), c.lane());
627 }
628#endif
629
632 ace argon_type MultiplyFixedQMax(argon_type v) const { return simd::multiply_double_saturate_high(vec_, v); }
633
636 ace argon_type MultiplyFixedQMax(scalar_type s) const { return simd::multiply_double_saturate_high(vec_, s); }
637
638#ifndef ARGON_PLATFORM_MVE
642 return simd::multiply_double_saturate_high_lane(vec_, l.vec(), l.lane());
643 }
644#endif
645
649 return simd::multiply_double_round_saturate_high(vec_, v);
650 }
651
655 return simd::multiply_double_round_saturate_high(vec_, s);
656 }
657
658#ifndef ARGON_PLATFORM_MVE
662 return simd::multiply_double_round_saturate_high_lane(vec_, l.vec(), l.lane());
663 }
664#endif
665
669 ace argon_type Absolute() const { return simd::abs(vec_); }
670
675 requires lane_floating_point<scalar_type> || (std::is_same_v<scalar_type, uint32_t> && !mve_platform)
676 {
677#ifdef ARGON_PLATFORM_MVE
678 return 1.f / vec_;
679#else
680 return simd::reciprocal_estimate(vec_);
681#endif
682 }
683
688 requires lane_floating_point<scalar_type> || (std::is_same_v<scalar_type, uint32_t> && !mve_platform)
689 {
690#ifdef ARGON_PLATFORM_MVE
691 // MVE has no vrsqrte: take the bit-level initial guess, then one Newton-Raphson step, which lands within NEON's
692 // estimate precision (~1/256).
693 const auto bits = std::bit_cast<Bool_t<VectorType>>(vec_);
694 const VectorType guess = std::bit_cast<VectorType>(0x5f3759dfu - (bits >> 1));
695 return guess * (1.5f - 0.5f * vec_ * guess * guess);
696#else
697 return simd::reciprocal_sqrt_estimate(vec_);
698#endif
699 }
700
706 {
707#ifdef ARGON_PLATFORM_MVE
708 return 2.f - vec_ * b.vec_;
709#else
710 return simd::reciprocal_step(vec_, b.vec_);
711#endif
712 }
713
719 {
720#ifdef ARGON_PLATFORM_MVE
721 return (3.f - vec_ * b.vec_) * 0.5f;
722#else
723 return simd::reciprocal_sqrt_step(vec_, b.vec_);
724#endif
725 }
726
730 ace argon_type ReciprocalEstimateRefine(int n_iters = 1) const
732 {
734 for (int i = 0; i < n_iters; ++i) {
735 est = est * ReciprocalStep(est);
736 }
737 return est;
738 }
739
743 ace argon_type ReciprocalSqrtEstimateRefine(int n_iters = 1) const
745 {
747 for (int i = 0; i < n_iters; ++i) {
748 est = est * (*this * est).ReciprocalSqrtStep(est);
749 }
750 return est;
751 }
752
755 template <typename arg_type>
756 requires(is_one_of<arg_type, argon_type, scalar_type, lane_type> || std::is_convertible_v<arg_type, argon_type> ||
757 std::is_convertible_v<arg_type, scalar_type>)
758 ace argon_type MultiplyAddFixedQMax(argon_type b, arg_type c) const {
759 return Add(b.MultiplyFixedQMax(c));
760 }
761
764 template <typename arg_type>
765 requires(is_one_of<arg_type, argon_type, scalar_type, lane_type> || std::is_convertible_v<arg_type, argon_type> ||
766 std::is_convertible_v<arg_type, scalar_type>)
768 return Add(b.MultiplyRoundFixedQMax(c));
769 }
770
771#ifdef __aarch64__
773 ace argon_type Divide(argon_type b) const {
774 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
775 return vec_ / b.vec_;
776 } else {
777 return simd::divide(vec_, b);
778 }
779 }
780#else
783 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
784 return vec_ / b.vec_;
785 } else {
786 return this->map2(b, [](scalar_type lane1, scalar_type lane2) { return lane1 / lane2; });
787 }
788 }
789#endif
790
794 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
795 return vec_ % b.vec_;
796 } else if constexpr (lane_floating_point<scalar_type>) {
797 return this->map2(b, [](scalar_type lane1, scalar_type lane2) { return std::fmod(lane1, lane2); });
798 } else {
799 return this->map2(b, [](scalar_type lane1, scalar_type lane2) { return lane1 % lane2; });
800 }
801 }
802
806 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
807 return vec_ % b;
808 } else {
809 return this->map([b](scalar_type lane1) { return std::fmod(lane1, b); });
810 }
811 }
812
821 ace argon_type Max(argon_type b) const {
822#ifdef ARGON_PLATFORM_MVE
823 if constexpr (mve_float) {
824 // GCC scalarises vector-extension float ?: on MVE; vcmp + vpsel keeps a > b ? a : b (vmaxnm would not).
825 return simd::predicate_select(vec_, b.vec_,
826 helpers::mve_compare<helpers::MveComparison::GreaterThan>(vec_, b.vec_));
827 } else
828#endif
829 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
830 return vec_ > b.vec_ ? vec_ : b.vec_;
831 } else if constexpr (lane_floating_point<scalar_type>) {
832 // vmax/vmin return NaN for a NaN in either lane; keep a > b ? a : b.
833 return (argon_type{vec_} > b).Select(argon_type{vec_}, b);
834 } else {
835 return simd::max(vec_, b);
836 }
837 }
838
842 ace argon_type Min(argon_type b) const {
843#ifdef ARGON_PLATFORM_MVE
844 if constexpr (mve_float) {
845 return simd::predicate_select(vec_, b.vec_,
846 helpers::mve_compare<helpers::MveComparison::GreaterThan>(b.vec_, vec_));
847 } else
848#endif
849 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
850 return vec_ < b.vec_ ? vec_ : b.vec_;
851 } else if constexpr (lane_floating_point<scalar_type>) {
852 // vmax/vmin return NaN for a NaN in either lane; keep a < b ? a : b.
853 return (argon_type{vec_} < b).Select(argon_type{vec_}, b);
854 } else {
855 return simd::min(vec_, b);
856 }
857 }
858
870 {
871#if ARGON_HAS_MAXNM
872 if constexpr (native_maxnm) {
873 return simd::max_strict(vec_, b.vec_);
874 } else
875#endif
876 {
877 return NumberMinMax<true>(b);
878 }
879 }
880
887 {
888#if ARGON_HAS_MAXNM
889 if constexpr (native_maxnm) {
890 return simd::min_strict(vec_, b.vec_);
891 } else
892#endif
893 {
894 return NumberMinMax<false>(b);
895 }
896 }
897
899 template <bool max>
901 using bits_type = std::conditional_t<sizeof(scalar_type) == 2, uint16_t,
902 std::conditional_t<sizeof(scalar_type) == 4, uint32_t, uint64_t>>;
903 const argon_type a{vec_};
904 argon_type r = max ? (a > b).Select(a, b) : (a < b).Select(a, b); // NaN in a: b
905 const auto a_bits = a.template As<bits_type>(), b_bits = b.template As<bits_type>();
906 const argon_type zeros = (max ? (a_bits & b_bits) : (a_bits | b_bits)).template As<scalar_type>();
907 r = (a == b).Select(zeros, r); // equal lanes: the same value, or zeros of either sign (+0 & -0 is +0)
908 return (b == b).Select(r, a); // NaN in b: a (NaN only if a is too)
909 }
910
913#ifdef ARGON_PLATFORM_MVE
914 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::Equal>(vec_, b.vec_)};
915#else
916 return argon_bool_type{simd::equal(vec_, b.vec_)};
917#endif
918 }
919
922#ifdef ARGON_PLATFORM_MVE
923 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::GreaterThanOrEqual>(vec_, b.vec_)};
924#else
925#if ARGON_GCC_AARCH32_FLOAT
926 if constexpr (fixup_float_compare)
927 return argon_bool_type{helpers::greater_than_or_equal(vec_, b.vec_)};
928#endif
929 return argon_bool_type{simd::greater_than_or_equal(vec_, b.vec_)};
930#endif
931 }
932
935#ifdef ARGON_PLATFORM_MVE
936 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::GreaterThanOrEqual>(b.vec_, vec_)};
937#else
938#if ARGON_GCC_AARCH32_FLOAT
939 if constexpr (fixup_float_compare)
940 return argon_bool_type{helpers::greater_than_or_equal(b.vec_, vec_)};
941#endif
942 return argon_bool_type{simd::less_than_or_equal(vec_, b.vec_)};
943#endif
944 }
945
948#ifdef ARGON_PLATFORM_MVE
949 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::GreaterThan>(vec_, b.vec_)};
950#else
951#if ARGON_GCC_AARCH32_FLOAT
952 if constexpr (fixup_float_compare)
953 return argon_bool_type{helpers::greater_than(vec_, b.vec_)};
954#endif
955 return argon_bool_type{simd::greater_than(vec_, b.vec_)};
956#endif
957 }
958
961#ifdef ARGON_PLATFORM_MVE
962 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::GreaterThan>(b.vec_, vec_)};
963#else
964#if ARGON_GCC_AARCH32_FLOAT
965 if constexpr (fixup_float_compare)
966 return argon_bool_type{helpers::greater_than(b.vec_, vec_)};
967#endif
968 return argon_bool_type{simd::less_than(vec_, b.vec_)};
969#endif
970 }
971
975 requires std::is_integral_v<scalar_type>
976 {
977 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
978 return vec_ << b.vec_;
979 } else {
980 return simd::shift_left(vec_, b.vec_);
981 }
982 }
983
986 ace argon_type ShiftLeft(std::make_signed_t<simd::Scalar_t<Bool_t<VectorType>>> n) const
987 requires std::is_integral_v<scalar_type>
988 {
989 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
990 return vec_ << n;
991 } else {
993 return simd::shift_left(vec_, b.vec_);
994 }
995 }
996
998 ace argon_type ShiftByVector(int count) const
999 requires std::is_integral_v<scalar_type>
1000 {
1001 using signed_scalar = std::make_signed_t<scalar_type>;
1002 const helpers::ArgonFor_t<simd::make_signed_t<VectorType>> b{static_cast<signed_scalar>(count)};
1003 return simd::shift_left(vec_, b.vec());
1004 }
1005
1008 template <int n>
1009 ace argon_type ShiftLeft() const {
1010 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1011 return vec_ << n;
1012 } else {
1013 return simd::shift_left<n>(vec_);
1014 }
1015 }
1016
1019 requires(std::is_integral_v<scalar_type>)
1020 {
1021 return simd::shift_left_saturate(vec_, b);
1022 }
1023
1025 ace argon_type ShiftLeftRound(argon_type b) const { return simd::shift_left_round(vec_, b); }
1026
1028 ace argon_type ShiftLeftRoundSaturate(argon_type b) const { return simd::shift_left_round_saturate(vec_, b); }
1029
1031 template <int n>
1033 return simd::shift_left_saturate<n>(vec_);
1034 }
1035
1041 template <int n>
1043 return simd::shift_left_insert<n>(vec_, b);
1044 }
1045
1047 template <int n>
1049 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1050 return vec_ >> n;
1051 } else {
1052 return simd::shift_right<n>(vec_);
1053 }
1054 }
1055
1057 template <int n>
1059 return simd::shift_right_round<n>(vec_);
1060 }
1061
1065 template <int n>
1067#ifdef ARGON_PLATFORM_MVE
1068 return vec_ + (b >> n).vec();
1069#else
1070 return simd::shift_right_accumulate<n>(vec_, b);
1071#endif
1072 }
1073
1077 template <int n>
1079#ifdef ARGON_PLATFORM_MVE
1080 return vec_ + mve::shift_right_round<n>(b.vec());
1081#else
1082 return simd::shift_right_accumulate_round<n>(vec_, b);
1083#endif
1084 }
1085
1089 template <int n>
1091 return simd::shift_right_insert<n>(vec_, b);
1092 }
1093
1095 ace static argon_type Load(const scalar_type* ptr) {
1096#ifdef ARGON_PLATFORM_MVE
1097 return mve::load1(ptr);
1098#else
1099 return neon::load1<VectorType>(ptr);
1100#endif
1101 }
1102
1104 ace static argon_type LoadCopy(const scalar_type* ptr) {
1105#ifdef ARGON_PLATFORM_MVE
1106 return simd::duplicate(*ptr);
1107#else
1108 return simd::load1_duplicate<VectorType>(ptr);
1109#endif
1110 }
1111
1116 ace static argon_type Load(const scalar_type* ptr, argon_bool_type active) {
1117#ifdef ARGON_PLATFORM_MVE
1118 return mve::load1(ptr, active.native());
1119#else
1120 argon_type destination{scalar_type{0}};
1121 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1122 if (active.Active(i)) {
1123 destination = destination.template LoadToLane<i>(ptr + i);
1124 }
1125 });
1126 return destination;
1127#endif
1128 }
1129
1135 ace static argon_type LoadGatherOffsetBytes(const scalar_type* base, offset_type offsets) {
1136 return Gather<true>(base, offsets);
1137 }
1138
1144 return Gather<true>(base, offsets, active);
1145 }
1146
1152 ace static argon_type LoadGatherOffsetIndex(const scalar_type* base, offset_type offsets) {
1153 return Gather<false>(base, offsets);
1154 }
1155
1161 return Gather<false>(base, offsets, active);
1162 }
1163
1167 template <size_t lane>
1169 return ConstLane<lane, VectorType>{vec_}.Load(ptr);
1170 }
1171
1178 template <size_t stride>
1179 ace static std::array<argon_type, stride> LoadInterleaved(const scalar_type* ptr) {
1180#ifdef ARGON_PLATFORM_MVE
1181 static_assert(stride > 1 && stride < 5, "De-interleaving Loads can only be performed with a stride of 2, 3, or 4");
1182 if constexpr (stride == 2) {
1183 return argon::to_array(mve::load2(ptr).val);
1184 } else if constexpr (stride == 3) {
1185 // MVE has no vld3; gather each channel at indices {0, 3, 6, ...} instead.
1186 const offset_type offsets = offset_type::Iota(0) * 3;
1187 return {LoadGatherOffsetIndex(ptr, offsets), LoadGatherOffsetIndex(ptr + 1, offsets),
1188 LoadGatherOffsetIndex(ptr + 2, offsets)};
1189 } else if constexpr (stride == 4) {
1190 return argon::to_array(mve::load4(ptr).val);
1191 }
1192#else
1193 static_assert(stride > 1 && stride < 5, "De-interleaving Loads can only be performed with a stride of 2, 3, or 4");
1194 using multivec_type = simd::MultiVector_t<VectorType, stride>;
1195 if constexpr (stride == 2) {
1196 return argon::to_array(neon::load2<multivec_type>(ptr).val);
1197 } else if constexpr (stride == 3) {
1198 return argon::to_array(neon::load3<multivec_type>(ptr).val);
1199 } else if constexpr (stride == 4) {
1200 return argon::to_array(neon::load4<multivec_type>(ptr).val);
1201 }
1202#endif
1203 }
1204
1210 template <size_t stride>
1211 ace static std::array<argon_type, stride> LoadCopyInterleaved(const scalar_type* ptr) {
1212#ifdef ARGON_PLATFORM_MVE
1213 static_assert(stride == 2 || stride == 4,
1214 "De-interleaving LoadCopy can only be performed with a stride of 2, 3, or 4");
1215 if constexpr (stride == 2) {
1216 return {mve::duplicate(*ptr++), mve::duplicate(*ptr++)};
1217 } else if constexpr (stride == 4) {
1218 return {mve::duplicate(*ptr++), mve::duplicate(*ptr++), mve::duplicate(*ptr++), mve::duplicate(*ptr)};
1219 }
1220#else
1221 static_assert(stride > 1 && stride < 5,
1222 "De-interleaving LoadCopy can only be performed with a stride of 2, 3, or 4");
1223 using multivec_type = simd::MultiVector<VectorType, stride>::type;
1224 if constexpr (stride == 2) {
1225 return argon::to_array(simd::load2_duplicate<multivec_type>(ptr).val);
1226 } else if constexpr (stride == 3) {
1227 return argon::to_array(simd::load3_duplicate<multivec_type>(ptr).val);
1228 } else if constexpr (stride == 4) {
1229 return argon::to_array(simd::load4_duplicate<multivec_type>(ptr).val);
1230 }
1231#endif
1232 }
1233
1240 template <size_t LaneIndex, size_t Stride>
1241 ace static std::array<argon_type, Stride> LoadToLaneInterleaved(simd::MultiVector_t<VectorType, Stride> multi,
1242 const scalar_type* ptr) {
1243 static_assert(Stride > 1 && Stride < 5, "De-interleaving Loads can only be performed with a stride of 2, 3, or 4");
1244#ifdef ARGON_PLATFORM_MVE
1245 auto out = multi;
1246 utility::constexpr_for<0, Stride, 1>([&]<int i>() { //<
1247 out.val[i][LaneIndex] = ptr[i];
1248 });
1249 return argon::to_array(out.val);
1250#else
1251 if constexpr (Stride == 2) {
1252 if constexpr (simd::is_quadword_v<VectorType>) {
1253 return argon::to_array(simd::load2_lane_quad<LaneIndex>(ptr, multi).val);
1254 } else {
1255 return argon::to_array(simd::load2_lane<LaneIndex>(ptr, multi).val);
1256 }
1257 } else if constexpr (Stride == 3) {
1258 if constexpr (simd::is_quadword_v<VectorType>) {
1259 return argon::to_array(simd::load3_lane_quad<LaneIndex>(ptr, multi).val);
1260 } else {
1261 return argon::to_array(simd::load3_lane<LaneIndex>(ptr, multi).val);
1262 }
1263 } else if constexpr (Stride == 4) {
1264 if constexpr (simd::is_quadword_v<VectorType>) {
1265 return argon::to_array(simd::load4_lane_quad<LaneIndex>(ptr, multi).val);
1266 } else {
1267 return argon::to_array(simd::load4_lane<LaneIndex>(ptr, multi).val);
1268 }
1269 }
1270#endif
1271 }
1272
1274 template <size_t lane, size_t stride>
1275 ace static std::array<argon_type, stride> LoadToLaneInterleaved(std::array<argon_type, stride> multi,
1276 const scalar_type* ptr) {
1277 using multivec_type = simd::MultiVector_t<VectorType, stride>;
1278 return LoadToLaneInterleaved<lane, stride>(*(multivec_type*)multi.data(), ptr);
1279 }
1280
1291 template <size_t stride>
1292 ace static std::array<argon_type, stride> LoadGatherOffsetIndexInterleaved(
1293 const scalar_type* base_ptr,
1294 helpers::ArgonFor_t<simd::make_unsigned_t<Bool_t<VectorType>>> offset_vector) {
1295 static_assert(stride > 1 && stride < 5, "De-interleaving Loads can only be performed with a stride of 2, 3, or 4");
1296 std::array<argon_type, stride> multi{};
1297 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1298 auto lane_val = simd::get_lane<i>(offset_vector);
1299 multi = LoadToLaneInterleaved<i, stride>(multi, base_ptr + (lane_val * stride));
1300 });
1301 return multi;
1302 }
1303
1311 template <size_t n>
1312 ace static std::array<argon_type, n> LoadMulti(const scalar_type* ptr) {
1313 static_assert(n > 1 && n < 5, "LoadMulti can only be performed with a size of 2, 3, or 4");
1314#ifdef ARGON_PLATFORM_MVE
1315 std::array<argon_type, n> multi{};
1316 utility::constexpr_for<0, n, 1>([&]<int i>() { //<
1317 multi[i] = Load(ptr);
1318 ptr += lanes;
1319 });
1320 return multi;
1321#else
1322#if defined(__clang__) || (__GNUC__ > 13)
1323 using multi_type = simd::MultiVector_t<VectorType, n>;
1324 if constexpr (n == 2) {
1325 return argon::to_array(simd::load1_x2<multi_type>(ptr).val);
1326 } else if constexpr (n == 3) {
1327 return argon::to_array(simd::load1_x3<multi_type>(ptr).val);
1328 } else if constexpr (n == 4) {
1329 return argon::to_array(simd::load1_x4<multi_type>(ptr).val);
1330 }
1331#else
1332 // load1 is a return-type-only template, so the element type must be named
1333 // explicitly — `simd::load1(ptr)` cannot deduce it (fails to compile on MSVC).
1334 if constexpr (n == 2) {
1335 auto a = simd::load1<VectorType>(ptr);
1336 auto b = simd::load1<VectorType>(ptr + lanes);
1337 return {a, b};
1338 } else if constexpr (n == 3) {
1339 auto a = simd::load1<VectorType>(ptr);
1340 auto b = simd::load1<VectorType>(ptr + lanes);
1341 auto c = simd::load1<VectorType>(ptr + 2 * lanes);
1342 return {a, b, c};
1343 } else if constexpr (n == 4) {
1344 auto a = simd::load1<VectorType>(ptr);
1345 auto b = simd::load1<VectorType>(ptr + lanes);
1346 auto c = simd::load1<VectorType>(ptr + 2 * lanes);
1347 auto d = simd::load1<VectorType>(ptr + 3 * lanes);
1348 return {a, b, c, d};
1349 }
1350#endif
1351#endif
1352 }
1353
1356 ace void StoreTo(scalar_type* ptr) const { simd::store1(ptr, vec_); }
1357
1362 ace void StoreTo(scalar_type* ptr, argon_bool_type active) const {
1363#ifdef ARGON_PLATFORM_MVE
1364 mve::store1(ptr, vec_, active.native());
1365#else
1366 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1367 if (active.Active(i)) {
1368 ptr[i] = simd::get_lane<i>(vec_);
1369 }
1370 });
1371#endif
1372 }
1373
1378 ace void StoreScatterOffsetBytes(scalar_type* base, offset_type offsets) const { Scatter<true>(base, offsets); }
1379
1384 ace void StoreScatterOffsetBytes(scalar_type* base, offset_type offsets, argon_bool_type active) const {
1385 Scatter<true>(base, offsets, active);
1386 }
1387
1392 ace void StoreScatterOffsetIndex(scalar_type* base, offset_type offsets) const { Scatter<false>(base, offsets); }
1393
1398 ace void StoreScatterOffsetIndex(scalar_type* base, offset_type offsets, argon_bool_type active) const {
1399 Scatter<false>(base, offsets, active);
1400 }
1401
1405 template <int LaneIndex>
1406 ace void StoreLaneTo(scalar_type* ptr) {
1407#ifdef ARGON_PLATFORM_MVE
1408 *ptr = vec_[LaneIndex];
1409#else
1410 simd::store1_lane<LaneIndex>(ptr, vec_);
1411#endif
1412 }
1413
1414#ifndef ARGON_PLATFORM_MVE
1416
1420 ace argon_type PairwiseAdd(argon_type b) const { return simd::pairwise_add(vec_, b); }
1421
1425 ace argon_type PairwiseMax(argon_type b) const { return simd::pairwise_max(vec_, b); }
1426
1430 ace argon_type PairwiseMin(argon_type b) const { return simd::pairwise_min(vec_, b); }
1431#endif
1432
1434
1437 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1438 return ~vec_;
1439 } else {
1440 return simd::bitwise_not(vec_);
1441 }
1442 }
1443
1446 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1447 return vec_ & b.vec_;
1448 } else {
1449 return simd::bitwise_and(vec_, b);
1450 }
1451 }
1452
1455 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1456 return vec_ | b.vec_;
1457 } else {
1458 return simd::bitwise_or(vec_, b);
1459 }
1460 }
1461
1464 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1465 return vec_ ^ b.vec_;
1466 } else {
1467 return simd::bitwise_xor(vec_, b);
1468 }
1469 }
1470
1474 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1475 return vec_ | ~b.vec_;
1476 } else {
1477 return simd::bitwise_or_not(vec_, b);
1478 }
1479 }
1480
1484 if constexpr (ARGON_USE_COMPILER_EXTENSIONS) {
1485 return vec_ & ~b.vec_;
1486 } else {
1487 return simd::bitwise_clear(vec_, b);
1488 }
1489 }
1490
1493
1497 template <typename ArgType>
1498 requires std::is_unsigned_v<scalar_type>
1499 ace ArgType BitwiseSelect(ArgType true_value, ArgType false_value) const {
1500#ifdef ARGON_PLATFORM_MVE
1501 // MVE has no vbsl; blend the bits of the operands through the mask's type.
1502 const auto t = std::bit_cast<VectorType>(true_value.vec());
1503 const auto f = std::bit_cast<VectorType>(false_value.vec());
1504 return ArgType{std::bit_cast<typename ArgType::vector_type>((vec_ & t) | (f & ~vec_))};
1505#else
1506 return ArgType{simd::bitwise_select(vec_, true_value, false_value)};
1507#endif
1508 }
1509
1511 template <typename ArgType>
1512 requires std::is_unsigned_v<scalar_type>
1513 ace ArgType Select(ArgType true_value, ArgType false_value) const {
1514 return BitwiseSelect(true_value, false_value);
1515 }
1516
1520 requires std::is_integral_v<scalar_type>
1521 {
1522#ifdef ARGON_PLATFORM_MVE
1523 return ~(argon_type{vec_ & b.vec_} == argon_type{scalar_type{0}});
1524#else
1525 return argon_bool_type{simd::compare_test_nonzero(vec_, b.vec_)};
1526#endif
1527 }
1528
1531 requires std::is_integral_v<scalar_type>
1532 {
1533 return CompareTestNonzero(*this);
1534 }
1535
1536 // ── Predicated operations ──────────────────────────────────────────────────────────────────────────────────
1537 // Each operation has two predicated forms, after ACLE's:
1538 // Op(b, active) "_x": lanes outside `active` are unspecified (on NEON, simply Op(b)).
1539 // Op(b, active, inactive) "_m": lanes outside `active` are taken from `inactive` (pass zero for "_z").
1540 // On MVE these are the VPT-predicated instructions; on NEON, the operation followed by vbsl. They are worth using
1541 // on MVE with GCC, which doesn't fold Select(op, ...) into a predicated instruction the way clang does.
1542
1543#ifdef ARGON_PLATFORM_MVE
1544#define ARGON_PREDICATED_BINARY(Name, mve_name, mve_has_it) \
1545 ace argon_type Name(argon_type b, argon_bool_type active) const { \
1546 if constexpr (mve_has_it) { \
1547 return mve::mve_name(vec_, b.vec_, active.native()); \
1548 } else { \
1549 return Name(b); \
1550 } \
1551 } \
1552 ace argon_type Name(argon_type b, argon_bool_type active, argon_type inactive) const { \
1553 if constexpr (mve_has_it) { \
1554 return mve::mve_name(inactive.vec_, vec_, b.vec_, active.native()); \
1555 } else { \
1556 return active.Select(Name(b), inactive); \
1557 } \
1558 }
1559#define ARGON_PREDICATED_UNARY(Name, mve_name, mve_has_it) \
1560 ace argon_type Name(argon_bool_type active) const { \
1561 if constexpr (mve_has_it) { \
1562 return mve::mve_name(vec_, active.native()); \
1563 } else { \
1564 return Name(); \
1565 } \
1566 } \
1567 ace argon_type Name(argon_bool_type active, argon_type inactive) const { \
1568 if constexpr (mve_has_it) { \
1569 return mve::mve_name(inactive.vec_, vec_, active.native()); \
1570 } else { \
1571 return active.Select(Name(), inactive); \
1572 } \
1573 }
1574#else
1575#define ARGON_PREDICATED_BINARY(Name, mve_name, mve_has_it) \
1576 ace argon_type Name(argon_type b, argon_bool_type /*active*/) const { return Name(b); } \
1577 ace argon_type Name(argon_type b, argon_bool_type active, argon_type inactive) const { \
1578 return active.Select(Name(b), inactive); \
1579 }
1580#define ARGON_PREDICATED_UNARY(Name, mve_name, mve_has_it) \
1581 ace argon_type Name(argon_bool_type /*active*/) const { return Name(); } \
1582 ace argon_type Name(argon_bool_type active, argon_type inactive) const { return active.Select(Name(), inactive); }
1583#endif
1584
1585 ARGON_PREDICATED_BINARY(Add, add, true)
1586 ARGON_PREDICATED_BINARY(Subtract, subtract, true)
1587 ARGON_PREDICATED_BINARY(Multiply, multiply, true)
1588 // Float Max/Min would be vmaxnm/vminnm, whose NaN handling differs from the unpredicated a > b ? a : b.
1589 ARGON_PREDICATED_BINARY(Max, max, std::is_integral_v<scalar_type>)
1590 ARGON_PREDICATED_BINARY(Min, min, std::is_integral_v<scalar_type>)
1591 ARGON_PREDICATED_BINARY(SubtractAbs, subtract_absolute, true)
1592 ARGON_PREDICATED_BINARY(BitwiseAnd, bitwise_and, true)
1593 ARGON_PREDICATED_BINARY(BitwiseOr, bitwise_or, true)
1594 ARGON_PREDICATED_BINARY(BitwiseXor, bitwise_xor, true)
1595 ARGON_PREDICATED_BINARY(BitwiseAndNot, bitwise_clear, true)
1596 // MVE has no unsigned vneg/vabs.
1597 ARGON_PREDICATED_UNARY(Negate, negate, !std::is_unsigned_v<scalar_type>)
1598 ARGON_PREDICATED_UNARY(Absolute, abs, !std::is_unsigned_v<scalar_type>)
1599
1600#undef ARGON_PREDICATED_BINARY
1601#undef ARGON_PREDICATED_UNARY
1602
1607#ifdef ARGON_PLATFORM_MVE
1608 if constexpr (mve_float) {
1609 return simd::multiply_add_fused(vec_, b.vec_, c.vec_, active.native());
1610 } else
1611#endif
1612 {
1613 return active.Select(MultiplyAdd(b, c), argon_type{vec_});
1614 }
1615 }
1616
1619#ifdef ARGON_PLATFORM_MVE
1620 if constexpr (mve_float) {
1621 return simd::multiply_add_fused(vec_, b.vec_, c, active.native());
1622 } else
1623#endif
1624 {
1625 return active.Select(MultiplyAdd(b, c), argon_type{vec_});
1626 }
1627 }
1628
1631#ifdef ARGON_PLATFORM_MVE
1632 if constexpr (mve_float) {
1633 return simd::multiply_subtract_fused(vec_, b.vec_, c.vec_, active.native());
1634 } else
1635#endif
1636 {
1637 return active.Select(MultiplySubtract(b, c), argon_type{vec_});
1638 }
1639 }
1640
1644#ifdef ARGON_PLATFORM_MVE
1645 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::Equal>(vec_, b.vec_, active.native())};
1646#else
1647 return active & Equal(b);
1648#endif
1649 }
1650
1654#ifdef ARGON_PLATFORM_MVE
1655 return argon_bool_type{helpers::mve_compare<helpers::MveComparison::GreaterThan>(vec_, b.vec_, active.native())};
1656#else
1657 return active & GreaterThan(b);
1658#endif
1659 }
1660
1664#ifdef ARGON_PLATFORM_MVE
1665 return argon_bool_type{
1666 helpers::mve_compare<helpers::MveComparison::GreaterThanOrEqual>(vec_, b.vec_, active.native())};
1667#else
1668 return active & GreaterThanOrEqual(b);
1669#endif
1670 }
1671
1674 ace argon_bool_type LessThan(argon_type b, argon_bool_type active) const { return b.GreaterThan(*this, active); }
1675
1679 return b.GreaterThanOrEqual(*this, active);
1680 }
1681
1685 requires(std::is_integral_v<scalar_type>)
1686 {
1687 return simd::count_leading_sign_bits(vec_);
1688 }
1689
1692 ace argon_type CountLeadingZeroBits() const { return simd::count_leading_zero_bits(vec_); }
1693
1697#ifdef ARGON_PLATFORM_MVE
1698 auto new_vec = vec_;
1699 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1700 new_vec[i] = std::popcount(vec_[i]);
1701 });
1702 return new_vec;
1703#else
1704 return neon::count_active_bits(vec_);
1705#endif
1706 }
1707
1709 ace argon_type Popcount() const { return CountActiveBits(); }
1710
1714 template <int n>
1716#ifdef ARGON_PLATFORM_MVE
1717 return ShuffleConcat<[](size_t i) { return i + n; }>(vec_, b.vec_);
1718#else
1719 return simd::extract<n>(vec_, b);
1720#endif
1721 }
1722
1723 ace argon_type Reverse64bit() const { return simd::reverse_64bit(vec_); }
1724 ace argon_type Reverse32bit() const { return simd::reverse_32bit(vec_); }
1725 ace argon_type Reverse16bit() const { return simd::reverse_16bit(vec_); }
1726
1730 ace std::array<argon_type, 2> ZipWith(argon_type b) const {
1731#ifdef ARGON_PLATFORM_MVE
1732 // Lanes of {a, b}: even result lanes come from a, odd ones from b (offset by `lanes`).
1733 return {ShuffleConcat<[](size_t i) { return i / 2 + (i % 2) * lanes; }>(vec_, b.vec_),
1734 ShuffleConcat<[](size_t i) { return (i + lanes) / 2 + (i % 2) * lanes; }>(vec_, b.vec_)};
1735#else
1736 return argon::to_array(neon::zip(vec_, b.vec()).val);
1737#endif
1738 }
1739
1743 std::array<argon_type, 2> UnzipWith(argon_type b) {
1744#ifdef ARGON_PLATFORM_MVE
1745 return {ShuffleConcat<[](size_t i) { return i * 2; }>(vec_, b.vec_),
1746 ShuffleConcat<[](size_t i) { return i * 2 + 1; }>(vec_, b.vec_)};
1747#else
1748 return argon::to_array(neon::unzip(vec_, b.vec()).val);
1749#endif
1750 }
1751
1754 // {b0, b1, b2, b3}}
1756 // {a1, b1, a3, b3}}
1757 std::array<argon_type, 2> TransposeWith(argon_type b) const {
1758#ifdef ARGON_PLATFORM_MVE
1759 return {ShuffleConcat<[](size_t i) { return i % 2 ? lanes + i - 1 : i; }>(vec_, b.vec_),
1760 ShuffleConcat<[](size_t i) { return i % 2 ? lanes + i : i + 1; }>(vec_, b.vec_)};
1761#else
1762 return argon::to_array(simd::transpose(vec_, b.vec()).val);
1763#endif
1764 }
1765
1767 ace static int size() { return lanes; }
1768
1769 template <typename FuncType>
1770 requires std::convertible_to<FuncType, std::function<scalar_type(scalar_type)>>
1771 ace argon_type map(FuncType body) const {
1772 VectorType out;
1773 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1774 out[i] = body(vec_[i]);
1775 });
1776 return out;
1777 }
1778
1779 template <typename FuncType>
1780 requires std::convertible_to<FuncType, std::function<scalar_type(scalar_type, int)>>
1781 ace argon_type map_with_index(FuncType body) const {
1782 VectorType out;
1783 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1784 out[i] = body(vec_[i], i);
1785 });
1786 return out;
1787 }
1788
1789 template <typename FuncType>
1790 requires std::convertible_to<FuncType, std::function<scalar_type(scalar_type, scalar_type)>>
1791 ace argon_type map2(argon_type other, FuncType body) const {
1792 VectorType out;
1793 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1794 out[i] = body(vec_[i], other.vec_[i]);
1795 });
1796 return out;
1797 }
1798
1799 template <typename FuncType>
1800 requires std::convertible_to<FuncType, std::function<void(scalar_type&)>>
1801 ace argon_type each_lane(FuncType body) {
1802 VectorType out = vec_;
1803 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1804 // A vector subscript (out[i]) is not an lvalue a non-const reference can bind to under
1805 // Clang (GCC accepts it as an extension). Round-trip through a scalar so the callback's
1806 // scalar_type& binds to a real object, then write the mutated value back.
1807 scalar_type lane = out[i];
1808 body(lane);
1809 out[i] = lane;
1810 });
1811 return out;
1812 }
1813
1814 template <typename FuncType>
1815 requires std::convertible_to<FuncType, std::function<void(scalar_type&, int)>>
1816 ace argon_type each_lane_with_index(FuncType body) {
1817 VectorType out = vec_;
1818 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1819 // See each_lane: a non-const reference cannot bind to a vector subscript under Clang.
1820 scalar_type lane = out[i];
1821 body(lane, i);
1822 out[i] = lane;
1823 });
1824 return out;
1825 }
1826
1827 template <typename FuncType>
1828 requires std::convertible_to<FuncType, std::function<void()>>
1829 ace void if_lane(FuncType true_branch) {
1830 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1831 if (vec_[i] != 0) {
1832 true_branch();
1833 }
1834 });
1835 }
1836
1837 template <typename FuncType>
1838 requires std::convertible_to<FuncType, std::function<void()>>
1839 ace void if_else_lane(FuncType true_branch, FuncType false_branch) {
1840 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1841 if (vec_[i] != 0) {
1842 true_branch();
1843 } else {
1844 false_branch();
1845 }
1846 });
1847 }
1848
1849 template <typename FuncType>
1850 requires std::convertible_to<FuncType, std::function<void(int)>>
1851 ace void if_lane_with_index(FuncType true_branch) {
1852 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1853 if (vec_[i] != 0) {
1854 true_branch(i);
1855 }
1856 });
1857 }
1858
1859 template <typename FuncType1, typename FuncType2>
1860 requires std::convertible_to<FuncType1, std::function<void(int)>> &&
1861 std::convertible_to<FuncType2, std::function<void(int)>>
1862 ace void if_else_lane_with_index(FuncType1 true_branch, FuncType2 false_branch) {
1863 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1864 if (vec_[i] != 0) {
1865 true_branch(i);
1866 } else {
1867 false_branch(i);
1868 }
1869 });
1870 }
1871
1873 ace bool any() const { return !Equal(argon_type{scalar_type{0}}).All(); }
1874
1876 ace bool all() const { return Equal(argon_type{scalar_type{0}}).None(); }
1877
1878 template <std::size_t Index>
1879 std::tuple_element_t<Index, argon_type> get() {
1880#ifdef ARGON_PLATFORM_MVE
1881 return vec_[Index];
1882#else
1883 return GetLane<Index>();
1884#endif
1885 }
1886
1887 protected:
1890 template <bool byte_offsets, typename PointerType, typename OffsetType>
1891 ace static PointerType* LaneAddress(PointerType* base, OffsetType offset) {
1892 if constexpr (byte_offsets) {
1893 using byte_type = std::conditional_t<std::is_const_v<PointerType>, const char, char>;
1894 return reinterpret_cast<PointerType*>(reinterpret_cast<byte_type*>(base) + offset);
1895 } else {
1896 return base + offset;
1897 }
1898 }
1899
1901 template <bool byte_offsets, typename... PredicateType>
1902 ace static argon_type Gather(const scalar_type* base, offset_type offsets, PredicateType... active) {
1903 static_assert(sizeof...(PredicateType) <= 1);
1904#ifdef ARGON_PLATFORM_MVE
1905 const auto off = offsets.vec();
1906 if constexpr (sizeof(scalar_type) == 1) {
1907 return mve::load_byte_gather_offset(base, off, active.native()...);
1908 } else if constexpr (sizeof(scalar_type) == 2) {
1909 if constexpr (byte_offsets) {
1910 return mve::load_halfword_gather_offset(base, off, active.native()...);
1911 } else {
1912 return mve::load_halfword_gather_shifted_offset(base, off, active.native()...);
1913 }
1914 } else if constexpr (sizeof(scalar_type) == 4) {
1915 if constexpr (byte_offsets) {
1916 return mve::load_word_gather_offset(base, off, active.native()...);
1917 } else {
1918 return mve::load_word_gather_shifted_offset(base, off, active.native()...);
1919 }
1920 } else {
1921 if constexpr (byte_offsets) {
1922 return mve::load_doubleword_gather_offset(base, off, active.native()...);
1923 } else {
1924 return mve::load_doubleword_gather_shifted_offset(base, off, active.native()...);
1925 }
1926 }
1927#else
1928 argon_type destination{scalar_type{0}}; // inactive lanes stay zero
1929 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1930 if ((active.Active(i) && ...)) {
1931 const auto offset = simd::get_lane<i>(offsets.vec());
1932 destination = destination.template LoadToLane<i>(LaneAddress<byte_offsets>(base, offset));
1933 }
1934 });
1935 return destination;
1936#endif
1937 }
1938
1940 template <bool byte_offsets, typename... PredicateType>
1941 ace void Scatter(scalar_type* base, offset_type offsets, PredicateType... active) const {
1942 static_assert(sizeof...(PredicateType) <= 1);
1943#ifdef ARGON_PLATFORM_MVE
1944 const auto off = offsets.vec();
1945 if constexpr (sizeof(scalar_type) == 1) {
1946 mve::store_byte_scatter_offset(base, off, vec_, active.native()...);
1947 } else if constexpr (sizeof(scalar_type) == 2) {
1948 if constexpr (byte_offsets) {
1949 mve::store_halfword_scatter_offset(base, off, vec_, active.native()...);
1950 } else {
1951 mve::store_halfword_scatter_shifted_offset(base, off, vec_, active.native()...);
1952 }
1953 } else if constexpr (sizeof(scalar_type) == 4) {
1954 if constexpr (byte_offsets) {
1955 mve::store_word_scatter_offset(base, off, vec_, active.native()...);
1956 } else {
1957 mve::store_word_scatter_shifted_offset(base, off, vec_, active.native()...);
1958 }
1959 } else {
1960 if constexpr (byte_offsets) {
1961 mve::store_doubleword_scatter_offset(base, off, vec_, active.native()...);
1962 } else {
1963 mve::store_doubleword_scatter_shifted_offset(base, off, vec_, active.native()...);
1964 }
1965 }
1966#else
1967 utility::constexpr_for<0, lanes, 1>([&]<int i>() { //<
1968 if ((active.Active(i) && ...)) {
1969 *LaneAddress<byte_offsets>(base, simd::get_lane<i>(offsets.vec())) = simd::get_lane<i>(vec_);
1970 }
1971 });
1972#endif
1973 }
1974
1976 template <typename ArgType>
1977 ace static decltype(auto) LaneValue(ArgType&& arg) {
1979 return static_cast<scalar_type>(arg);
1980 } else {
1981 return std::forward<ArgType>(arg);
1982 }
1983 }
1984
1985#ifdef ARGON_PLATFORM_MVE
1988 template <auto index>
1989 ace static VectorType ShuffleConcat(VectorType a, VectorType b) {
1990 return [&]<std::size_t... Is>(std::index_sequence<Is...>) {
1991 return VectorType(__builtin_shufflevector(a, b, index(Is)...));
1992 }(std::make_index_sequence<lanes>{});
1993 }
1994#endif
1995
1996 template <std::size_t... Ints>
1997 ace static argon_type IotaHelper(scalar_type start, std::index_sequence<Ints...>) {
1998 return VectorType{static_cast<scalar_type>(start + Ints)...};
1999 }
2000
2001 VectorType vec_;
2002};
2003
2004} // namespace argon
2005
2009namespace std {
2010template <typename T>
2011struct tuple_size<argon::Vector<T>> {
2012 static constexpr size_t value = argon::Vector<T>::lanes;
2013};
2014
2015template <size_t Index, typename T>
2016struct tuple_element<Index, argon::Vector<T>> {
2017 static_assert(Index < argon::Vector<T>::lanes);
2019};
2020} // namespace std
2021
2022#undef ace
2023#undef simd
Provides utility templates and concepts for type traits and compile-time iteration.
Definition argon_full.hpp:44
Represents a single lane of a SIMD vector with the lane index known at compile time.
Definition lane.hpp:35
ace int lane()
On ARM32, return the local lane index within the 64-bit half-register returned by vec().
Definition lane.hpp:85
ace neon::Vec64_t< scalar_type > vec()
On ARM32, return the 64-bit half-register that contains this lane.
Definition lane.hpp:73
ace scalar_type Get() const
Get the scalar value of this lane.
Definition lane.hpp:64
ace argon_type Load(const scalar_type *ptr)
Load a scalar from ptr into this lane and return the updated vector.
Definition lane.hpp:50
Represents a single lane of a SIMD vector with a runtime-determined index.
Definition lane.hpp:107
ace int lane()
On ARM32, return the local lane index within the 64-bit half-register returned by vec().
Definition lane.hpp:153
ace neon::Vec64_t< scalar_type > vec()
On ARM32, return the 64-bit half-register that contains this lane.
Definition lane.hpp:141
ace scalar_type Get() const
Get the scalar value of this lane.
Definition lane.hpp:130
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
ace bool Active(size_t i) const
Whether a single lane is active.
Definition predicate.hpp:246
ace void StoreScatterOffsetBytes(scalar_type *base, offset_type offsets) const
Scatter the lanes to base plus a byte offset per lane.
Definition vector.hpp:1378
ace argon_type PairwiseMin(argon_type b) const
Select the maximum of each pair of lanes in the two vectors.
Definition vector.hpp:1430
Lane< simd::Vec128_t< ScalarType > > lane_type
Definition vector.hpp:57
ace argon_type MultiplySubtract(argon_type b, lane_type c) const
Multiply a vector by a lane value and subtract from a third vector.
Definition vector.hpp:625
ace Vector(VectorType vector)
Constructs a Vector from a SIMD vector type.
Definition vector.hpp:102
simd::Vec128_t< ScalarType > vector_type
Definition vector.hpp:78
ace void StoreScatterOffsetBytes(scalar_type *base, offset_type offsets, argon_bool_type active) const
Scatter the active lanes to base plus a byte offset per lane; inactive lanes are not written.
Definition vector.hpp:1384
ace argon_type Modulo(argon_type b) const
Get the modulo of two vectors.
Definition vector.hpp:793
ace argon_bool_type operator<(argon_type b) const
Compare two vectors, checking if this vector is less than the other.
Definition vector.hpp:258
ace argon_type ShiftLeftRound(argon_type b) const
Shift the elements of the vector to the left by a specified number of bits, rounding the result.
Definition vector.hpp:1025
ace Lane< const VectorType > GetLane(const int i) const
Get a single lane of the vector by index.
Definition vector.hpp:335
std::array< argon_type, 2 > TransposeWith(argon_type b) const
Perform a 2x2 matrix transpose on two vectors, returning two vectors of pairs.
Definition vector.hpp:1757
ace argon_type MaxNumber(argon_type b) const
The larger of each lane by IEEE 754 maxNum, as Arm's vmaxnm: a quiet NaN in one operand gives the oth...
Definition vector.hpp:868
constexpr Vector(const Vector &other)=default
Copy constructor for the Vector class.
static ace std::array< argon_type, stride > LoadInterleaved(const scalar_type *ptr)
Load multiple vectors from a pointer, de-interleaving.
Definition vector.hpp:1179
static ace argon_type Iota(scalar_type start)
Constructs a Vector from an incrementing sequence.
Definition vector.hpp:194
static ace argon_type FromScalar(scalar_type scalar)
Definition vector.hpp:143
ace argon_type Multiply(scalar_type b) const
Multiply a vector by a scalar value.
Definition vector.hpp:455
static ace argon_type Load(const scalar_type *ptr, argon_bool_type active)
Load the active lanes of a vector from a pointer; inactive lanes are zero and their memory is not rea...
Definition vector.hpp:1116
ace argon_type MultiplySubtract(argon_type b, argon_type c) const
Multiply two vectors and subtract from a third vector.
Definition vector.hpp:540
ace argon_type Extract(argon_type b) const
Extract n elements from the lower end of the operand, and the remaining elements from the top end of ...
Definition vector.hpp:1715
ace argon_bool_type LessThan(argon_type b, argon_bool_type active) const
Compare only the lanes of active: a predicate active where active holds and a < b.
Definition vector.hpp:1674
constexpr VectorType vec() const
Get the underlying SIMD vector.
Definition vector.hpp:312
ace void Scatter(scalar_type *base, offset_type offsets, PredicateType... active) const
Scatter by byte or element offsets, optionally only the lanes of one predicate.
Definition vector.hpp:1941
ace argon_type Multiply(argon_type b) const
Multiply two vectors.
Definition vector.hpp:439
ace argon_bool_type LessThanOrEqual(argon_type b) const
Compare the lanes of two vectors, returning a predicate active where a is less than or equal to b.
Definition vector.hpp:934
static constexpr bool mve_float
Definition vector.hpp:69
ace argon_type operator--() const
Decrement the vector by 1 and return the result.
Definition vector.hpp:273
ace argon_type ShiftLeft(const int i) const
Shift the elements of the vector to the left by a specified number of bits.
Definition vector.hpp:367
static ace argon_type Load(const scalar_type *ptr)
Load a vector from a pointer.
Definition vector.hpp:1095
ace argon_type operator+(argon_type b) const
Add a vector and return the result.
Definition vector.hpp:240
ace void StoreTo(scalar_type *ptr, argon_bool_type active) const
Store the active lanes of the vector to a pointer; memory for inactive lanes is not written.
Definition vector.hpp:1362
ace argon_type ShiftLeft(helpers::ArgonFor_t< simd::make_signed_t< Bool_t< VectorType > > > b) const
Shift the elemnets of the vector to the left by a specified number of bits.
Definition vector.hpp:974
ace argon_type Multiply(const_lane_type< LaneIndex > b) const
Multiply a vector by a lane value.
Definition vector.hpp:469
ace argon_type PairwiseAdd(argon_type b) const
Pairwise ops.
Definition vector.hpp:1420
ace argon_type MultiplyAdd(scalar_type b, argon_type c) const
Multiply a vector by a scalar value and add a third vector.
Definition vector.hpp:511
ace void StoreScatterOffsetIndex(scalar_type *base, offset_type offsets, argon_bool_type active) const
Scatter the active lanes to base[offsets[i]]; inactive lanes are not written.
Definition vector.hpp:1398
ace argon_bool_type operator>=(argon_type b) const
Compare two vectors, checking if this vector is greater than or equal to the other.
Definition vector.hpp:267
ace argon_type MultiplyAdd(argon_type b, lane_type c) const
Multiply a vector by a lane value and add a third vector.
Definition vector.hpp:516
static ace argon_type LoadGatherOffsetBytes(const scalar_type *base, offset_type offsets, argon_bool_type active)
Gather the active lanes from base plus a byte offset per lane; inactive lanes are zero and not read.
Definition vector.hpp:1143
ace argon_bool_type operator==(argon_type b) const
Compare two vectors for equality.
Definition vector.hpp:252
ace argon_type MultiplyAdd(argon_type b, argon_type c) const
Multiply two vectors and add a third vector.
Definition vector.hpp:477
ace argon_type ShiftLeft(std::make_signed_t< simd::Scalar_t< Bool_t< VectorType > > > n) const
Shift the elements of the vector to the left by a specified number of bits.
Definition vector.hpp:986
ace argon_type BitwiseOrNot(argon_type b) const
Bitwise OR of the vector with the NOT of another vector.
Definition vector.hpp:1473
ace helpers::ArgonFor_t< simd::make_signed_t< Bool_t< VectorType > > > CountLeadingSignBits() const
Count the number of consecutive bits following the sign bit that are set to the same value as the sig...
Definition vector.hpp:1684
static ace argon_type FromLane(argon::ConstLane< LaneIndex, VectorType > lane)
Constructs a Vector from a ConstLane object.
Definition vector.hpp:169
ace argon_type AddSaturate(argon_type b) const
Adds two vectors, saturating the result.
Definition vector.hpp:406
ace argon_type ReciprocalSqrtEstimateRefine(int n_iters=1) const
Compute a refined reciprocal-sqrt estimate using Newton-Raphson iterations.
Definition vector.hpp:743
std::array< argon_type, 2 > UnzipWith(argon_type b)
Unzip two vectors, returning two vectors of pairs.
Definition vector.hpp:1743
ace argon_type operator++() const
Increment the vector by 1 and return the result.
Definition vector.hpp:270
ace argon_type MultiplyAddFixedQMax(argon_type b, arg_type c) const
Multiply-add three fixed-point vectors, returning a fixed-point sum.
Definition vector.hpp:758
ace argon_type operator^(argon_type b) const
Bitwise XOR two vectors and return the result.
Definition vector.hpp:282
ace argon_bool_type GreaterThanOrEqual(argon_type b, argon_bool_type active) const
Compare only the lanes of active: a predicate active where active holds and a >= b.
Definition vector.hpp:1663
ace argon_bool_type Equal(argon_type b) const
Compare the lanes of two vectors, returning a predicate active where a == b.
Definition vector.hpp:912
ace void StoreTo(scalar_type *ptr) const
Store the vector to a pointer.
Definition vector.hpp:1356
ConstLane< LaneIndex, simd::Vec128_t< ScalarType > > const_lane_type
Definition vector.hpp:56
ace argon_type MultiplyRoundFixedQMax(lane_type l) const
Multiply a fixed-point vector by a lane value, returning a fixed-point product.
Definition vector.hpp:661
ace Vector(scalar_type scalar)
Constructs a Vector from a scalar value.
Definition vector.hpp:109
static constexpr bool extension_arithmetic
Definition vector.hpp:61
ace argon_type MultiplyAdd(argon_type b, scalar_type c, argon_bool_type active) const
MultiplyAdd under a predicate: lanes outside active keep this vector's value, the accumulator (as ACL...
Definition vector.hpp:1618
ace argon_type CountActiveBits() const
Count the number of bits that are set to one in the vector.
Definition vector.hpp:1696
ace argon_type MultiplyFixedQMax(scalar_type s) const
Multiply a QMax fixed-point vector by a scalar value, returning a fixed-point product.
Definition vector.hpp:636
static ace std::array< argon_type, stride > LoadToLaneInterleaved(std::array< argon_type, stride > multi, const scalar_type *ptr)
Load a value from a pointer into a vector at the lane index lane, de-interleaving.
Definition vector.hpp:1275
ace argon_type PairwiseMax(argon_type b) const
Select the maximum of each pair of lanes in the two vectors.
Definition vector.hpp:1425
ace argon_type operator/(argon_type b) const
Divide a vector and return the result.
Definition vector.hpp:249
ace argon_type BitwiseNot() const
Bitwise ops.
Definition vector.hpp:1436
ace ConstLane< LaneIndex, const VectorType > GetLane() const
Get a single lane of the vector by index.
Definition vector.hpp:343
ace argon_type Max(argon_type b) const
Compare the lanes of two vectors, copying the larger of each lane to the result.
Definition vector.hpp:821
ace argon_bool_type Equal(argon_type b, argon_bool_type active) const
Compare only the lanes of active: a predicate active where active holds and a == b.
Definition vector.hpp:1643
static ace argon_type FromLane(argon::Lane< IntrinsicType > lane)
Definition vector.hpp:156
constexpr Vector & operator=(Vector &&other)=default
Move assignment operator for the Vector class.
ace argon_type ShiftLeftInsert(argon_type b) const
Shift the elements of the vector to the left by a specified number of bits, and then OR the result wi...
Definition vector.hpp:1042
ace ArgType BitwiseSelect(ArgType true_value, ArgType false_value) const
Bitwise select between two vectors, using the current vector as a mask.
Definition vector.hpp:1499
ace argon_type BitwiseAnd(argon_type b) const
Bitwise AND of the vector with another vector.
Definition vector.hpp:1445
static ace PointerType * LaneAddress(PointerType *base, OffsetType offset)
The address of one gathered / scattered lane: base plus a byte offset, or base indexed by an element ...
Definition vector.hpp:1891
ace argon_type MultiplyAdd(argon_type b, const_lane_type< LaneIndex > c) const
Multiply a vector by a lane value and add a third vector.
Definition vector.hpp:527
ace argon_type Modulo(scalar_type b) const
Get the modulo of a vector and a scalar value.
Definition vector.hpp:805
ace argon_type Popcount() const
Count the number of bits that are set to one in the vector.
Definition vector.hpp:1709
ace argon_bool_type LessThan(argon_type b) const
Compare the lanes of two vectors, returning a predicate active where a is less than b.
Definition vector.hpp:960
ace argon_type ShiftRight(const int i) const
Shift the elements of the vector to the right by a specified number of bits.
Definition vector.hpp:358
ace argon_type ShiftLeftRoundSaturate(argon_type b) const
Shift the elements of the vector to the left by a specified number of bits, rounding and saturating t...
Definition vector.hpp:1028
ace argon_type ShiftRight() const
Shift the elements of the vector to the right by a specified number of bits.
Definition vector.hpp:1048
ace argon_type Negate() const
Bitwise negate the vector and return the result.
Definition vector.hpp:376
static ace argon_type LoadGatherOffsetIndex(const scalar_type *base, offset_type offsets)
Gather a vector from base[offsets[i]].
Definition vector.hpp:1152
static constexpr bool mve_platform
Definition vector.hpp:66
ace void StoreLaneTo(scalar_type *ptr)
Store a lane of the vector to a pointer.
Definition vector.hpp:1406
ace argon_type Multiply(lane_type b) const
Multiply a vector by a lane value.
Definition vector.hpp:465
ace argon_type MultiplySubtract(argon_type b, scalar_type c) const
Multiply a vector by a scalar value and subtract from a third vector.
Definition vector.hpp:558
ace argon_type MultiplyAdd(const_lane_type< LaneIndex > b, argon_type c) const
Multiply a vector by a lane value and add a third vector.
Definition vector.hpp:533
ace argon_bool_type CompareTestNonzero(argon_type b) const
Compare the lanes of (a & b) with zero, returning a predicate active where they share a set bit.
Definition vector.hpp:1519
ace argon_type MultiplyRoundFixedQMax(scalar_type s) const
Multiply a fixed-point vector by a scalar value, returning a fixed-point product.
Definition vector.hpp:654
ace argon_bool_type GreaterThanOrEqual(argon_type b) const
Compare the lanes of two vectors, returning a predicate active where a is greater than or equal to b.
Definition vector.hpp:921
ace argon_bool_type operator>(argon_type b) const
Compare two vectors, checking if this vector is greater than the other.
Definition vector.hpp:261
ace argon_type operator<<(const int i) const
Shift the elements of the vector to the left by a specified number of bits.
Definition vector.hpp:303
ace argon_type AddHalve(argon_type b) const
Adds two vectors, halving the result.
Definition vector.hpp:397
helpers::ArgonFor_t< simd::make_unsigned_t< Bool_t< simd::Vec128_t< ScalarType > > > > offset_type
Definition vector.hpp:86
static ace std::array< argon_type, stride > LoadGatherOffsetIndexInterleaved(const scalar_type *base_ptr, helpers::ArgonFor_t< simd::make_unsigned_t< Bool_t< VectorType > > > offset_vector)
Perform a Load-Gather of interleaved elements.
Definition vector.hpp:1292
static ace decltype(auto) LaneValue(ArgType &&arg)
Definition vector.hpp:1977
ace argon_type MinNumber(argon_type b) const
The smaller of each lane by IEEE 754 minNum, as Arm's vminnm: a quiet NaN in one operand gives the ot...
Definition vector.hpp:885
ace argon_type Divide(argon_type b) const
Divide two vectors.
Definition vector.hpp:782
ace argon_type ShiftRightRound() const
Shift the elements of the vector to the right by a specified number of bits, rounding the result.
Definition vector.hpp:1058
static ace std::array< argon_type, stride > LoadCopyInterleaved(const scalar_type *ptr)
Load multiple vectors from a pointer, duplicating the value across all lanes.
Definition vector.hpp:1211
static ace int size()
Get the number of elements.
Definition vector.hpp:1767
ace argon_bool_type GreaterThan(argon_type b) const
Compare the lanes of two vectors, returning a predicate active where a is greater than b.
Definition vector.hpp:947
ace std::array< argon_type, 2 > ZipWith(argon_type b) const
Zip two vectors together, returning two vectors of pairs.
Definition vector.hpp:1730
ace argon_type operator-(argon_type b) const
Subtract a vector and return the result.
Definition vector.hpp:243
ace argon_type MultiplyRoundAddFixedQMax(argon_type b, arg_type c) const
Multiply-round-add three fixed-point vectors, returning a fixed-point sum.
Definition vector.hpp:767
helpers::ArgonFor_t< simd::Vec128_t< ScalarType > > argon_type
Definition vector.hpp:79
static ace argon_type LoadScalar(const scalar_type *ptr)
Constructs a Vector from a scalar pointer.
Definition vector.hpp:137
ace argon_type ShiftRightAccumulateRound(argon_type b) const
Shift the elements of the b vector to the right by a specified number of bits, and then add the resul...
Definition vector.hpp:1078
ace bool all() const
Whether every lane is nonzero.
Definition vector.hpp:1876
ace argon_type operator*(argon_type b) const
Multiply a vector and return the result.
Definition vector.hpp:246
static ace argon_type LoadCopy(const scalar_type *ptr)
Load a vector from a pointer, duplicating the value across all lanes.
Definition vector.hpp:1104
Bool_t< simd::Vec128_t< ScalarType > > mask_type
Definition vector.hpp:80
ace argon_type ReciprocalStep(argon_type b) const
Newton-Raphson step for reciprocal refinement: (2 - a * b) / 2.
Definition vector.hpp:704
ace argon_type LoadToLane(const scalar_type *ptr)
Load a lane from a pointer.
Definition vector.hpp:1168
ace argon_type SubtractAbs(argon_type b) const
Subtract two vectors, taking the absolute value of the result.
Definition vector.hpp:426
ace argon_type ShiftLeft() const
Shift the elements of the vector to the left by a specified number of bits.
Definition vector.hpp:1009
static ace argon_type Gather(const scalar_type *base, offset_type offsets, PredicateType... active)
Gather by byte or element offsets, optionally only the lanes of one predicate (inactive lanes are zer...
Definition vector.hpp:1902
ace const_lane_type< lanes - 1 > LastLane()
Get the last lane of the vector.
Definition vector.hpp:353
ace Lane< const VectorType > GetLane(const size_t i) const
Get a single lane of the vector by index.
Definition vector.hpp:329
ace bool any() const
Whether any lane is nonzero.
Definition vector.hpp:1873
ace argon_bool_type LessThanOrEqual(argon_type b, argon_bool_type active) const
Compare only the lanes of active: a predicate active where active holds and a <= b.
Definition vector.hpp:1678
ace argon_type ShiftLeftSaturate(helpers::ArgonFor_t< simd::make_signed_t< Bool_t< VectorType > > > b) const
Shift the elements of the vector to the left by a specified number of bits, saturating the result.
Definition vector.hpp:1018
ace argon_type MultiplyFixedQMax(lane_type l) const
Multiply a QMax fixed-point vector by a lane value, returning a fixed-point product.
Definition vector.hpp:641
ace argon_type MultiplySubtract(scalar_type b, argon_type c) const
Multiply a vector by a scalar value and subtract from a third vector.
Definition vector.hpp:580
ace argon_bool_type operator<=(argon_type b) const
Compare two vectors, checking if this vector is less than or equal to the other.
Definition vector.hpp:264
ace argon_type MultiplySubtract(argon_type b, argon_type c, argon_bool_type active) const
MultiplySubtract under a predicate: lanes outside active keep this vector's value (as ACLE's vfmsq_m)...
Definition vector.hpp:1630
ace argon_type ShiftLeftSaturate() const
Shift the elements of the vector to the left by a specified number of bits, saturating the result.
Definition vector.hpp:1032
ace argon_type operator&(argon_type b) const
Bitwise AND two vectors and return the result.
Definition vector.hpp:276
ace argon_type MultiplyRoundFixedQMax(argon_type v) const
Multiply two fixed-point vectors, returning a fixed-point product.
Definition vector.hpp:648
ace argon_type ReciprocalSqrtStep(argon_type b) const
Newton-Raphson step for reciprocal-sqrt refinement: (3 - a * b) / 2.
Definition vector.hpp:717
ace argon_bool_type TestNonzero() const
Return a predicate active where the lane is nonzero.
Definition vector.hpp:1530
ace argon_type SubtractSaturate(argon_type b) const
Subtract two vectors, saturating the result.
Definition vector.hpp:422
static ace std::array< argon_type, Stride > LoadToLaneInterleaved(simd::MultiVector_t< VectorType, Stride > multi, const scalar_type *ptr)
Load a value from a pointer into a vector at the lane index lane, de-interleaving.
Definition vector.hpp:1241
static ace std::array< argon_type, n > LoadMulti(const scalar_type *ptr)
Load n vectors from a single contiguous set of memory.
Definition vector.hpp:1312
ace Vector(ArgTypes... args)
Constructs a Vector from one value per lane.
Definition vector.hpp:130
ace argon_type MultiplyAdd(argon_type b, argon_type c, argon_bool_type active) const
MultiplyAdd under a predicate: lanes outside active keep this vector's value, the accumulator (as ACL...
Definition vector.hpp:1606
ace argon_type ReciprocalSqrtEstimate() const
1 / sqrt(value), using an estimate for speed
Definition vector.hpp:687
ace argon_type operator|(argon_type b) const
Bitwise OR two vectors and return the result.
Definition vector.hpp:279
ace argon_type MultiplyFixedQMax(argon_type v) const
Multiply two QMax fixed-point vectors, returning a fixed-point product.
Definition vector.hpp:632
ace argon_type ReciprocalEstimateRefine(int n_iters=1) const
Compute a refined reciprocal estimate using Newton-Raphson iterations.
Definition vector.hpp:730
ace argon_type MultiplyAdd(argon_type b, scalar_type c) const
Multiply a vector by a scalar value and add a third vector.
Definition vector.hpp:492
ace void StoreScatterOffsetIndex(scalar_type *base, offset_type offsets) const
Scatter the lanes to base[offsets[i]].
Definition vector.hpp:1392
simd::Scalar_t< simd::Vec128_t< ScalarType > > scalar_type
Definition vector.hpp:58
static constexpr bool fixup_float_compare
Definition vector.hpp:77
ace std::array< scalar_type, lanes > to_array() const
Convert the vector to an array of scalar values.
Definition vector.hpp:319
ace argon_type NumberMinMax(argon_type b) const
MaxNumber/MinNumber from compares and selects, where there is no vmaxnm/vminnm.
Definition vector.hpp:900
ace argon_type operator~() const
Bitwise NOT the vector and return the result.
Definition vector.hpp:285
ace Vector(argon::ConstLane< LaneIndex, VectorType > lane)
Constructs a Vector from a ConstLane object.
Definition vector.hpp:123
static ace argon_type LoadGatherOffsetBytes(const scalar_type *base, offset_type offsets)
Gather a vector from base plus a byte offset per lane.
Definition vector.hpp:1135
ace argon_bool_type GreaterThan(argon_type b, argon_bool_type active) const
Compare only the lanes of active: a predicate active where active holds and a > b.
Definition vector.hpp:1653
ace argon_type Absolute() const
Get the absolute value of the vector.
Definition vector.hpp:669
static constexpr size_t lanes
Definition vector.hpp:90
ace lane_type operator[](const size_t i)
Access a lane of the vector by index.
Definition vector.hpp:291
static constexpr bool native_maxnm
Definition vector.hpp:74
ace argon_type BitwiseClear(argon_type b) const
Bitwise AND of the vector with the NOT of another vector.
Definition vector.hpp:1492
ace argon_type BitwiseAndNot(argon_type b) const
Bitwise AND of the vector with the NOT of another vector.
Definition vector.hpp:1483
ace argon_type ShiftRightAccumulate(argon_type b) const
Shift the elements of the b vector to the right by a specified number of bits, and then add the resul...
Definition vector.hpp:1066
ace argon_type operator>>(const int i) const
Shift the elements of the vector to the right by a specified number of bits.
Definition vector.hpp:294
ace argon_type Add(argon_type b) const
Add two vectors.
Definition vector.hpp:387
ace argon_type BitwiseOr(argon_type b) const
Bitwise OR of the vector with another vector.
Definition vector.hpp:1454
constexpr Vector()=default
The default constructor for the Vector class.
constexpr Vector & operator=(const Vector &other)=default
Copy assignment operator for the Vector class.
static ace argon_type GenerateWithIndex(FuncType body)
Constructs a Vector from a function that generates values with an index.
Definition vector.hpp:226
ace argon_bool_type operator!=(argon_type b) const
Compare two vectors for inequality.
Definition vector.hpp:255
static ace argon_type LoadGatherOffsetIndex(const scalar_type *base, offset_type offsets, argon_bool_type active)
Gather the active lanes from base[offsets[i]]; inactive lanes are zero and not read.
Definition vector.hpp:1160
ace ArgType Select(ArgType true_value, ArgType false_value) const
Bitwise select between two vectors, using the current vector as a mask.
Definition vector.hpp:1513
ace argon_type ShiftByVector(int count) const
vshl by count in every lane: left for positive counts, right (arithmetic or logical) for negative one...
Definition vector.hpp:998
ace argon_type CountLeadingZeroBits() const
Count the number of consecutive top bits that are set to zero.
Definition vector.hpp:1692
ace argon_type Min(argon_type b) const
Compare the lanes of two vectors, copying the smaller of each lane to the result.
Definition vector.hpp:842
ace argon_type operator-() const
Negate the SIMD vector and return the result.
Definition vector.hpp:237
ace argon_type SubtractHalve(argon_type b) const
Subtract two vectors, halving the result.
Definition vector.hpp:419
ace argon_type MultiplyAdd(lane_type b, argon_type c) const
Multiply a vector by a lane value and add a third vector.
Definition vector.hpp:522
ace argon_type ShiftRightInsert(argon_type b) const
Shift the elements of the vector to the right by a specified number of bits, ORing the result with th...
Definition vector.hpp:1090
ace argon_type SubtractAbsAdd(argon_type b, argon_type c) const
Subtract two vectors, taking the absolute value of the result and adding a third vector.
Definition vector.hpp:430
ace argon_type ReciprocalEstimate() const
1 / value, using an estimate for speed
Definition vector.hpp:674
constexpr Vector(Vector &&other)=default
Move constructor for the Vector class.
ace argon_type Subtract(argon_type b) const
Subtract two vectors.
Definition vector.hpp:409
ace argon_type BitwiseXor(argon_type b) const
Bitwise XOR of the vector with another vector.
Definition vector.hpp:1463
ace Vector(argon::Lane< VectorType > lane)
Constructs a Vector from a Lane object.
Definition vector.hpp:116
static ace argon_type Generate(FuncType body)
Constructs a Vector from a function that generates values.
Definition vector.hpp:209
ace argon_type AddHalveRound(argon_type b) const
Adds two vectors, halving and rounding the result.
Definition vector.hpp:401
Predicate< simd::Vec128_t< ScalarType > > argon_bool_type
Definition vector.hpp:85
ace Lane< const VectorType > operator[](const size_t i) const
Access a lane of the vector by index.
Definition vector.hpp:288
Definition vector.hpp:39
A floating-point lane type: float, double, or float16_t where half-float vectors exist.
Definition lane_scalar.hpp:35
A scalar type a vector lane can hold: an arithmetic type, or float16_t where half-float vectors exist...
Definition lane_scalar.hpp:31
Header file for SIMD features and platform detection.
#define ARGON_NEON_FP16_VECTOR
True where NEON has half-precision vector arithmetic (FEAT_FP16), so the f16 forms of vmaxnm/vminnm e...
Definition features.h:93
#define ARGON_HAS_MAXNM
True where vmaxnm/vminnm exist (simd::max_strict / min_strict): Helium with floating point,...
Definition features.h:77
#define ARGON_GCC_AARCH32_FLOAT
True where GCC compiles AArch32 NEON code without -ffast-math: it then scalarises generic vector-exte...
Definition features.h:111
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
constexpr bool is_half_float_v
Whether T is the half-precision lane type, float16_t (__fp16), on a platform with half-float vectors.
Definition lane_scalar.hpp:22
Bool< T >::type Bool_t
Helper alias to get the boolean type of a SIMD operation.
Definition bool.hpp:49
constexpr bool is_one_of
Helper template to check if a type is one of the specified types.
Definition vector.hpp:46
constexpr std::array< helpers::ArgonFor_t< T >, N > to_array(T(&a)[N])
Convert a C-style array of vector types to a std::array of Argon types.
Definition to_array.hpp:31
Lane deconstruction feature.
Definition argon_full.hpp:1547
A per-lane boolean for a SIMD vector type, as returned by comparisons.
Helper functions to convert C-style arrays to std::array of Argon types, mimicking std::to_array.