Argon 0.1.0
Loading...
Searching...
No Matches
argon_full.hpp
1#pragma once
2#include <algorithm>
3#include <array>
4#include <limits>
5#include <numeric>
6#include <type_traits>
7#include <utility>
8#include "arm_simd.hpp"
9#include "helpers.hpp"
10#include "helpers/argon_for.hpp"
11#include "vector.hpp"
12
13#ifdef __ARM_FEATURE_MVE
14#define simd mve
15#else
16#define simd neon
17#endif
18
19#ifdef __clang__
20#define ace [[nodiscard]] [[gnu::always_inline]] constexpr
21#else
22#define ace [[nodiscard]] [[gnu::always_inline]] inline
23#endif
24
30namespace argon {
33template <typename N, typename W>
34concept widenable_from = std::is_integral_v<N> && std::is_integral_v<W> && sizeof(N) < sizeof(W) && sizeof(W) <= 4;
35} // namespace argon
36
37namespace argon {
39enum class DotForm { Plain, Exchange, Subtract, SubtractExchange };
40} // namespace argon
41
42template <typename ScalarType>
44class Argon : public argon::Vector<simd::Vec128_t<ScalarType>> {
46
47 public:
48 using vector_type = simd::Vec128_t<ScalarType>;
49 using lane_type = const argon::Lane<vector_type>;
50
51 static_assert(simd::is_quadword_v<vector_type>);
52
53 static constexpr size_t bytes = 16;
54 static constexpr size_t lanes = bytes / sizeof(ScalarType);
55
56 // The constructors argon::Vector declares, forwarded rather than inherited: an inherited constructor doesn't carry
57 // the base's [[gnu::always_inline]], so under -fno-inline-functions it compiles to an out-of-line call. Not `ace`,
58 // whose [[nodiscard]] argon::Vector's constructors don't have.
59
61 constexpr Argon() = default;
63 [[gnu::always_inline]] constexpr Argon(vector_type vector) : T{vector} {}
65 [[gnu::always_inline]] constexpr Argon(typename T::scalar_type scalar) : T{scalar} {}
67 template <size_t LaneIndex>
68 [[gnu::always_inline]] constexpr Argon(argon::ConstLane<LaneIndex, vector_type> lane) : T{lane} {}
70 template <typename... ArgTypes>
71 requires(sizeof...(ArgTypes) > 1)
72 [[gnu::always_inline]] constexpr Argon(ArgTypes... args) : T{args...} {}
73
79 ace Argon(std::array<ScalarType, 4> value_list) : T{FromFour(value_list)} {};
83 template <typename S = ScalarType>
84 requires std::is_same_v<S, ScalarType>
85 ace Argon(ArgonHalf<S> low, ArgonHalf<S> high) : T{Combine(low, high)} {};
86
87 ace Argon(argon::Lane<vector_type> b) : T{b} {};
88 ace Argon(argon::ConstLane<0, vector_type> b) : T{b} {};
89
90 template <simd::is_vector_type intrinsic_type>
91 ace Argon(argon::Lane<intrinsic_type> b) : T{b} {};
92
96 template <typename new_scalar_type>
98 return simd::reinterpret<simd::Vec128_t<new_scalar_type>>(this->vec_);
99 }
100
101#ifndef ARGON_PLATFORM_MVE
106 return simd::combine(low, high);
107 }
108
112 auto rev_half = this->Reverse64bit();
113 return Combine(rev_half.GetHigh(), rev_half.GetLow());
114 }
115
118 template <typename U>
120 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
122 return simd::multiply_add_long(this->vec_, b, c);
123 }
124
125 template <typename U, typename C>
127 std::is_same_v<C, simd::Vec64_t<argon::helpers::NextSmaller_t<ScalarType>>>
129 return simd::multiply_add_long(this->vec_, b, c);
130 }
131
133 template <typename U>
135 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
137 return simd::multiply_add_long(this->vec_, b, c);
138 }
139
141 template <typename U>
143 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
145 return simd::multiply_add_long(this->vec_, b, c.vec(), c.lane());
146 }
147
149 template <typename U>
151 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
153 return simd::multiply_subtract_long(this->vec_, b, c);
154 }
155
157 template <typename U>
159 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
161 return simd::multiply_subtract_long(this->vec_, b, c);
162 }
163
165 template <typename U>
167 std::is_same_v<U, typename argon::helpers::NextSmaller<ScalarType>::type>
169 return simd::multiply_subtract_long(this->vec_, b, c.vec(), c.lane());
170 }
171
174 ace auto AddNarrow(Argon<ScalarType> b) const
176 {
177 auto result = simd::add_narrow(this->vec_, b);
178 return argon::helpers::ArgonFor_t<decltype(result)>{result};
179 }
180
184 {
185 auto result = simd::add_round_narrow(this->vec_, b);
186 return argon::helpers::ArgonFor_t<decltype(result)>{result};
187 }
188
192 {
193 auto result = simd::subtract_narrow(this->vec_, b);
194 return argon::helpers::ArgonFor_t<decltype(result)>{result};
195 }
196
200 {
201 auto result = simd::subtract_round_narrow(this->vec_, b);
202 return argon::helpers::ArgonFor_t<decltype(result)>{result};
203 }
204
207 template <size_t n>
209 ace auto ShiftRightNarrow() const {
210 auto result = simd::shift_right_narrow<n>(this->vec_);
211 return argon::helpers::ArgonFor_t<decltype(result)>{result};
212 }
213
216 template <size_t n>
218 ace auto ShiftRightSaturateNarrow() const {
219 auto result = simd::shift_right_saturate_narrow<n>(this->vec_);
220 return argon::helpers::ArgonFor_t<decltype(result)>{result};
221 }
222
225 template <size_t n>
228 auto result = simd::shift_right_round_saturate_narrow<n>(this->vec_);
229 return argon::helpers::ArgonFor_t<decltype(result)>{result};
230 }
231
234 template <size_t n>
236 ace auto ShiftRightRoundNarrow() const {
237 auto result = simd::shift_right_round_narrow<n>(this->vec_);
238 return argon::helpers::ArgonFor_t<decltype(result)>{result};
239 }
240
242 ace auto Narrow() const
243 requires argon::helpers::has_smaller_v<ScalarType>
244 {
245 auto result = simd::move_narrow(this->vec_);
246 return argon::helpers::ArgonFor_t<decltype(result)>{result};
247 }
248
250 ace auto SaturateNarrow() const
251 requires argon::helpers::has_smaller_v<ScalarType>
252 {
253 auto result = simd::move_saturate_narrow(this->vec_);
254 return argon::helpers::ArgonFor_t<decltype(result)>{result};
255 }
256
258 template <typename NextSmallerType>
260 std::is_same_v<NextSmallerType, argon::helpers::NextSmaller_t<ScalarType>>
262 return neon::multiply_double_add_saturate_long(this->vec_, b, c);
263 }
264
266 ace ArgonHalf<ScalarType> GetHigh() const { return simd::get_high(this->vec_); }
268 ace ArgonHalf<ScalarType> GetLow() const { return simd::get_low(this->vec_); }
269#endif
270
271 // ── Bottom / top widening and narrowing ─────────────────────────────────────────────────────────────────────
272 // Helium widens and narrows by lane parity rather than by vector half: the "bottom" lanes are the even ones
273 // (0, 2, 4, ...) and the "top" lanes the odd ones. Each pair of narrow lanes shares the bits of one wide lane, so
274 // a narrow vector splits into WidenBottom() and WidenTop(), and NarrowBottom()/NarrowTop() write a wide vector
275 // back into those lanes: hi.NarrowTop(lo.NarrowBottom(dest)) reassembles what WidenBottom/WidenTop took apart.
276 // MVE has an instruction for each; NEON views the narrow vector as the wide type, where the bottom lane is the
277 // low half of each wide lane, and widens with shifts and narrows with a bit select.
278
280 template <typename S = ScalarType>
281 requires(std::is_integral_v<S> && sizeof(S) <= 2)
283#ifdef ARGON_PLATFORM_MVE
284 return mve::move_long_bottom(this->vec_);
285#else
286 constexpr int half = 8 * sizeof(S);
287 return this->template As<argon::helpers::NextLarger_t<S>>().template ShiftLeft<half>().template ShiftRight<half>();
288#endif
289 }
290
292 template <typename S = ScalarType>
293 requires(std::is_integral_v<S> && sizeof(S) <= 2)
295#ifdef ARGON_PLATFORM_MVE
296 return mve::move_long_top(this->vec_);
297#else
298 constexpr int half = 8 * sizeof(S);
299 return this->template As<argon::helpers::NextLarger_t<S>>().template ShiftRight<half>();
300#endif
301 }
302
304 template <int n, typename S = ScalarType>
305 requires(std::is_integral_v<S> && sizeof(S) <= 2 && n >= 1 && n <= 8 * int{sizeof(S)})
307#ifdef ARGON_PLATFORM_MVE
308 return mve::shift_left_long_bottom<n>(this->vec_);
309#else
310 return WidenBottom().template ShiftLeft<n>();
311#endif
312 }
313
315 template <int n, typename S = ScalarType>
316 requires(std::is_integral_v<S> && sizeof(S) <= 2 && n >= 1 && n <= 8 * int{sizeof(S)})
318#ifdef ARGON_PLATFORM_MVE
319 return mve::shift_left_long_top<n>(this->vec_);
320#else
321 return WidenTop().template ShiftLeft<n>();
322#endif
323 }
324
326 template <typename S = ScalarType>
327 requires(std::is_integral_v<S> && sizeof(S) <= 4)
329#ifdef ARGON_PLATFORM_MVE
330 return mve::multiply_long_bottom(this->vec_, b.vec());
331#else
332 return BottomLanes(*this) * BottomLanes(b);
333#endif
334 }
335
337 template <typename S = ScalarType>
338 requires(std::is_integral_v<S> && sizeof(S) <= 4)
340#ifdef ARGON_PLATFORM_MVE
341 return mve::multiply_long_top(this->vec_, b.vec());
342#else
343 return TopLanes(*this) * TopLanes(b);
344#endif
345 }
346
349 template <typename S = ScalarType>
350 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4))
352#ifdef ARGON_PLATFORM_MVE
353 return mve::move_narrow_bottom(dest.vec(), this->vec_);
354#else
355 return InsertBottom(dest, *this);
356#endif
357 }
358
361 template <typename S = ScalarType>
362 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4))
364#ifdef ARGON_PLATFORM_MVE
365 return mve::move_narrow_top(dest.vec(), this->vec_);
366#else
367 return InsertTop(dest, *this);
368#endif
369 }
370
372 template <typename S = ScalarType>
373 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4))
375#ifdef ARGON_PLATFORM_MVE
376 return mve::move_narrow_saturate_bottom(dest.vec(), this->vec_);
377#else
378 return InsertBottom(dest, SaturateToNarrow(*this));
379#endif
380 }
381
383 template <typename S = ScalarType>
384 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4))
386#ifdef ARGON_PLATFORM_MVE
387 return mve::move_narrow_saturate_top(dest.vec(), this->vec_);
388#else
389 return InsertTop(dest, SaturateToNarrow(*this));
390#endif
391 }
392
393#ifdef ARGON_PLATFORM_MVE
394#define ARGON_SHIFT_NARROW_BODY(mve_name, Insert, neon_value) return mve::mve_name<n>(dest.vec(), this->vec_);
395#else
396#define ARGON_SHIFT_NARROW_BODY(mve_name, Insert, neon_value) return Insert(dest, neon_value);
397#endif
398 // Shift right by n, optionally rounding and/or saturating, then narrow into the bottom or top lanes of dest.
399#define ARGON_SHIFT_NARROW(Name, mve_name, Insert, neon_value) \
400 template <int n, typename S = ScalarType> \
401 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4) && n >= 1 && n <= 4 * int{sizeof(S)}) \
402 ace Argon<argon::helpers::NextSmaller_t<S>> Name(Argon<argon::helpers::NextSmaller_t<S>> dest) \
403 const {ARGON_SHIFT_NARROW_BODY(mve_name, Insert, neon_value)}
404
406 ARGON_SHIFT_NARROW(ShiftRightNarrowBottom, shift_right_narrow_bottom, InsertBottom, this->template ShiftRight<n>())
408 ARGON_SHIFT_NARROW(ShiftRightNarrowTop, shift_right_narrow_top, InsertTop, this->template ShiftRight<n>())
410 ARGON_SHIFT_NARROW(ShiftRightRoundNarrowBottom,
411 shift_right_narrow_round_bottom,
412 InsertBottom,
413 this->template ShiftRightRound<n>())
415 ARGON_SHIFT_NARROW(ShiftRightRoundNarrowTop,
416 shift_right_narrow_round_top,
417 InsertTop,
418 this->template ShiftRightRound<n>())
421 ARGON_SHIFT_NARROW(ShiftRightSaturateNarrowBottom,
422 shift_right_narrow_saturate_bottom,
423 InsertBottom,
424 SaturateToNarrow(this->template ShiftRight<n>()))
426 ARGON_SHIFT_NARROW(ShiftRightSaturateNarrowTop,
427 shift_right_narrow_saturate_top,
428 InsertTop,
429 SaturateToNarrow(this->template ShiftRight<n>()))
432 ARGON_SHIFT_NARROW(ShiftRightRoundSaturateNarrowBottom,
433 shift_right_narrow_round_saturate_bottom,
434 InsertBottom,
435 SaturateToNarrow(this->template ShiftRightRound<n>()))
438 ARGON_SHIFT_NARROW(ShiftRightRoundSaturateNarrowTop,
439 shift_right_narrow_round_saturate_top,
440 InsertTop,
441 SaturateToNarrow(this->template ShiftRightRound<n>()))
442#undef ARGON_SHIFT_NARROW
443#undef ARGON_SHIFT_NARROW_BODY
444
445 // ── Dot products ──────────────────────────────────────────────────────────────────────────────────────────
446 // Multiply-accumulate across the vector into a scalar, Helium's vmladav family: FIR filters, convolution and
447 // complex dot products in one instruction. The forms besides Plain treat lanes 2i and 2i+1 as a pair (the real
448 // and imaginary parts of a complex number) and, like the instructions, are signed-only.
449
450 using DotForm = argon::DotForm;
452 using dot_type = std::conditional_t<std::is_signed_v<ScalarType>, int32_t, uint32_t>;
454 using dot_long_type = std::conditional_t<std::is_signed_v<ScalarType>, int64_t, uint64_t>;
455
460 template <DotForm form = DotForm::Plain, typename S = ScalarType>
461 requires(std::is_integral_v<S> && sizeof(S) <= 4 && (form == DotForm::Plain || std::is_signed_v<S>))
462 ace dot_type DotProduct(Argon<S> b, dot_type acc = 0) const {
463#ifdef ARGON_PLATFORM_MVE
464 if constexpr (form == DotForm::Plain) {
465 return mve::multiply_add_dual_reduce_add_accumulate(acc, this->vec_, b.vec());
466 } else if constexpr (form == DotForm::Exchange) {
467 return mve::multiply_add_dual_reduce_add_accumulate_exchange_pairs(acc, this->vec_, b.vec());
468 } else if constexpr (form == DotForm::Subtract) {
469 return mve::multiply_subtract_dual_reduce_add_accumulate(acc, this->vec_, b.vec());
470 } else {
471 return mve::multiply_subtract_dual_reduce_add_accumulate_exchange_pairs(acc, this->vec_, b.vec());
472 }
473#else
474 using U = std::make_unsigned_t<dot_type>; // wrapping arithmetic
475 if constexpr (form == DotForm::Plain) {
476 // A sum doesn't care about lane order, so use NEON's own shape: multiply-long the low and high halves
477 // (smull/smull2), widen pairwise (vpaddl), and reduce the 32-bit lanes.
478 dot_type lanes_sum;
479 if constexpr (sizeof(S) == 1) {
480 auto low = this->GetLow().MultiplyLong(b.GetLow()), high = this->GetHigh().MultiplyLong(b.GetHigh());
481 lanes_sum =
482 (Argon<dot_type>{neon::pairwise_add_long(low.vec())} + Argon<dot_type>{neon::pairwise_add_long(high.vec())})
483 .ReduceAdd();
484 } else if constexpr (sizeof(S) == 2) {
485 lanes_sum = (this->GetLow().MultiplyLong(b.GetLow()) + this->GetHigh().MultiplyLong(b.GetHigh())).ReduceAdd();
486 } else {
487 lanes_sum = (*this * b).ReduceAdd();
488 }
489 return static_cast<dot_type>(static_cast<U>(acc) + static_cast<U>(lanes_sum));
490 } else {
491 U sum = static_cast<U>(acc);
492 for (auto p : DotProducts<form>(b))
493 sum += static_cast<U>(p);
494 return static_cast<dot_type>(sum);
495 }
496#endif
497 }
498
501 template <DotForm form = DotForm::Plain, typename S = ScalarType>
502 requires(std::is_integral_v<S> && (sizeof(S) == 2 || sizeof(S) == 4) &&
503 (form == DotForm::Plain || std::is_signed_v<S>))
505#ifdef ARGON_PLATFORM_MVE
506 if constexpr (form == DotForm::Plain) {
507 return mve::multiply_add_long_dual_reduce_add_accumulate(acc, this->vec_, b.vec());
508 } else if constexpr (form == DotForm::Exchange) {
509 return mve::multiply_add_long_dual_reduce_add_accumulate_exchange_pairs(acc, this->vec_, b.vec());
510 } else if constexpr (form == DotForm::Subtract) {
511 return mve::multiply_subtract_long_dual_reduce_add_accumulate(acc, this->vec_, b.vec());
512 } else {
513 return mve::multiply_subtract_long_dual_reduce_add_accumulate_exchange_pairs(acc, this->vec_, b.vec());
514 }
515#else
516 if constexpr (form == DotForm::Plain && sizeof(S) == 2) {
517 // smull/smull2, then widen pairwise into 64-bit lanes (vpaddl) and reduce.
518 const auto low = this->GetLow().MultiplyLong(b.GetLow()), high = this->GetHigh().MultiplyLong(b.GetHigh());
519 const auto lanes_sum = (Argon<dot_long_type>{neon::pairwise_add_long(low.vec())} +
520 Argon<dot_long_type>{neon::pairwise_add_long(high.vec())})
521 .ReduceAdd();
522 return static_cast<dot_long_type>(static_cast<uint64_t>(acc) + static_cast<uint64_t>(lanes_sum));
523 } else {
524 uint64_t sum = static_cast<uint64_t>(acc);
525 for (auto p : DotProducts<form>(b))
526 sum += static_cast<uint64_t>(static_cast<dot_long_type>(p));
527 return static_cast<dot_long_type>(sum);
528 }
529#endif
530 }
531
536 template <DotForm form = DotForm::Plain, typename S = ScalarType>
537 requires(std::is_integral_v<S> && sizeof(S) == 4 && (form == DotForm::Plain || std::is_signed_v<S>))
539#ifdef ARGON_PLATFORM_MVE
540 if constexpr (form == DotForm::Plain) {
541 return mve::multiply_add_long_round_dual_reduce_add_high_accumulate(acc, this->vec_, b.vec());
542 } else if constexpr (form == DotForm::Exchange) {
543 return mve::multiply_add_long_round_dual_reduce_add_high_accumulate_exchange_pairs(acc, this->vec_, b.vec());
544 } else if constexpr (form == DotForm::Subtract) {
545 return mve::multiply_subtract_long_round_dual_reduce_add_high_accumulate(acc, this->vec_, b.vec());
546 } else {
547 return mve::multiply_subtract_long_round_dual_reduce_add_high_accumulate_exchange_pairs(acc, this->vec_, b.vec());
548 }
549#else
550 uint64_t sum = static_cast<uint64_t>(acc);
551 for (auto p : DotProducts<form>(b)) {
552 sum += static_cast<uint64_t>((p + 128) >> 8); // arithmetic shift for signed lanes; no overflow at 32x32 bits
553 }
554 return static_cast<dot_long_type>(sum);
555#endif
556 }
557
561 template <typename S = ScalarType>
562 requires(std::is_integral_v<S> && std::is_signed_v<S> && sizeof(S) <= 4)
563 ace std::pair<dot_type, dot_type> ComplexDotProduct(Argon<S> b) const {
565 }
566
567 // ── Circular-buffer indices ───────────────────────────────────────────────────────────────────────────────
568 // Index vectors for walking a ring buffer (a delay line, a wavetable), ready to feed a gather. MVE generates each
569 // in one instruction (viwdup / vdwdup); NEON replays the same lane-by-lane rule.
570
577 template <int step = 1, typename S = ScalarType>
578 requires(std::is_unsigned_v<S> && sizeof(S) <= 4 && (step == 1 || step == 2 || step == 4 || step == 8))
579 ace static Argon<S> CircularIndices(uint32_t& offset, uint32_t size) {
580#ifdef ARGON_PLATFORM_MVE
581 // Write back through a local: GCC 16 at -O0 rejects the _wb intrinsics given any other pointer
582 // ("unrecognizable insn"), including through a wrapper.
583 uint32_t next = offset;
584 typename Argon<S>::vector_type indices;
585 if constexpr (sizeof(S) == 1) {
586 indices = viwdupq_wb_u8(&next, size, step);
587 } else if constexpr (sizeof(S) == 2) {
588 indices = viwdupq_wb_u16(&next, size, step);
589 } else {
590 indices = viwdupq_wb_u32(&next, size, step);
591 }
592 offset = next;
593 return indices;
594#else
595 std::array<S, lanes> out{};
596 for (auto& lane : out) {
597 lane = static_cast<S>(offset);
598 offset += step;
599 if (offset == size)
600 offset = 0;
601 }
602 return Argon<S>::Load(out.data());
603#endif
604 }
605
611 template <int step = 1, typename S = ScalarType>
612 requires(std::is_unsigned_v<S> && sizeof(S) <= 4 && (step == 1 || step == 2 || step == 4 || step == 8))
613 ace static Argon<S> CircularIndicesDown(uint32_t& offset, uint32_t size) {
614#ifdef ARGON_PLATFORM_MVE
615 uint32_t next = offset; // see CircularIndices
616 typename Argon<S>::vector_type indices;
617 if constexpr (sizeof(S) == 1) {
618 indices = vdwdupq_wb_u8(&next, size, step);
619 } else if constexpr (sizeof(S) == 2) {
620 indices = vdwdupq_wb_u16(&next, size, step);
621 } else {
622 indices = vdwdupq_wb_u32(&next, size, step);
623 }
624 offset = next;
625 return indices;
626#else
627 std::array<S, lanes> out{};
628 for (auto& lane : out) {
629 lane = static_cast<S>(offset);
630 if (offset == 0)
631 offset = size;
632 offset -= step;
633 }
634 return Argon<S>::Load(out.data());
635#endif
636 }
637
638 // ── Widening loads and narrowing stores ─────────────────────────────────────────────────────────────────
639 // Narrow data in memory, wide lanes in registers: int16 samples straight into int32 lanes and back, with the
640 // conversion folded into the memory access. Loads extend by the source type's signedness (so uint8 data loads
641 // into int32 lanes as 0..255); stores keep the low bits of each lane. MVE: one vldrb/vldrh / vstrb/vstrh (also as
642 // gathers and scatters); NEON: vld1 + vmovl / vmovn + vst1 for a 2x ratio, lane by lane otherwise. The lane walks
643 // index std::array through its non-const data(), which libstdc++ marks always-inline (operator[] it doesn't).
644
646 template <typename N, typename S = ScalarType>
648 ace static Argon<S> LoadWiden(const N* ptr) {
649#ifdef ARGON_PLATFORM_MVE
650 return Argon<S>{WidenMve<N, S>(ptr)};
651#else
652 if constexpr (sizeof(S) == 2 * sizeof(N)) {
653 // vld1 of the lanes' worth of narrow elements (64 bits), then vmovl
654 const auto wide = neon::move_long(neon::load1<neon::Vec64_t<N>>(ptr));
655 return Argon<std::conditional_t<std::is_signed_v<N>, std::make_signed_t<S>, std::make_unsigned_t<S>>>{wide}
656 .template As<S>();
657 } else {
658 std::array<S, lanes> out{};
659 for (size_t i = 0; i < lanes; ++i)
660 out.data()[i] = static_cast<S>(ptr[i]);
661 return Argon<S>::Load(out.data());
662 }
663#endif
664 }
665
668 template <typename N, typename S = ScalarType>
670 ace static Argon<S> LoadWiden(const N* ptr, typename Argon<S>::argon_bool_type active) {
671#ifdef ARGON_PLATFORM_MVE
672 return Argon<S>{WidenMve<N, S>(ptr, active.native())};
673#else
674 std::array<S, lanes> out{};
675 for (size_t i = 0; i < lanes; ++i) {
676 if (active.Active(i))
677 out.data()[i] = static_cast<S>(ptr[i]);
678 }
679 return Argon<S>::Load(out.data());
680#endif
681 }
682
684 template <typename N, typename S = ScalarType>
686 [[gnu::always_inline]] inline void StoreNarrow(N* ptr) const {
687#ifdef ARGON_PLATFORM_MVE
688 NarrowMve<N>(ptr);
689#else
690 if constexpr (sizeof(S) == 2 * sizeof(N)) {
691 // vmovn, then vst1 of the 64-bit result
692 using SameSign = std::conditional_t<std::is_signed_v<N>, std::make_signed_t<S>, std::make_unsigned_t<S>>;
693 neon::store1(ptr, neon::move_narrow(this->template As<SameSign>().vec()));
694 } else {
695 auto values = this->to_array();
696 for (size_t i = 0; i < lanes; ++i)
697 ptr[i] = static_cast<N>(values.data()[i]);
698 }
699#endif
700 }
701
703 template <typename N, typename S = ScalarType>
705 [[gnu::always_inline]] inline void StoreNarrow(N* ptr, typename Argon<S>::argon_bool_type active) const {
706#ifdef ARGON_PLATFORM_MVE
707 NarrowMve<N>(ptr, active.native());
708#else
709 auto values = this->to_array();
710 for (size_t i = 0; i < lanes; ++i) {
711 if (active.Active(i))
712 ptr[i] = static_cast<N>(values.data()[i]);
713 }
714#endif
715 }
716
718 template <typename N, typename S = ScalarType, typename... PredicateType>
719 requires(argon::widenable_from<N, S> && sizeof...(PredicateType) <= 1)
720 ace static Argon<S> LoadGatherOffsetIndexWiden(const N* base,
721 typename Argon<S>::offset_type offsets,
722 PredicateType... active) {
723 return GatherWiden<false, N, S>(base, offsets, active...);
724 }
725
727 template <typename N, typename S = ScalarType, typename... PredicateType>
728 requires(argon::widenable_from<N, S> && sizeof...(PredicateType) <= 1)
729 ace static Argon<S> LoadGatherOffsetBytesWiden(const N* base,
730 typename Argon<S>::offset_type offsets,
731 PredicateType... active) {
732 return GatherWiden<true, N, S>(base, offsets, active...);
733 }
734
736 template <typename N, typename S = ScalarType, typename... PredicateType>
737 requires(argon::widenable_from<N, S> && sizeof...(PredicateType) <= 1)
738 [[gnu::always_inline]] inline void StoreScatterOffsetIndexNarrow(N* base,
739 typename Argon<S>::offset_type offsets,
740 PredicateType... active) const {
741 ScatterNarrow<false>(base, offsets, active...);
742 }
743
745 template <typename N, typename S = ScalarType, typename... PredicateType>
746 requires(argon::widenable_from<N, S> && sizeof...(PredicateType) <= 1)
747 [[gnu::always_inline]] inline void StoreScatterOffsetBytesNarrow(N* base,
748 typename Argon<S>::offset_type offsets,
749 PredicateType... active) const {
750 ScatterNarrow<true>(base, offsets, active...);
751 }
752
753 // ── Complex arithmetic ────────────────────────────────────────────────────────────────────────────────────
754 // Lanes 2i and 2i+1 hold the real and imaginary parts of a complex number. MVE has these as instructions
755 // (vcadd, vhcadd, vcmla); NEON has the float ones from Armv8.3 (FEAT_FCMA), and otherwise swaps each pair with a
756 // vrev and blends the even and odd lanes.
757
759 template <typename S = ScalarType>
760 requires(sizeof(S) <= 4)
762#ifdef ARGON_PLATFORM_MVE
763 if constexpr (argon::lane_floating_point<S>) {
764 if constexpr (sizeof(S) == 2) {
765 return vcaddq_rot90_f16(this->vec_, b.vec());
766 } else {
767 return vcaddq_rot90_f32(this->vec_, b.vec());
768 }
769 } else {
770 return mve::complex_add_rotate_90(this->vec_, b.vec());
771 }
772#else
773#ifdef __ARM_FEATURE_COMPLEX
774 if constexpr (argon::lane_floating_point<S>)
775 return neon::complex_add_rotate_90(this->vec_, b.vec());
776#endif
777 const auto swapped = SwapPairs(b);
778 return EvenLanes().Select(*this - swapped, *this + swapped);
779#endif
780 }
781
783 template <typename S = ScalarType>
784 requires(sizeof(S) <= 4)
786#ifdef ARGON_PLATFORM_MVE
787 if constexpr (argon::lane_floating_point<S>) {
788 if constexpr (sizeof(S) == 2) {
789 return vcaddq_rot270_f16(this->vec_, b.vec());
790 } else {
791 return vcaddq_rot270_f32(this->vec_, b.vec());
792 }
793 } else {
794 return mve::complex_add_rotate_270(this->vec_, b.vec());
795 }
796#else
797#ifdef __ARM_FEATURE_COMPLEX
798 if constexpr (argon::lane_floating_point<S>)
799 return neon::complex_add_rotate_270(this->vec_, b.vec());
800#endif
801 const auto swapped = SwapPairs(b);
802 return EvenLanes().Select(*this + swapped, *this - swapped);
803#endif
804 }
805
807 template <typename S = ScalarType>
808 requires(std::is_integral_v<S> && std::is_signed_v<S> && sizeof(S) <= 4)
810#ifdef ARGON_PLATFORM_MVE
811 return mve::complex_add_rotate_90_halve(this->vec_, b.vec());
812#else
813 const auto swapped = SwapPairs(b);
814 return EvenLanes().Select(this->SubtractHalve(swapped), this->AddHalve(swapped));
815#endif
816 }
817
819 template <typename S = ScalarType>
820 requires(std::is_integral_v<S> && std::is_signed_v<S> && sizeof(S) <= 4)
822#ifdef ARGON_PLATFORM_MVE
823 return mve::complex_add_rotate_270_halve(this->vec_, b.vec());
824#else
825 const auto swapped = SwapPairs(b);
826 return EvenLanes().Select(this->AddHalve(swapped), this->SubtractHalve(swapped));
827#endif
828 }
829
834 template <int rotation, typename S = ScalarType>
835 requires(argon::lane_floating_point<S> && sizeof(S) <= 4 &&
836 (rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270))
838#if defined(ARGON_PLATFORM_MVE) || defined(__ARM_FEATURE_COMPLEX)
839 if constexpr (rotation == 0) {
840 return simd::complex_multiply_add(this->vec_, b.vec(), c.vec());
841 } else if constexpr (rotation == 90) {
842 return simd::complex_multiply_add_rotate_90(this->vec_, b.vec(), c.vec());
843 } else if constexpr (rotation == 180) {
844 return simd::complex_multiply_add_rotate_180(this->vec_, b.vec(), c.vec());
845 } else {
846 return simd::complex_multiply_add_rotate_270(this->vec_, b.vec(), c.vec());
847 }
848#else
849 const auto even = EvenLanes();
850 if constexpr (rotation == 0 || rotation == 180) {
851 const auto real = even.Select(b, SwapPairs(b)); // (b.re, b.re)
852 return rotation == 0 ? this->MultiplyAdd(real, c) : this->MultiplySubtract(real, c);
853 } else {
854 const auto imag = even.Select(SwapPairs(b), b); // (b.im, b.im)
855 const auto swapped = SwapPairs(c); // (c.im, c.re)
856 const auto minus = this->MultiplySubtract(imag, swapped), plus = this->MultiplyAdd(imag, swapped);
857 return rotation == 90 ? even.Select(minus, plus) : even.Select(plus, minus);
858 }
859#endif
860 }
861
863 template <typename S = ScalarType>
864 requires(argon::lane_floating_point<S> && sizeof(S) <= 4)
866 const Argon<S> zero{S(0)};
867 return zero.template ComplexMultiplyAdd<0>(*this, b).template ComplexMultiplyAdd<90>(*this, b);
868 }
869
871 template <typename S = ScalarType>
872 requires(argon::lane_floating_point<S> && sizeof(S) <= 4)
874 const Argon<S> zero{S(0)};
875 return zero.template ComplexMultiplyAdd<0>(b, *this).template ComplexMultiplyAdd<270>(b, *this);
876 }
877
878 // ── Bit-reversed indices ──────────────────────────────────────────────────────────────────────────────────
879
883 template <typename S = ScalarType>
884 requires(std::is_integral_v<S> && sizeof(S) <= 4)
885 ace Argon<S> BitReverse(int bits) const {
886#ifdef ARGON_PLATFORM_MVE
887 return mve::bit_reverse_shift_right(this->vec_, static_cast<int32_t>(bits));
888#else
889 using U = std::make_unsigned_t<S>;
890 constexpr int width = 8 * sizeof(S);
891 if (bits <= 0)
892 return Argon<S>{S(0)};
893 // Reverse the bits of each byte, then the bytes of each lane.
894 Argon<uint8_t> bytes = this->template As<uint8_t>();
895#ifdef __aarch64__
896 bytes = neon::reverse_bits(bytes.vec()); // rbit
897#else
898 bytes = ((bytes >> 1) & Argon<uint8_t>{uint8_t{0x55}}) | ((bytes & Argon<uint8_t>{uint8_t{0x55}}) << 1);
899 bytes = ((bytes >> 2) & Argon<uint8_t>{uint8_t{0x33}}) | ((bytes & Argon<uint8_t>{uint8_t{0x33}}) << 2);
900 bytes = (bytes >> 4) | (bytes << 4);
901#endif
902 if constexpr (sizeof(S) == 2) {
903 bytes = bytes.Reverse16bit();
904 } else if constexpr (sizeof(S) == 4) {
905 bytes = bytes.Reverse32bit();
906 }
907 const auto reversed = bytes.template As<U>();
908 return (bits >= width ? reversed : reversed >> (width - bits)).template As<S>(); // logical shift
909#endif
910 }
911
912 // ── Carry chains ──────────────────────────────────────────────────────────────────────────────────────────
913 // The vector as one 128-bit number, lane 0 least significant, for multi-word arithmetic and bitstreams. MVE has
914 // instructions for these (vadc, vsbc, vshlc); NEON works through the 32-bit words one at a time.
915
918 template <typename S = ScalarType>
919 requires(std::is_integral_v<S> && sizeof(S) == 4)
920 ace Argon<S> AddWithCarry(Argon<S> b, uint32_t& carry) const {
921#ifdef ARGON_PLATFORM_MVE
922 unsigned c = carry & 1; // through a local: see CircularIndices
923 Argon<S> out;
924 if constexpr (std::is_signed_v<S>) {
925 out = vadcq_s32(this->vec_, b.vec(), &c);
926 } else {
927 out = vadcq_u32(this->vec_, b.vec(), &c);
928 }
929 carry = c;
930 return out;
931#else
932 const auto x = this->template As<uint32_t>().to_array(), y = b.template As<uint32_t>().to_array();
933 std::array<uint32_t, 4> sum{};
934 uint64_t c = carry & 1;
935 for (size_t i = 0; i < 4; ++i) {
936 c += uint64_t{x[i]} + y[i];
937 sum[i] = static_cast<uint32_t>(c);
938 c >>= 32;
939 }
940 carry = static_cast<uint32_t>(c);
941 return Argon<uint32_t>::Load(sum.data()).template As<S>();
942#endif
943 }
944
947 template <typename S = ScalarType>
948 requires(std::is_integral_v<S> && sizeof(S) == 4)
949 ace Argon<S> SubtractWithBorrow(Argon<S> b, uint32_t& borrow) const {
950#ifdef ARGON_PLATFORM_MVE
951 unsigned c = 1 - (borrow & 1);
952 Argon<S> out;
953 if constexpr (std::is_signed_v<S>) {
954 out = vsbcq_s32(this->vec_, b.vec(), &c);
955 } else {
956 out = vsbcq_u32(this->vec_, b.vec(), &c);
957 }
958 borrow = 1 - c;
959 return out;
960#else
961 const auto x = this->template As<uint32_t>().to_array(), y = b.template As<uint32_t>().to_array();
962 std::array<uint32_t, 4> difference{};
963 uint64_t owed = borrow & 1;
964 for (size_t i = 0; i < 4; ++i) {
965 const uint64_t subtrahend = uint64_t{y[i]} + owed;
966 difference[i] = static_cast<uint32_t>(uint64_t{x[i]} - subtrahend);
967 owed = subtrahend > x[i];
968 }
969 borrow = static_cast<uint32_t>(owed);
970 return Argon<uint32_t>::Load(difference.data()).template As<S>();
971#endif
972 }
973
977 template <int n, typename S = ScalarType>
978 requires(std::is_integral_v<S> && sizeof(S) <= 4 && n >= 1 && n <= 32)
979 ace Argon<S> ShiftLeftWithCarry(uint32_t& carry) const {
980#ifdef ARGON_PLATFORM_MVE
981 uint32_t c = carry;
982 const auto words = this->template As<uint32_t>().vec();
983 const Argon<uint32_t> out = vshlcq_u32(words, &c, n);
984 carry = c;
985 return out.template As<S>();
986#else
987 const auto x = this->template As<uint32_t>().to_array();
988 std::array<uint32_t, 4> shifted{};
989 const uint64_t in_mask = n == 32 ? ~uint32_t{0} : ((uint32_t{1} << n) - 1);
990 uint64_t incoming = carry & in_mask;
991 for (size_t i = 0; i < 4; ++i) {
992 const uint64_t wide = (uint64_t{x[i]} << n) | incoming;
993 shifted[i] = static_cast<uint32_t>(wide);
994 incoming = wide >> 32;
995 }
996 carry = static_cast<uint32_t>(incoming);
997 return Argon<uint32_t>::Load(shifted.data()).template As<S>();
998#endif
999 }
1000
1003 template <typename U>
1004 ace Argon<U> ConvertTo() const {
1005#ifndef __ARM_FEATURE_MVE
1006 // vcvt semantics (truncate, saturate, NaN -> 0) on every compiler: see helpers/float_fixups.hpp
1007 if constexpr (std::is_same_v<ScalarType, float> && std::is_same_v<U, int32_t>) {
1008 return argon::helpers::convert_to_int32(this->vec_);
1009 } else if constexpr (std::is_same_v<ScalarType, float> && std::is_same_v<U, uint32_t>) {
1010 return argon::helpers::convert_to_uint32(this->vec_);
1011 }
1012#endif
1013 return simd::convert<typename simd::Vec128<U>::type>(this->vec_);
1014 }
1015
1019 template <typename U, int fracbits>
1020 requires(std::is_same_v<U, uint32_t> || std::is_same_v<U, int32_t> || std::is_same_v<U, float>)
1021 ace Argon<U> ConvertTo() const {
1022 if constexpr (std::is_same_v<U, float>) {
1023 return simd::convert_n<fracbits>(this->vec_);
1024 } else if constexpr (std::is_unsigned_v<U>) {
1025#ifndef __ARM_FEATURE_MVE
1026 return argon::helpers::convert_n_to_uint32<fracbits>(this->vec_);
1027#else
1028 return simd::convert_n_unsigned<fracbits>(this->vec_);
1029#endif
1030 } else if constexpr (std::is_signed_v<U>) {
1031#ifndef __ARM_FEATURE_MVE
1032 return argon::helpers::convert_n_to_int32<fracbits>(this->vec_);
1033#else
1034 return simd::convert_n_signed<fracbits>(this->vec_);
1035#endif
1036 }
1037 }
1038
1042 return Argon<ScalarType>{this->Reverse64bit()}.SwapDoublewords(); // rev within dword, then swap dwords
1043 }
1044
1045#ifdef ARGON_PLATFORM_MVE
1047 static constexpr bool mve_across_add = std::is_integral_v<ScalarType> && sizeof(ScalarType) < 8;
1048#endif
1049
1050#ifdef ARGON_PLATFORM_MVE
1054 template <typename OpType>
1055 ScalarType FoldFloatPairs(OpType op) const {
1056 if constexpr (lanes == 4) {
1057 Argon pairs = op(*this, this->Reverse64bit()); // lane 2k: (2k) op (2k + 1)
1058 return static_cast<ScalarType>(op(pairs[0], pairs[2]));
1059 } else {
1060 Argon pairs = op(*this, this->Reverse32bit()); // lane 2k: (2k) op (2k + 1)
1061 Argon quads = op(pairs, pairs.Reverse64bit()); // lane 4k: lanes 4k .. 4k + 3
1062 return static_cast<ScalarType>(op(quads[0], quads[4]));
1063 }
1064 }
1065#endif
1066
1067#ifdef ARGON_PLATFORM_NEON
1069 static constexpr bool neon_pairwise_lanes =
1070 (std::is_integral_v<ScalarType> && sizeof(ScalarType) <= 4) || std::is_same_v<ScalarType, float>;
1071
1078 template <typename HalfOp, typename PairwiseOp>
1079 ace ScalarType FoldHalves(HalfOp op, PairwiseOp pairwise) const {
1080 auto half = op(this->GetLow(), this->GetHigh());
1081 if constexpr (lanes >= 4) {
1082 half = pairwise(half);
1083 }
1084 if constexpr (lanes >= 8) {
1085 half = pairwise(half);
1086 }
1087 if constexpr (lanes >= 16) {
1088 half = pairwise(half);
1089 }
1090 return half[0];
1091 }
1092#endif
1093
1098 template <typename CommutableOpType>
1099 ScalarType Reduce(CommutableOpType op) const {
1100 auto rev = this->SwapDoublewords();
1101 auto sum = op(*this, rev);
1102 if constexpr (lanes == 16) {
1103 sum = op(sum, sum.Reverse16bit());
1104 }
1105 if constexpr (lanes == 8 || lanes == 16) {
1106 sum = op(sum, sum.Reverse32bit());
1107 }
1108 if constexpr (lanes == 4 || lanes == 8 || lanes == 16) {
1109 sum = op(sum, sum.Reverse64bit());
1110 }
1111 return sum[0];
1112 }
1113
1115 ScalarType ReduceAdd() const {
1116#if defined(__aarch64__)
1117 if constexpr (!argon::is_half_float_v<ScalarType>) { // A64 has no across-vector f16 add
1118 return simd::reduce_add(this->vec_);
1119 }
1120#elifdef ARGON_PLATFORM_MVE
1121 if constexpr (mve_across_add) {
1122 return static_cast<ScalarType>(mve::reduce_add(this->vec_)); // vaddv
1123 } else if constexpr (argon::lane_floating_point<ScalarType>) {
1124 // MVE has no float vaddv: ((0 + 1) + (2 + 3)), as AArch64's faddp does.
1125 return FoldFloatPairs([](auto a, auto b) { return a + b; });
1126 }
1127#elifdef ARGON_PLATFORM_NEON
1128 if constexpr (neon_pairwise_lanes) {
1129 return FoldHalves([](auto a, auto b) { return a.Add(b); }, [](auto h) { return h.PairwiseAdd(h); });
1130 }
1131#endif
1132 return this->Reduce([](auto a, auto b) { return a + b; });
1133 }
1134
1139 ScalarType ReduceAdd(typename T::argon_bool_type active) const {
1140#ifdef ARGON_PLATFORM_MVE
1141 if constexpr (mve_across_add) {
1142 return static_cast<ScalarType>(mve::reduce_add(this->vec_, active.native()));
1143 }
1144#endif
1145 return active.Select(*this, Argon<ScalarType>{ScalarType{0}}).ReduceAdd();
1146 }
1147
1149 ScalarType ReduceMax() const {
1150#ifdef __aarch64__
1151 if constexpr (requires { simd::reduce_max(this->vec_); }) {
1152 return simd::reduce_max(this->vec_);
1153 } else { // A64 has no 64-bit integer across-vector max
1154 auto arr = this->to_array();
1155 return std::reduce(arr.begin(), arr.end(), arr[0], [](auto a, auto b) { return std::max(a, b); });
1156 }
1157#else
1158#ifdef ARGON_PLATFORM_MVE
1159 if constexpr (std::is_integral_v<ScalarType> && sizeof(ScalarType) <= 4) {
1160 return mve::maximum_across_vector(std::numeric_limits<ScalarType>::lowest(), this->vec_); // vmaxv
1161 } else if constexpr (argon::lane_floating_point<ScalarType>) {
1162 // vmaxnmv would skip NaNs; keep Max's a > b ? a : b
1163 return FoldFloatPairs([](auto a, auto b) {
1164 if constexpr (requires { a.Max(b); }) {
1165 return a.Max(b);
1166 } else {
1167 return a > b ? a : b;
1168 }
1169 });
1170 }
1171#endif
1172#ifdef ARGON_PLATFORM_NEON
1173 if constexpr (neon_pairwise_lanes) {
1174 return FoldHalves([](auto a, auto b) { return a.Max(b); }, [](auto h) { return h.PairwiseMax(h); });
1175 }
1176#endif
1177 return this->Reduce([](auto a, auto b) { return a.Max(b); });
1178#endif
1179 }
1180
1182 ScalarType ReduceMin() const {
1183#ifdef __aarch64__
1184 if constexpr (requires { simd::reduce_min(this->vec_); }) {
1185 return simd::reduce_min(this->vec_);
1186 } else { // A64 has no 64-bit integer across-vector min
1187 auto arr = this->to_array();
1188 return std::reduce(arr.begin(), arr.end(), arr[0], [](auto a, auto b) { return std::min(a, b); });
1189 }
1190#else
1191#ifdef ARGON_PLATFORM_MVE
1192 if constexpr (std::is_integral_v<ScalarType> && sizeof(ScalarType) <= 4) {
1193 return mve::minimum_across_vector(std::numeric_limits<ScalarType>::max(), this->vec_); // vminv
1194 } else if constexpr (argon::lane_floating_point<ScalarType>) {
1195 // vminnmv would skip NaNs; keep Min's a < b ? a : b
1196 return FoldFloatPairs([](auto a, auto b) {
1197 if constexpr (requires { a.Min(b); }) {
1198 return a.Min(b);
1199 } else {
1200 return a < b ? a : b;
1201 }
1202 });
1203 }
1204#endif
1205#ifdef ARGON_PLATFORM_NEON
1206 if constexpr (neon_pairwise_lanes) {
1207 return FoldHalves([](auto a, auto b) { return a.Min(b); }, [](auto h) { return h.PairwiseMin(h); });
1208 }
1209#endif
1210 auto arr = this->to_array();
1211 return std::reduce(arr.begin(), arr.end(), arr[0], [](auto a, auto b) { return std::min(a, b); });
1212#endif
1213 }
1214
1217 template <typename S = ScalarType>
1218 requires(std::is_integral_v<S> && std::is_signed_v<S> && sizeof(S) <= 4)
1219 ace std::make_unsigned_t<S> ReduceMaxAbs(std::make_unsigned_t<S> init = 0) const {
1220#ifdef ARGON_PLATFORM_MVE
1221 return mve::maximum_absolute_across_vector(init, this->vec_);
1222#else
1223 using U = std::make_unsigned_t<S>;
1224 return std::max(init, this->Absolute().template As<U>().ReduceMax()); // vabs wraps INT_MIN to its magnitude
1225#endif
1226 }
1227
1230 template <typename S = ScalarType>
1231 requires(std::is_integral_v<S> && std::is_signed_v<S> && sizeof(S) <= 4)
1232 ace std::make_unsigned_t<S> ReduceMinAbs(
1233 std::make_unsigned_t<S> init = std::numeric_limits<std::make_unsigned_t<S>>::max()) const {
1234#ifdef ARGON_PLATFORM_MVE
1235 return mve::minimum_absolute_across_vector(init, this->vec_);
1236#else
1237 using U = std::make_unsigned_t<S>;
1238 return std::min(init, this->Absolute().template As<U>().ReduceMin());
1239#endif
1240 }
1241
1244 template <typename S = ScalarType>
1245 requires(std::is_integral_v<S> && std::is_unsigned_v<S> && sizeof(S) <= 4)
1246 ace Argon<S> MaxAbs(Argon<std::make_signed_t<S>> b) const {
1247#ifdef ARGON_PLATFORM_MVE
1248 return mve::maximum_absolute(this->vec_, b.vec());
1249#else
1250 return this->Max(b.Absolute().template As<S>());
1251#endif
1252 }
1253
1255 template <typename S = ScalarType>
1256 requires(std::is_integral_v<S> && std::is_unsigned_v<S> && sizeof(S) <= 4)
1257 ace Argon<S> MinAbs(Argon<std::make_signed_t<S>> b) const {
1258#ifdef ARGON_PLATFORM_MVE
1259 return mve::minimum_absolute(this->vec_, b.vec());
1260#else
1261 return this->Min(b.Absolute().template As<S>());
1262#endif
1263 }
1264
1267#ifdef ARGON_PLATFORM_MVE
1268 // MVE has no half-vector registers or vext; swap the two 64-bit lanes instead.
1269 uint64x2_t dwords = simd::reinterpret<uint64x2_t>(this->vec_);
1270 return simd::reinterpret<vector_type>(uint64x2_t{dwords[1], dwords[0]});
1271#else
1272 // vext by half the lanes swaps the doublewords in one instruction.
1273 return this->template Extract<lanes / 2>(*this);
1274#endif
1275 }
1276
1277#if ARGON_HAS_CRYPTO && !defined(ARGON_PLATFORM_MVE)
1282 ace Argon<ScalarType> AesEncrypt(Argon<ScalarType> key) const
1283 requires std::is_same_v<ScalarType, uint8_t>
1284 {
1285 return neon::aes_encrypt(this->vec_, key.vec_);
1286 }
1287
1292 ace Argon<ScalarType> AesDecrypt(Argon<ScalarType> key) const
1293 requires std::is_same_v<ScalarType, uint8_t>
1294 {
1295 return neon::aes_decrypt(this->vec_, key.vec_);
1296 }
1297
1301 ace Argon<ScalarType> AesMixColumns() const
1302 requires std::is_same_v<ScalarType, uint8_t>
1303 {
1304 return neon::aes_mix_columns(this->vec_);
1305 }
1306
1310 ace Argon<ScalarType> AesInverseMixColumns() const
1311 requires std::is_same_v<ScalarType, uint8_t>
1312 {
1313 return neon::aes_inverse_mix_columns(this->vec_);
1314 }
1315#endif
1316
1317 private:
1318#ifndef ARGON_PLATFORM_MVE
1319 // NEON helpers for the bottom/top operations. A narrow vector viewed as the next larger type has its bottom
1320 // (even) lane in the low half of each wide lane and its top (odd) lane in the high half.
1321
1323 template <typename S>
1324 ace static Argon<argon::helpers::NextLarger_t<S>> BottomLanes(Argon<S> v) {
1325 constexpr int half = 8 * sizeof(S);
1326 return v.template As<argon::helpers::NextLarger_t<S>>().template ShiftLeft<half>().template ShiftRight<half>();
1327 }
1328
1330 template <typename S>
1331 ace static Argon<argon::helpers::NextLarger_t<S>> TopLanes(Argon<S> v) {
1332 return v.template As<argon::helpers::NextLarger_t<S>>().template ShiftRight<8 * sizeof(S)>();
1333 }
1334
1336 template <typename W>
1337 ace static Argon<std::make_unsigned_t<W>> LowHalfMask() {
1338 using U = std::make_unsigned_t<W>;
1339 return Argon<U>{static_cast<U>((U{1} << (4 * sizeof(W))) - 1)};
1340 }
1341
1343 template <typename W>
1345 Argon<W> wide) {
1347 return LowHalfMask<W>().Select(wide, dest.template As<W>()).template As<N>();
1348 }
1349
1351 template <typename W>
1353 Argon<W> wide) {
1355 return LowHalfMask<W>().Select(dest.template As<W>(), wide.template ShiftLeft<4 * sizeof(W)>()).template As<N>();
1356 }
1357
1359 template <typename S>
1360 ace static Argon<S> SwapPairs(Argon<S> v) {
1361 if constexpr (sizeof(S) == 1) {
1362 return v.Reverse16bit();
1363 } else if constexpr (sizeof(S) == 2) {
1364 return v.Reverse32bit();
1365 } else {
1366 return v.Reverse64bit();
1367 }
1368 }
1369
1371 ace static typename Argon<ScalarType>::argon_bool_type EvenLanes() {
1372 using U = std::conditional_t<sizeof(ScalarType) == 1, uint8_t,
1373 std::conditional_t<sizeof(ScalarType) == 2, uint16_t, uint32_t>>;
1374 return (Argon<U>::Iota(0) & Argon<U>{U{1}}) == Argon<U>{U{0}};
1375 }
1376
1378 template <DotForm form, typename S>
1379 ace std::array<std::conditional_t<std::is_signed_v<S>, int64_t, uint64_t>, Argon<S>::lanes> DotProducts(
1380 Argon<S> b) const {
1381 using T = std::conditional_t<std::is_signed_v<S>, int64_t, uint64_t>;
1382 constexpr bool exchange = form == DotForm::Exchange || form == DotForm::SubtractExchange;
1383 const auto x = this->to_array();
1384 const auto y = b.to_array();
1385 std::array<T, Argon<S>::lanes> out{};
1386 for (size_t i = 0; i < out.size(); ++i) {
1387 const size_t j = exchange ? (i ^ 1) : i; // the other lane of the pair
1388 T p = static_cast<T>(x[i]) * static_cast<T>(y[j]);
1389 // Subtract negates the odd lanes' products; SubtractExchange the even lanes' (a[2i+1]·b[2i] − a[2i]·b[2i+1]).
1390 const bool negate = form == DotForm::Subtract ? (i & 1) : (form == DotForm::SubtractExchange && !(i & 1));
1391 if (negate)
1392 p = static_cast<T>(T{0} - p);
1393 out[i] = p;
1394 }
1395 return out;
1396 }
1397
1399 template <typename W>
1400 ace static Argon<W> SaturateToNarrow(Argon<W> wide) {
1402 const Argon<W> high{static_cast<W>(std::numeric_limits<N>::max())};
1403 if constexpr (std::is_signed_v<W>) {
1404 return wide.Min(high).Max(Argon<W>{static_cast<W>(std::numeric_limits<N>::min())});
1405 } else {
1406 return wide.Min(high);
1407 }
1408 }
1409#endif
1410
1411 private:
1412 // ── Helpers for the widening loads and narrowing stores ──
1414 template <typename N, typename S>
1415 using ExtendedFrom = std::conditional_t<std::is_signed_v<N>, std::make_signed_t<S>, std::make_unsigned_t<S>>;
1416
1417#ifdef ARGON_PLATFORM_MVE
1418 template <typename N, typename S, typename... P>
1419 ace static Argon<S> WidenMve(const N* ptr, P... p) {
1420 using native = typename Argon<ExtendedFrom<N, S>>::vector_type;
1421 native v;
1422 if constexpr (sizeof(N) == 1) {
1423 v = mve::load_byte<native>(ptr, p...);
1424 } else {
1425 v = mve::load_halfword<native>(ptr, p...);
1426 }
1427 return Argon<ExtendedFrom<N, S>>{v}.template As<S>();
1428 }
1429
1430 template <typename N, typename... P>
1431 [[gnu::always_inline]] inline void NarrowMve(N* ptr, P... p) const {
1432 const auto v = this->template As<ExtendedFrom<N, ScalarType>>().vec();
1433 if constexpr (sizeof(N) == 1) {
1434 mve::store_byte(ptr, v, p...);
1435 } else {
1436 mve::store_halfword(ptr, v, p...);
1437 }
1438 }
1439#endif
1440
1441 template <bool byte_offsets, typename N, typename S, typename... PredicateType>
1442 ace static Argon<S> GatherWiden(const N* base, typename Argon<S>::offset_type offsets, PredicateType... active) {
1443#ifdef ARGON_PLATFORM_MVE
1444 using native = ExtendedFrom<N, S>;
1445 Argon<native> v;
1446 if constexpr (sizeof(N) == 1) {
1447 v = mve::load_byte_gather_offset(base, offsets.vec(), active.native()...); // bytes: index == byte offset
1448 } else if constexpr (byte_offsets) {
1449 v = mve::load_halfword_gather_offset(base, offsets.vec(), active.native()...);
1450 } else {
1451 v = mve::load_halfword_gather_shifted_offset(base, offsets.vec(), active.native()...);
1452 }
1453 return v.template As<S>();
1454#else
1455 const auto off = offsets.to_array();
1456 std::array<S, lanes> out{};
1457 for (size_t i = 0; i < lanes; ++i) {
1458 if ((active.Active(i) && ...)) {
1459 const N* p =
1460 byte_offsets ? reinterpret_cast<const N*>(reinterpret_cast<const char*>(base) + off[i]) : base + off[i];
1461 out[i] = static_cast<S>(*p);
1462 }
1463 }
1464 return Argon<S>::Load(out.data());
1465#endif
1466 }
1467
1468 template <bool byte_offsets, typename N, typename... PredicateType>
1469 [[gnu::always_inline]] inline void ScatterNarrow(N* base,
1470 typename Argon<ScalarType>::offset_type offsets,
1471 PredicateType... active) const {
1472#ifdef ARGON_PLATFORM_MVE
1473 const auto v = this->template As<ExtendedFrom<N, ScalarType>>().vec();
1474 if constexpr (sizeof(N) == 1) {
1475 mve::store_byte_scatter_offset(base, offsets.vec(), v, active.native()...);
1476 } else if constexpr (byte_offsets) {
1477 mve::store_halfword_scatter_offset(base, offsets.vec(), v, active.native()...);
1478 } else {
1479 mve::store_halfword_scatter_shifted_offset(base, offsets.vec(), v, active.native()...);
1480 }
1481#else
1482 const auto off = offsets.to_array();
1483 const auto values = this->to_array();
1484 for (size_t i = 0; i < lanes; ++i) {
1485 if ((active.Active(i) && ...)) {
1486 N* p = byte_offsets ? reinterpret_cast<N*>(reinterpret_cast<char*>(base) + off[i]) : base + off[i];
1487 *p = static_cast<N>(values[i]);
1488 }
1489 }
1490#endif
1491 }
1492
1495 ace static vector_type FromFour(std::array<ScalarType, 4> values) {
1496 if constexpr (lanes <= 4) {
1497 return T::Load(values.data());
1498 } else {
1499 std::array<ScalarType, lanes> padded{};
1500 std::copy(values.begin(), values.end(), padded.begin());
1501 return T::Load(padded.data());
1502 }
1503 }
1504};
1505
1506template <typename... arg_types>
1507 requires(sizeof...(arg_types) > 1)
1508// Argon(arg_types...) -> Argon<arg_types...[0]>;
1509Argon(arg_types...) -> Argon<std::tuple_element_t<0, std::tuple<arg_types...>>>;
1510
1511#ifndef ARGON_PLATFORM_MVE
1512template <typename VectorType>
1514
1515template <typename VectorType>
1517#endif
1518
1519template <typename ScalarType>
1520 requires std::is_scalar_v<ScalarType>
1521Argon(ScalarType) -> Argon<ScalarType>;
1522
1523template <typename V>
1524 requires std::is_scalar_v<V>
1525ace Argon<V> operator+(const V a, const Argon<V> b) {
1526 return b.Add(a);
1527}
1528
1529template <typename V>
1530 requires std::is_scalar_v<V>
1531ace Argon<V> operator-(const V a, const Argon<V> b) {
1532 return Argon<V>{a}.Subtract(b);
1533}
1534
1535template <typename V>
1536 requires std::is_scalar_v<V>
1537ace Argon<V> operator*(const V a, const Argon<V> b) {
1538 return b.Multiply(a);
1539}
1540
1541template <typename V>
1542 requires std::is_scalar_v<V>
1543ace Argon<V> operator/(const V a, const Argon<V> b) {
1544 return Argon<V>{a}.Divide(b);
1545}
1546
1547namespace std {
1548
1549template <typename T>
1550struct tuple_size<Argon<T>> {
1551 static constexpr size_t value = Argon<T>::lanes;
1552};
1553
1554template <size_t Index, typename T>
1555struct tuple_element<Index, Argon<T>> {
1556 static_assert(Index < Argon<T>::lanes);
1558};
1559} // namespace std
1560
1561#undef ace
1562#undef simd
Provides utility templates and concepts for type traits and compile-time iteration.
ace argon_next_larger MultiplyLong(ArgonHalf< ScalarType > b) const
Multiply this and b, widening each product to the next-larger element type (vector × vector).
Definition argon_half.hpp:201
Definition argon_half.hpp:11
Definition argon_full.hpp:44
void StoreNarrow(N *ptr, typename Argon< S >::argon_bool_type active) const
Store the low bits of the active lanes as N; memory for inactive lanes is not written.
Definition argon_full.hpp:705
ace auto ShiftRightRoundNarrow() const
Shift right, round, and narrow.
Definition argon_full.hpp:236
ScalarType Reduce(CommutableOpType op) const
Fold all lanes into a single scalar using a commutative binary operation.
Definition argon_full.hpp:1099
ace Argon< ScalarType > MultiplyAddLong(ArgonHalf< U > b, typename ArgonHalf< U >::lane_type c)
Multiply a half-vector by a lane and add the widened result (vector × lane).
Definition argon_full.hpp:144
ace Argon< ScalarType > MultiplyAddLong(ArgonHalf< U > b, U c)
Multiply a half-vector by a scalar and add the widened result (vector × scalar).
Definition argon_full.hpp:136
this template ShiftRightRound()) ARGON_SHIFT_NARROW(ShiftRightSaturateNarrowBottom
static ace Argon< S > CircularIndices(uint32_t &offset, uint32_t size)
The next lanes indices of a forward walk through a circular buffer of size elements.
Definition argon_full.hpp:579
constexpr Argon(ArgTypes... args)
Construct from one value per lane, each converted to the lane type.
Definition argon_full.hpp:72
void StoreScatterOffsetBytesNarrow(N *base, typename Argon< S >::offset_type offsets, PredicateType... active) const
Scatter the low bits of each lane as N to base plus a byte offset per lane.
Definition argon_full.hpp:747
ace Argon< ScalarType > MultiplySubtractLong(ArgonHalf< U > b, typename ArgonHalf< U >::lane_type c)
Multiply a half-vector by a lane and subtract the widened result (vector × lane).
Definition argon_full.hpp:168
ace Argon< ScalarType > Reverse() const
Reverse the order of all elements in the 128-bit vector.
Definition argon_full.hpp:1041
ace Argon< S > ComplexAddRotate90(Argon< S > b) const
a + i·b for each complex pair: re = a.re − b.im, im = a.im + b.re. MVE / FCMA: vcadd #90.
Definition argon_full.hpp:761
ace Argon< ScalarType > MultiplySubtractLong(ArgonHalf< U > b, ArgonHalf< U > c)
Multiply two narrower half-vectors and subtract the widened result from this vector (vector × vector)...
Definition argon_full.hpp:152
ace Argon< argon::helpers::NextLarger_t< S > > MultiplyLongBottom(Argon< S > b) const
Multiply the even (bottom) lanes, producing full-width products. MVE: vmullb.
Definition argon_full.hpp:328
ace Argon< S > ShiftLeftWithCarry(uint32_t &carry) const
Shift the whole vector, as a 128-bit number, left by n bits: the low n bits of carry shift in at the ...
Definition argon_full.hpp:979
ace auto Narrow() const
Truncate each lane to the next-smaller element type (no saturation).
Definition argon_full.hpp:242
ace Argon< argon::helpers::NextSmaller_t< S > > SaturateNarrowBottom(Argon< argon::helpers::NextSmaller_t< S > > dest) const
Narrow each lane with saturation into the even (bottom) lanes of dest. MVE: vqmovnb.
Definition argon_full.hpp:374
ARGON_SHIFT_NARROW(ShiftRightRoundNarrowBottom, shift_right_narrow_round_bottom, InsertBottom, this->template ShiftRightRound< n >()) ARGON_SHIFT_NARROW(ShiftRightRoundNarrowTop
Shift each lane right by n and narrow it into the even (bottom) lanes of dest. MVE: vshrnb.
ace Argon< S > ComplexMultiply(Argon< S > b) const
The complex product a·b of each pair. Float lanes. MVE / FCMA: two vcmla.
Definition argon_full.hpp:865
constexpr Argon(vector_type vector)
Construct from the underlying intrinsic vector.
Definition argon_full.hpp:63
ace auto AddRoundNarrow(Argon< ScalarType > b) const
Add, round, and narrow: add b, round the result, and truncate to the next-smaller type.
Definition argon_full.hpp:182
ace auto ShiftRightSaturateNarrow() const
Shift right, saturate, and narrow: shift each lane right by n bits with unsigned saturation.
Definition argon_full.hpp:218
ace std::make_unsigned_t< S > ReduceMaxAbs(std::make_unsigned_t< S > init=0) const
The largest magnitude across the lanes, or init if that is larger: a peak meter.
Definition argon_full.hpp:1219
ace Argon(argon::Vector< vector_type > vec)
Construct from an underlying argon::Vector.
Definition argon_full.hpp:75
void StoreScatterOffsetIndexNarrow(N *base, typename Argon< S >::offset_type offsets, PredicateType... active) const
Scatter the low bits of each lane as N to base[offsets[i]]. MVE: vstrb / vstrh scatter.
Definition argon_full.hpp:738
ace Argon< U > ConvertTo() const
Convert each lane to a different element type.
Definition argon_full.hpp:1004
ScalarType ReduceMin() const
Return the minimum value across all lanes.
Definition argon_full.hpp:1182
constexpr Argon()=default
Leave the lanes uninitialised; value-initialisation (Argon<T>{}) zeroes them.
ace Argon< S > ComplexAddRotate270Halve(Argon< S > b) const
(a − i·b) / 2 without overflow. Signed integer lanes. MVE: vhcadd #270.
Definition argon_full.hpp:821
constexpr Argon(argon::ConstLane< LaneIndex, vector_type > lane)
Duplicate lane LaneIndex of lane's vector across every lane.
Definition argon_full.hpp:68
ScalarType ReduceAdd(typename T::argon_bool_type active) const
Sum the active lanes and return the scalar result.
Definition argon_full.hpp:1139
ace Argon< ScalarType > SwapDoublewords() const
Swap the upper and lower 64-bit halves of the vector.
Definition argon_full.hpp:1266
static ace Argon< next_larger > Combine(ArgonHalf< next_larger > low, ArgonHalf< next_larger > high)
Definition argon_full.hpp:105
ace Argon< S > ComplexMultiplyConjugate(Argon< S > b) const
The complex product a·conj(b) of each pair. Float lanes. MVE / FCMA: two vcmla.
Definition argon_full.hpp:873
ace Argon< argon::helpers::NextLarger_t< S > > MultiplyLongTop(Argon< S > b) const
Multiply the odd (top) lanes, producing full-width products. MVE: vmullt.
Definition argon_full.hpp:339
static ace Argon< S > LoadWiden(const N *ptr)
Load lanes elements of the narrower integer type N and extend each to a lane. MVE: vldrb / vldrh.
Definition argon_full.hpp:648
ace auto SaturateNarrow() const
Saturate and narrow each lane to the next-smaller element type.
Definition argon_full.hpp:250
ace Argon< new_scalar_type > As() const
Reinterpret the vector bits as a vector of a different element type.
Definition argon_full.hpp:97
ace ArgonHalf< ScalarType > GetLow() const
Return the lower 64 bits as an ArgonHalf.
Definition argon_full.hpp:268
ace dot_type DotProduct(Argon< S > b, dot_type acc=0) const
Sum acc and the products of every lane of this vector with the matching lane of b.
Definition argon_full.hpp:462
ace std::make_unsigned_t< S > ReduceMinAbs(std::make_unsigned_t< S > init=std::numeric_limits< std::make_unsigned_t< S > >::max()) const
The smallest magnitude across the lanes, or init if that is smaller.
Definition argon_full.hpp:1232
ace Argon< ScalarType > Reverse()
Reverse the order of all elements across the full 128-bit vector.
Definition argon_full.hpp:111
std::conditional_t< std::is_signed_v< ScalarType >, int64_t, uint64_t > dot_long_type
The 64-bit accumulator of DotProductLong and DotProductRoundHigh.
Definition argon_full.hpp:454
ace Argon< ScalarType > MultiplyAddLong(ArgonHalf< U > b, C c)
Multiply two narrower vectors and add the widened result (vector × raw intrinsic).
Definition argon_full.hpp:128
ace dot_long_type DotProductLong(Argon< S > b, dot_long_type acc=0) const
As DotProduct, with products and sum in 64 bits.
Definition argon_full.hpp:504
ace Argon< argon::helpers::NextLarger_t< S > > ShiftLeftLongBottom() const
Widen the even (bottom) lanes and shift them left by n. MVE: vshllb.
Definition argon_full.hpp:306
std::conditional_t< std::is_signed_v< ScalarType >, int32_t, uint32_t > dot_type
The 32-bit accumulator of DotProduct: int32_t for signed lanes, uint32_t for unsigned.
Definition argon_full.hpp:452
ace ArgonHalf< ScalarType > GetHigh() const
Return the upper 64 bits as an ArgonHalf.
Definition argon_full.hpp:266
ace Argon< S > ComplexMultiplyAdd(Argon< S > b, Argon< S > c) const
Accumulate one rotation of the complex product of b and c into this vector, exactly as vcmla.
Definition argon_full.hpp:837
ace Argon< argon::helpers::NextLarger_t< S > > WidenTop() const
Widen the odd (top) lanes to the next larger type. MVE: vmovlt.
Definition argon_full.hpp:294
this template SaturateToNarrow(this->template ShiftRight< n >())) ARGON_SHIFT_NARROW(ShiftRightSaturateNarrowTop
Shift each lane right by n and narrow it with saturation into the top lanes of dest....
ace Argon< S > AddWithCarry(Argon< S > b, uint32_t &carry) const
Add b and carry (0 or 1) to the vector as 128-bit numbers; carry becomes the carry out.
Definition argon_full.hpp:920
ace Argon< S > ComplexAddRotate270(Argon< S > b) const
a − i·b for each complex pair: re = a.re + b.im, im = a.im − b.re. MVE / FCMA: vcadd #270.
Definition argon_full.hpp:785
ace Argon< argon::helpers::NextLarger_t< S > > ShiftLeftLongTop() const
Widen the odd (top) lanes and shift them left by n. MVE: vshllt.
Definition argon_full.hpp:317
ace Argon< argon::helpers::NextSmaller_t< S > > NarrowBottom(Argon< argon::helpers::NextSmaller_t< S > > dest) const
Narrow each lane (keeping its low half) into the even (bottom) lanes of dest.
Definition argon_full.hpp:351
ace Argon< ScalarType > MultiplyDoubleAddSaturateLong(ArgonHalf< NextSmallerType > b, ArgonHalf< NextSmallerType > c)
Multiply, double, add, and saturate long: this + saturate(2 * b * c) widening to ScalarType.
Definition argon_full.hpp:261
static ace Argon< S > LoadGatherOffsetBytesWiden(const N *base, typename Argon< S >::offset_type offsets, PredicateType... active)
Gather N from base plus a byte offset per lane, extending each to a lane.
Definition argon_full.hpp:729
ace Argon< S > MinAbs(Argon< std::make_signed_t< S > > b) const
Each lane's minimum of this (unsigned) vector and the magnitude of b. MVE: vmina.
Definition argon_full.hpp:1257
constexpr Argon(typename T::scalar_type scalar)
Duplicate a scalar across every lane.
Definition argon_full.hpp:65
ace dot_long_type DotProductRoundHigh(Argon< S > b, dot_long_type acc=0) const
As DotProductLong, but with each product divided by 256 and rounded: acc + Σ ⌊(pᵢ + 128) / 256⌋.
Definition argon_full.hpp:538
ace auto ShiftRightNarrow() const
Shift each lane right by n bits and narrow the result to the next-smaller type.
Definition argon_full.hpp:209
ace Argon< argon::helpers::NextSmaller_t< S > > SaturateNarrowTop(Argon< argon::helpers::NextSmaller_t< S > > dest) const
Narrow each lane with saturation into the odd (top) lanes of dest. MVE: vqmovnt.
Definition argon_full.hpp:385
ace Argon< argon::helpers::NextSmaller_t< S > > NarrowTop(Argon< argon::helpers::NextSmaller_t< S > > dest) const
Narrow each lane (keeping its low half) into the odd (top) lanes of dest.
Definition argon_full.hpp:363
ScalarType ReduceAdd() const
Sum all lanes and return the scalar result.
Definition argon_full.hpp:1115
ace Argon(std::array< ScalarType, 4 > value_list)
Construct from four values: lane i takes value_list[i].
Definition argon_full.hpp:79
ace Argon(ArgonHalf< S > low, ArgonHalf< S > high)
Construct by combining a low and high 64-bit half-vector.
Definition argon_full.hpp:85
ace Argon< S > BitReverse(int bits) const
The low bits bits of each lane, reversed; the other bits are zero.
Definition argon_full.hpp:885
ace Argon< ScalarType > MultiplySubtractLong(ArgonHalf< U > b, U c)
Multiply a half-vector by a scalar and subtract the widened result (vector × scalar).
Definition argon_full.hpp:160
static ace Argon< S > CircularIndicesDown(uint32_t &offset, uint32_t size)
The next lanes indices of a backward walk through a circular buffer of size elements.
Definition argon_full.hpp:613
static ace Argon< S > LoadGatherOffsetIndexWiden(const N *base, typename Argon< S >::offset_type offsets, PredicateType... active)
Gather base[offsets[i]] of the narrower type N, extending each to a lane. MVE: vldrb / vldrh gather.
Definition argon_full.hpp:720
ScalarType ReduceMax() const
Return the maximum value across all lanes.
Definition argon_full.hpp:1149
void StoreNarrow(N *ptr) const
Store the low bits of each lane as the narrower integer type N. MVE: vstrb / vstrh.
Definition argon_full.hpp:686
ace auto SubtractRoundNarrow(Argon< ScalarType > b) const
Subtract, round, and narrow: subtract b, round the result, and truncate to the next-smaller type.
Definition argon_full.hpp:198
ace Argon< S > SubtractWithBorrow(Argon< S > b, uint32_t &borrow) const
Subtract b and borrow (0 or 1) from the vector as 128-bit numbers; borrow becomes the borrow out.
Definition argon_full.hpp:949
ace Argon< argon::helpers::NextLarger_t< S > > WidenBottom() const
Widen the even (bottom) lanes to the next larger type. MVE: vmovlb.
Definition argon_full.hpp:282
ace Argon< S > ComplexAddRotate90Halve(Argon< S > b) const
(a + i·b) / 2 without overflow. Signed integer lanes. MVE: vhcadd #90.
Definition argon_full.hpp:809
ace Argon< ScalarType > MultiplyAddLong(ArgonHalf< U > b, ArgonHalf< U > c)
Multiply two narrower half-vectors and add the widened result to this vector (vector × vector).
Definition argon_full.hpp:121
ace auto AddNarrow(Argon< ScalarType > b) const
Add and narrow: add b to this vector and truncate each lane to the next-smaller type.
Definition argon_full.hpp:174
ace auto SubtractNarrow(Argon< ScalarType > b) const
Subtract and narrow: subtract b and truncate each lane to the next-smaller type.
Definition argon_full.hpp:190
ace Argon< U > ConvertTo() const
Convert each lane to a different type using a fixed-point fractional bit count.
Definition argon_full.hpp:1021
ace std::pair< dot_type, dot_type > ComplexDotProduct(Argon< S > b) const
The complex dot product Σ a·b of vectors of interleaved (real, imaginary) pairs, as {real,...
Definition argon_full.hpp:563
static ace Argon< S > LoadWiden(const N *ptr, typename Argon< S >::argon_bool_type active)
Load and extend the active lanes; inactive lanes are zero and their memory is not read.
Definition argon_full.hpp:670
ace Argon< S > MaxAbs(Argon< std::make_signed_t< S > > b) const
Each lane's maximum of this (unsigned) vector and the magnitude of b: running peak tracking,...
Definition argon_full.hpp:1246
ace auto ShiftRightRoundSaturateNarrow() const
Shift right, round, saturate, and narrow.
Definition argon_full.hpp:227
Represents a single lane of a SIMD vector with the lane index known at compile time.
Definition lane.hpp:35
Represents a single lane of a SIMD vector with a runtime-determined index.
Definition lane.hpp:107
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
Represents a SIMD vector with various operations.
Definition vector.hpp:53
simd::Vec128_t< ScalarType > vector_type
Definition vector.hpp:78
ace argon_type MultiplySubtract(argon_type b, argon_type c) const
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
constexpr VectorType vec() const
Get the underlying SIMD vector.
Definition vector.hpp:312
ace argon_type Multiply(argon_type b) const
Multiply two vectors.
Definition vector.hpp:439
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)
Definition vector.hpp:1095
ace argon_type MultiplyAdd(argon_type b, argon_type c) const
Definition vector.hpp:477
ace argon_type Max(argon_type b) const
Definition vector.hpp:821
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 ShiftRight() const
Definition vector.hpp:1048
ace argon_type AddHalve(argon_type b) const
Definition vector.hpp:397
helpers::ArgonFor_t< simd::make_unsigned_t< Bool_t< simd::Vec128_t< ScalarType > > > > offset_type
Definition vector.hpp:86
ace argon_type Divide(argon_type b) const
Divide two vectors.
Definition vector.hpp:782
static ace int size()
Get the number of elements.
Definition vector.hpp:1767
ace argon_type ShiftLeft() const
Definition vector.hpp:1009
simd::Scalar_t< VectorType > scalar_type
The scalar type of the SIMD vector.
Definition vector.hpp:58
ace std::array< scalar_type, lanes > to_array() const
Definition vector.hpp:319
ace argon_type Absolute() const
Definition vector.hpp:669
static constexpr size_t lanes
Definition vector.hpp:90
ace argon_type Add(argon_type b) const
Add two vectors.
Definition vector.hpp:387
ace argon_type Min(argon_type b) const
Definition vector.hpp:842
ace argon_type SubtractHalve(argon_type b) const
Definition vector.hpp:419
ace argon_type Subtract(argon_type b) const
Subtract two vectors.
Definition vector.hpp:409
Predicate< simd::Vec128_t< ScalarType > > argon_bool_type
Definition vector.hpp:85
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
Whether lanes of integer type W can be loaded from (and stored as) the narrower integer type N,...
Definition argon_full.hpp:34
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
NextSmaller< T >::type NextSmaller_t
Helper alias to get the next smaller type for a given type.
Definition helpers.hpp:97
constexpr bool has_smaller_v
Helper template to determine if a type has a smaller corresponding type.
Definition helpers.hpp:18
NextLarger< T >::type NextLarger_t
Helper alias to get the next larger type for a given type.
Definition helpers.hpp:75
A 128-bit SIMD vector wrapping a scalar type, providing arithmetic, logical, and data-movement operat...
Definition argon.hpp:30
DotForm
The forms of Argon::DotProduct and friends. See Argon::DotProduct.
Definition argon_full.hpp:39
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
Lane deconstruction feature.
Definition argon_full.hpp:1547