Loada.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SIMD_LOADA_H_
36 #define _BLAZE_MATH_SIMD_LOADA_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Inline.h>
47 #include <blaze/util/Assert.h>
48 #include <blaze/util/Complex.h>
49 #include <blaze/util/EnableIf.h>
50 #include <blaze/util/mpl/And.h>
51 #include <blaze/util/mpl/If.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // 8-BIT INTEGRAL SIMD TYPES
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
77 template< typename T > // Type of the integral value
78 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
79  , If_< IsSigned<T>, SIMDint8, SIMDuint8 > >
80  loada( const T* address ) noexcept
81 {
82  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
83 
84 #if BLAZE_AVX2_MODE
85  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
86 #elif BLAZE_SSE2_MODE
87  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
88 #else
89  return *address;
90 #endif
91 }
92 //*************************************************************************************************
93 
94 
95 //*************************************************************************************************
106 template< typename T > // Type of the integral value
107 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
108  , If_< IsSigned<T>, SIMDcint8, SIMDcuint8 > >
109  loada( const complex<T>* address ) noexcept
110 {
111  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
112  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
113 
114 #if BLAZE_AVX2_MODE
115  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
116 #elif BLAZE_SSE2_MODE
117  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
118 #else
119  return *address;
120 #endif
121 }
122 //*************************************************************************************************
123 
124 
125 
126 
127 //=================================================================================================
128 //
129 // 16-BIT INTEGRAL SIMD TYPES
130 //
131 //=================================================================================================
132 
133 //*************************************************************************************************
144 template< typename T > // Type of the integral value
145 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
146  , If_< IsSigned<T>, SIMDint16, SIMDuint16 > >
147  loada( const T* address ) noexcept
148 {
149  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
150 
151 #if BLAZE_AVX2_MODE
152  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
153 #elif BLAZE_SSE2_MODE
154  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
155 #else
156  return *address;
157 #endif
158 }
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
173 template< typename T > // Type of the integral value
174 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
175  , If_< IsSigned<T>, SIMDcint16, SIMDcuint16 > >
176  loada( const complex<T>* address ) noexcept
177 {
178  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
179  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
180 
181 #if BLAZE_AVX2_MODE
182  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
183 #elif BLAZE_SSE2_MODE
184  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
185 #else
186  return *address;
187 #endif
188 }
189 //*************************************************************************************************
190 
191 
192 
193 
194 //=================================================================================================
195 //
196 // 32-BIT INTEGRAL SIMD TYPES
197 //
198 //=================================================================================================
199 
200 //*************************************************************************************************
211 template< typename T > // Type of the integral value
212 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
213  , If_< IsSigned<T>, SIMDint32, SIMDuint32 > >
214  loada( const T* address ) noexcept
215 {
216  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
217 
218 #if BLAZE_MIC_MODE
219  return _mm512_load_epi32( address );
220 #elif BLAZE_AVX2_MODE
221  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
222 #elif BLAZE_SSE2_MODE
223  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
224 #else
225  return *address;
226 #endif
227 }
228 //*************************************************************************************************
229 
230 
231 //*************************************************************************************************
242 template< typename T > // Type of the integral value
243 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
244  , If_< IsSigned<T>, SIMDcint32, SIMDcuint32 > >
245  loada( const complex<T>* address ) noexcept
246 {
247  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
248  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
249 
250 #if BLAZE_MIC_MODE
251  return _mm512_load_epi32( address );
252 #elif BLAZE_AVX2_MODE
253  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
254 #elif BLAZE_SSE2_MODE
255  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
256 #else
257  return *address;
258 #endif
259 }
260 //*************************************************************************************************
261 
262 
263 
264 
265 //=================================================================================================
266 //
267 // 64-BIT INTEGRAL SIMD TYPES
268 //
269 //=================================================================================================
270 
271 //*************************************************************************************************
282 template< typename T > // Type of the integral value
283 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
284  , If_< IsSigned<T>, SIMDint64, SIMDuint64 > >
285  loada( const T* address ) noexcept
286 {
287  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
288 
289 #if BLAZE_MIC_MODE
290  return _mm512_load_epi64( address );
291 #elif BLAZE_AVX2_MODE
292  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
293 #elif BLAZE_SSE2_MODE
294  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
295 #else
296  return *address;
297 #endif
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
313 template< typename T > // Type of the integral value
314 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
315  , If_< IsSigned<T>, SIMDcint64, SIMDcuint64 > >
316  loada( const complex<T>* address ) noexcept
317 {
318  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
319  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
320 
321 #if BLAZE_MIC_MODE
322  return _mm512_load_epi64( address );
323 #elif BLAZE_AVX2_MODE
324  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
325 #elif BLAZE_SSE2_MODE
326  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
327 #else
328  return If_< IsSigned<T>, SIMDcint64, SIMDcuint64 >( *address );
329 #endif
330 }
331 //*************************************************************************************************
332 
333 
334 
335 
336 //=================================================================================================
337 //
338 // 32-BIT FLOATING POINT SIMD TYPES
339 //
340 //=================================================================================================
341 
342 //*************************************************************************************************
353 BLAZE_ALWAYS_INLINE const SIMDfloat loada( const float* address ) noexcept
354 {
355  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
356 
357 #if BLAZE_MIC_MODE
358  return _mm512_load_ps( address );
359 #elif BLAZE_AVX_MODE
360  return _mm256_load_ps( address );
361 #elif BLAZE_SSE_MODE
362  return _mm_load_ps( address );
363 #else
364  return *address;
365 #endif
366 }
367 //*************************************************************************************************
368 
369 
370 //*************************************************************************************************
381 BLAZE_ALWAYS_INLINE const SIMDcfloat loada( const complex<float>* address ) noexcept
382 {
383  BLAZE_STATIC_ASSERT ( sizeof( complex<float> ) == 2UL*sizeof( float ) );
384  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
385 
386 #if BLAZE_MIC_MODE
387  return _mm512_load_ps( reinterpret_cast<const float*>( address ) );
388 #elif BLAZE_AVX_MODE
389  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
390 #elif BLAZE_SSE_MODE
391  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
392 #else
393  return *address;
394 #endif
395 }
396 //*************************************************************************************************
397 
398 
399 
400 
401 //=================================================================================================
402 //
403 // 64-BIT FLOATING POINT SIMD TYPES
404 //
405 //=================================================================================================
406 
407 //*************************************************************************************************
418 BLAZE_ALWAYS_INLINE const SIMDdouble loada( const double* address ) noexcept
419 {
420  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
421 
422 #if BLAZE_MIC_MODE
423  return _mm512_load_pd( address );
424 #elif BLAZE_AVX_MODE
425  return _mm256_load_pd( address );
426 #elif BLAZE_SSE2_MODE
427  return _mm_load_pd( address );
428 #else
429  return *address;
430 #endif
431 }
432 //*************************************************************************************************
433 
434 
435 //*************************************************************************************************
446 BLAZE_ALWAYS_INLINE const SIMDcdouble loada( const complex<double>* address ) noexcept
447 {
448  BLAZE_STATIC_ASSERT ( sizeof( complex<double> ) == 2UL*sizeof( double ) );
449  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
450 
451 #if BLAZE_MIC_MODE
452  return _mm512_load_pd( reinterpret_cast<const double*>( address ) );
453 #elif BLAZE_AVX_MODE
454  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
455 #elif BLAZE_SSE2_MODE
456  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
457 #else
458  return *address;
459 #endif
460 }
461 //*************************************************************************************************
462 
463 } // namespace blaze
464 
465 #endif
SIMD type for 16-bit signed integral data values.
SIMD type for 32-bit unsigned integral complex values.
SIMD type for 16-bit unsigned integral complex values.
SIMD type for 32-bit signed integral complex values.
Header file for the IsIntegral type trait.
Header file for the And class template.
SIMD type for 32-bit unsigned integral data values.
SIMD type for 64-bit double precision floating point data values.
SIMD type for 64-bit unsigned integral complex values.
SIMD type for 16-bit signed integral complex values.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for the If class template.
Compile time assertion.
SIMD type for 16-bit unsigned integral data values.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:80
SIMD type for 32-bit signed integral data values.
Header file for the EnableIf class template.
Header file for the basic SIMD types.
Header file for run time assertion macros.
SIMD type for 8-bit signed integral complex values.
Header file for the HasSize type trait.
SIMD type for 32-bit single precision complex values.
SIMD type for 64-bit signed integral complex values.
Header file for the IsSigned type trait.
SIMD type for 32-bit single precision floating point data values.
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
SIMD type for 64-bit unsigned integral data values.
SIMD type for 64-bit integral data values.
SIMD type for 8-bit unsigned integral complex values.
Header file for the alignment check function.
SIMD type for 64-bit double precision complex values.
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:112
System settings for the inline keywords.
#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