Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
lanes.hpp
Go to the documentation of this file.
1#pragma once
2
26
27#include <cstddef>
28#include <type_traits>
29
30namespace pulp::simd {
31
32#if (defined(__GNUC__) || defined(__clang__)) && !defined(PULP_SIMD_DISABLE_VECTOR_LANES)
33#define PULP_SIMD_HAS_VECTOR_LANES 1
34inline constexpr bool kHasVectorLanes = true;
35
36namespace detail {
37template <typename T, std::size_t N> struct vector_lanes {
38 static_assert(std::is_arithmetic_v<T> && N > 1 && (N & (N - 1)) == 0,
39 "Lanes needs an arithmetic element type and a power-of-two width above 1");
40 typedef T type __attribute__((vector_size(N * sizeof(T))));
41};
42} // namespace detail
43
45template <typename T, std::size_t N> using Lanes = typename detail::vector_lanes<T, N>::type;
46#else
47#define PULP_SIMD_HAS_VECTOR_LANES 0
48inline constexpr bool kHasVectorLanes = false;
49#endif
50
52template <typename V>
53inline constexpr std::size_t lane_count = [] {
54 if constexpr (std::is_arithmetic_v<V>)
55 return std::size_t{1};
56 else
57 return sizeof(V) / sizeof(V{}[0]);
58}();
59
61template <typename V> inline auto get_lane(const V& v, std::size_t i) noexcept {
62 if constexpr (std::is_arithmetic_v<V>) {
63 (void)i;
64 return v;
65 } else {
66 return v[i];
67 }
68}
69
71template <typename V, typename T> inline void set_lane(V& v, std::size_t i, T x) noexcept {
72 if constexpr (std::is_arithmetic_v<V>) {
73 (void)i;
74 v = static_cast<V>(x);
75 } else {
76 v[i] = x;
77 }
78}
79
80} // namespace pulp::simd
Definition scalar_kernels.hpp:20
Definition lanes.hpp:30
void set_lane(V &v, std::size_t i, T x) noexcept
Set lane i of v to x; a scalar is its own lane 0.
Definition lanes.hpp:71
constexpr bool kHasVectorLanes
Definition lanes.hpp:48
constexpr std::size_t lane_count
Number of lanes in V: 1 for a scalar, N for Lanes<T, N>.
Definition lanes.hpp:53
auto get_lane(const V &v, std::size_t i) noexcept
Lane i of v; a scalar is its own lane 0.
Definition lanes.hpp:61