All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Load.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_INTRINSICS_LOAD_H_
36 #define _BLAZE_MATH_INTRINSICS_LOAD_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
46 #include <blaze/util/Assert.h>
47 #include <blaze/util/Complex.h>
49 #include <blaze/util/EnableIf.h>
51 
52 
53 namespace blaze {
54 
55 //=================================================================================================
56 //
57 // CLASS DEFINITION
58 //
59 //=================================================================================================
60 
61 //*************************************************************************************************
71 template< typename T // Type of the integral
72  , size_t N > // Size of the integral
73 struct Load;
75 //*************************************************************************************************
76 
77 
78 
79 
80 //=================================================================================================
81 //
82 // SPECIALIZATIONS OF THE LOAD CLASS TEMPLATE
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
91 template< typename T > // Type of the integral
92 struct Load<T,2UL>
93 {
94  public:
95  //**Type definitions****************************************************************************
96  typedef sse_int16_t Type;
97  //**********************************************************************************************
98 
99  //**Set function********************************************************************************
100  static inline Type load( const T* address )
101  {
102  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
103 
104 #if BLAZE_AVX2_MODE
105  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
106 #elif BLAZE_SSE2_MODE
107  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
108 #else
109  return *address;
110 #endif
111  }
112  //**********************************************************************************************
113 
114  private:
115  //**Compile time checks*************************************************************************
117  //**********************************************************************************************
118 };
120 //*************************************************************************************************
121 
122 
123 //*************************************************************************************************
128 template< typename T > // Type of the integral
129 struct Load<T,4UL>
130 {
131  public:
132  //**Type definitions****************************************************************************
133  typedef sse_int32_t Type;
134  //**********************************************************************************************
135 
136  //**Set function********************************************************************************
137  static inline Type load( const T* address )
138  {
139  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
140 
141 #if BLAZE_MIC_MODE
142  return _mm512_load_epi32( address );
143 #elif BLAZE_AVX2_MODE
144  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
145 #elif BLAZE_SSE2_MODE
146  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
147 #else
148  return *address;
149 #endif
150  }
151  //**********************************************************************************************
152 
153  private:
154  //**Compile time checks*************************************************************************
156  //**********************************************************************************************
157 };
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
167 template< typename T > // Type of the integral
168 struct Load<T,8UL>
169 {
170  public:
171  //**Type definitions****************************************************************************
172  typedef sse_int64_t Type;
173  //**********************************************************************************************
174 
175  //**Set function********************************************************************************
176  static inline Type load( const T* address )
177  {
178  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
179 
180 #if BLAZE_MIC_MODE
181  return _mm512_load_epi64( address );
182 #elif BLAZE_AVX2_MODE
183  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
184 #elif BLAZE_SSE2_MODE
185  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
186 #else
187  return *address;
188 #endif
189  }
190  //**********************************************************************************************
191 
192  private:
193  //**Compile time checks*************************************************************************
195  //**********************************************************************************************
196 };
198 //*************************************************************************************************
199 
200 
201 
202 
203 //=================================================================================================
204 //
205 // INTRINSIC LOAD FUNCTIONS
206 //
207 //=================================================================================================
208 
209 //*************************************************************************************************
220 template< typename T > // Type of the integral value
221 inline typename EnableIf< IsIntegral<T>, Load<T,sizeof(T)> >::Type::Type
222  load( const T* address )
223 {
224  return Load<T,sizeof(T)>::load( address );
225 }
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
240 inline sse_float_t load( const float* address )
241 {
242  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
243 
244 #if BLAZE_MIC_MODE
245  return _mm512_load_ps( address );
246 #elif BLAZE_AVX_MODE
247  return _mm256_load_ps( address );
248 #elif BLAZE_SSE_MODE
249  return _mm_load_ps( address );
250 #else
251  return *address;
252 #endif
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
268 inline sse_double_t load( const double* address )
269 {
270  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
271 
272 #if BLAZE_MIC_MODE
273  return _mm512_load_pd( address );
274 #elif BLAZE_AVX_MODE
275  return _mm256_load_pd( address );
276 #elif BLAZE_SSE2_MODE
277  return _mm_load_pd( address );
278 #else
279  return *address;
280 #endif
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
296 inline sse_cfloat_t load( const complex<float>* address )
297 {
298  BLAZE_STATIC_ASSERT ( sizeof( complex<float> ) == 2UL*sizeof( float ) );
299  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
300 
301 #if BLAZE_MIC_MODE
302  return _mm512_load_ps( reinterpret_cast<const float*>( address ) );
303 #elif BLAZE_AVX_MODE
304  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
305 #elif BLAZE_SSE_MODE
306  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
307 #else
308  return *address;
309 #endif
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
325 inline sse_cdouble_t load( const complex<double>* address )
326 {
327  BLAZE_STATIC_ASSERT ( sizeof( complex<double> ) == 2UL*sizeof( double ) );
328  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
329 
330 #if BLAZE_MIC_MODE
331  return _mm512_load_pd( reinterpret_cast<const double*>( address ) );
332 #elif BLAZE_AVX_MODE
333  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
334 #elif BLAZE_SSE2_MODE
335  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
336 #else
337  return *address;
338 #endif
339 }
340 //*************************************************************************************************
341 
342 } // namespace blaze
343 
344 #endif
Intrinsic type for 32-bit single precision complex values.
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
#define BLAZE_CONSTRAINT_MUST_BE_INTEGRAL_TYPE(T)
Constraint on the data type.In case the given data type T is not an integral data type...
Definition: Integral.h:78
Compile time assertion.
Intrinsic type for 32-bit single precision floating point data values.
Intrinsic type for 64-bit double precision complex values.
Constraint on the data type.
Header file for the EnableIf class template.
Intrinsic type for 64-bit double precision floating point data values.
Header file for the basic intrinsic types.
Header file for run time assertion macros.
bool checkAlignment(const T *address)
Checks the alignment of the given.
Definition: AlignmentCheck.h:68
Header file for the alignment check function.
System settings for the SSE mode.
Header file for the complex data type.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101