Expression Templates Library (ETL)
vectorization.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
15 #pragma once
16 
17 #ifdef __ARM_ARCH
18 #include <arm_neon.h>
19 #else
20 #include <immintrin.h>
21 #endif
22 
23 
24 #include "etl/inline.hpp"
25 
26 namespace etl {
27 
28 constexpr ETL_STRONG_INLINE(size_t) prev_multiple(size_t N, size_t size) {
29  return N & (size_t(-size));
30 }
31 
38 template <vector_mode_t V, typename T, typename VT>
39 struct simd_pack {
40  using value_type = T;
41  using intrinsic_type = VT;
42 
43  static constexpr vector_mode_t vector_mode = V;
44 
46 
51  simd_pack(intrinsic_type value) : value(value) {
52  // Nothing else to init
53  }
54 
60  ETL_STRONG_INLINE(value_type) operator[](size_t i) const noexcept {
61  return reinterpret_cast<const value_type*>(&value)[i];
62  }
63 };
64 
65 } // end of namespace etl
66 
67 #if defined __GNUC__ && __GNUC__>=6
68 #pragma GCC diagnostic ignored "-Wignored-attributes"
69 #endif
70 
71 //Include al the vector implementation
75 #include "etl/no_vectorization.hpp"
76 
77 #if defined __GNUC__ && __GNUC__>=6
78 #pragma GCC diagnostic pop
79 #endif
80 
81 namespace etl {
82 
87 template <vector_mode_t V>
93  template <typename T>
95 };
96 
101 template <vector_mode_t V>
103  using type = no_vec;
104 };
105 
106 #ifdef __AVX512F__
107 
111 template <>
117  template <typename T>
118  using type = avx512_intrinsic_traits<T>;
119 };
120 
124 template <>
125 struct get_vector_impl<vector_mode_t::AVX512> {
126  using type = avx512_vec;
127 };
128 
129 #endif
130 
131 #ifdef __AVX__
132 
136 template <>
137 struct get_intrinsic_traits<vector_mode_t::AVX> {
142  template <typename T>
143  using type = avx_intrinsic_traits<T>;
144 };
145 
149 template <>
150 struct get_vector_impl<vector_mode_t::AVX> {
151  using type = avx_vec;
152 };
153 
154 #endif
155 
156 #ifdef __SSE3__
157 
161 template <>
162 struct get_intrinsic_traits<vector_mode_t::SSE3> {
167  template <typename T>
168  using type = sse_intrinsic_traits<T>;
169 };
170 
174 template <>
175 struct get_vector_impl<vector_mode_t::SSE3> {
176  using type = sse_vec;
177 };
178 
179 #endif
180 
181 #ifdef ETL_VECTORIZE_EXPR
182 
183 #ifdef __AVX512F__
184 
188 using default_vec = avx512_vec;
189 
193 template <typename T>
194 using default_intrinsic_traits = avx512_intrinsic_traits<T>;
195 
196 #elif defined(__AVX__)
197 
201 using default_vec = avx_vec;
202 
206 template <typename T>
207 using default_intrinsic_traits = avx_intrinsic_traits<T>;
208 
209 #elif defined(__SSE3__)
210 
214 using default_vec = sse_vec;
215 
219 template <typename T>
220 using default_intrinsic_traits = sse_intrinsic_traits<T>;
221 
222 #else
223 
227 using default_vec = no_vec;
228 
232 template <typename T>
234 
235 #endif //defined(__SSE__)
236 
237 #else //ETL_VECTORIZE_EXPR
238 
243 
247 template <typename T>
249 
250 #endif //ETL_VECTORIZE_EXPR
251 
255 template <typename T>
257 
258 } //end of namespace etl
Traits to get the intrinsic traits for a vector mode.
Definition: vectorization.hpp:88
Traits to get the vector implementation for a vector mode.
Definition: vectorization.hpp:102
intrinsic_type value
The vector of value.
Definition: vectorization.hpp:45
Contains AVX-512 vectorized functions for the vectorized assignment of expressions.
vector_mode_t
Vectorization mode.
Definition: config.hpp:184
static constexpr vector_mode_t vector_mode
The vector implementation mode.
Definition: vectorization.hpp:43
Define traits to get vectorization information for types when no vector mode is available.
Definition: no_vectorization.hpp:16
SSE3 is the max vectorization available.
VT intrinsic_type
The used intrinsic type.
Definition: vectorization.hpp:41
Contains SSE vectorized functions for the vectorized assignment of expressions.
Root namespace for the ETL library.
Definition: adapter.hpp:15
typename default_intrinsic_traits< T >::intrinsic_type default_intrinsic_type
Helper to get the intrinsic corresponding type of a vectorizable type.
Definition: vectorization.hpp:256
T intrinsic_type
The intrinsic type.
Definition: no_vectorization.hpp:21
ETL_STRONG_INLINE(value_type) operator[](size_t i) const noexcept
Extract an element of the vector value.
Definition: vectorization.hpp:60
simd_pack(intrinsic_type value)
Construct a new simd_pack around the given vector.
Definition: vectorization.hpp:51
AVX is the max vectorization available.
const_return_type operator[](size_t j) const
Returns the element at the given index.
Definition: dyn_matrix_view.hpp:71
Inlining macros.
Contains AVX vectorized functions for the vectorized assignment of expressions.
T value_type
The real value type.
Definition: vectorization.hpp:40
AVX-512F is the max vectorization available.
SIMD pack of some type, using a vector implementation type.
Definition: vectorization.hpp:39
Vectorization support when no vectorization is enabled.
Definition: no_vectorization.hpp:29