Argon 0.1.0
Loading...
Searching...
No Matches
duplicate_lane.hpp
1#pragma once
2#include <utility>
3#include "argon/features.h"
4#include "arm_simd.hpp"
5#include "concepts.hpp"
6#include "scalar.hpp"
7#include "vec64.hpp"
8
9#ifdef __ARM_FEATURE_MVE
10#define simd mve
11#else
12#define simd neon
13#endif
14
15#ifdef ARGON_PLATFORM_SIMDE
16#define nce [[gnu::always_inline]] inline
17#elifdef __clang__
18#define nce [[gnu::always_inline]] constexpr
19#else
20#define nce [[gnu::always_inline]] inline
21#endif
22
23namespace simd {
24#ifndef ARGON_PLATFORM_MVE
25namespace detail {
27template <typename VectorType, int Lane>
28nce VectorType duplicate_half_lane(Vec64_t<Scalar_t<VectorType>> vec) {
29 if constexpr (is_quadword_v<VectorType>) {
30 return simd::duplicate_lane_quad<Lane>(vec);
31 } else if constexpr (sizeof(VectorType) == sizeof(Scalar_t<VectorType>)) {
32 return vec; // a one-lane vector is its own broadcast
33 } else {
34 return simd::duplicate_lane<Lane>(vec);
35 }
36}
37} // namespace detail
38
42template <typename VectorType>
43nce VectorType duplicate_lane(Vec64_t<Scalar_t<VectorType>> vec, const int i) {
44 constexpr int half_lanes = sizeof(Vec64_t<Scalar_t<VectorType>>) / sizeof(Scalar_t<VectorType>);
45 if constexpr (half_lanes == 1) {
46 return detail::duplicate_half_lane<VectorType, 0>(vec);
47 } else if constexpr (half_lanes == 2) {
48 switch (i) {
49 case 0:
50 return detail::duplicate_half_lane<VectorType, 0>(vec);
51 case 1:
52 return detail::duplicate_half_lane<VectorType, 1>(vec);
53 default:
54 std::unreachable();
55 }
56 } else if constexpr (half_lanes == 4) {
57 switch (i) {
58 case 0:
59 return detail::duplicate_half_lane<VectorType, 0>(vec);
60 case 1:
61 return detail::duplicate_half_lane<VectorType, 1>(vec);
62 case 2:
63 return detail::duplicate_half_lane<VectorType, 2>(vec);
64 case 3:
65 return detail::duplicate_half_lane<VectorType, 3>(vec);
66 default:
67 std::unreachable();
68 }
69 } else {
70 static_assert(half_lanes == 8);
71 switch (i) {
72 case 0:
73 return detail::duplicate_half_lane<VectorType, 0>(vec);
74 case 1:
75 return detail::duplicate_half_lane<VectorType, 1>(vec);
76 case 2:
77 return detail::duplicate_half_lane<VectorType, 2>(vec);
78 case 3:
79 return detail::duplicate_half_lane<VectorType, 3>(vec);
80 case 4:
81 return detail::duplicate_half_lane<VectorType, 4>(vec);
82 case 5:
83 return detail::duplicate_half_lane<VectorType, 5>(vec);
84 case 6:
85 return detail::duplicate_half_lane<VectorType, 6>(vec);
86 case 7:
87 return detail::duplicate_half_lane<VectorType, 7>(vec);
88 default:
89 std::unreachable();
90 }
91 }
92}
93#endif
94} // namespace simd
95#undef simd
96#undef nce
Header file for SIMD features and platform detection.