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_AVX512BW_MODE
85  return _mm512_load_si512( reinterpret_cast<const __m512i*>( address ) );
86 #elif BLAZE_AVX2_MODE
87  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
88 #elif BLAZE_SSE2_MODE
89  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
90 #else
91  return *address;
92 #endif
93 }
94 //*************************************************************************************************
95 
96 
97 //*************************************************************************************************
108 template< typename T > // Type of the integral value
109 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
110  , If_< IsSigned<T>, SIMDcint8, SIMDcuint8 > >
111  loada( const complex<T>* address ) noexcept
112 {
113  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
114  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
115 
116 #if BLAZE_AVX512BW_MODE
117  return _mm512_load_si512( reinterpret_cast<const __m512i*>( address ) );
118 #elif BLAZE_AVX2_MODE
119  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
120 #elif BLAZE_SSE2_MODE
121  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
122 #else
123  return If_< IsSigned<T>, SIMDcint8, SIMDcuint8 >( *address );
124 #endif
125 }
126 //*************************************************************************************************
127 
128 
129 
130 
131 //=================================================================================================
132 //
133 // 16-BIT INTEGRAL SIMD TYPES
134 //
135 //=================================================================================================
136 
137 //*************************************************************************************************
148 template< typename T > // Type of the integral value
149 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
150  , If_< IsSigned<T>, SIMDint16, SIMDuint16 > >
151  loada( const T* address ) noexcept
152 {
153  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
154 
155 #if BLAZE_AVX512BW_MODE
156  return _mm512_load_si512( reinterpret_cast<const __m512i*>( address ) );
157 #elif BLAZE_AVX2_MODE
158  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
159 #elif BLAZE_SSE2_MODE
160  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
161 #else
162  return *address;
163 #endif
164 }
165 //*************************************************************************************************
166 
167 
168 //*************************************************************************************************
179 template< typename T > // Type of the integral value
180 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
181  , If_< IsSigned<T>, SIMDcint16, SIMDcuint16 > >
182  loada( const complex<T>* address ) noexcept
183 {
184  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
185  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
186 
187 #if BLAZE_AVX512BW_MODE
188  return _mm512_load_si512( reinterpret_cast<const __m512i*>( address ) );
189 #elif BLAZE_AVX2_MODE
190  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
191 #elif BLAZE_SSE2_MODE
192  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
193 #else
194  return If_< IsSigned<T>, SIMDcint16, SIMDcuint16 >( *address );
195 #endif
196 }
197 //*************************************************************************************************
198 
199 
200 
201 
202 //=================================================================================================
203 //
204 // 32-BIT INTEGRAL SIMD TYPES
205 //
206 //=================================================================================================
207 
208 //*************************************************************************************************
219 template< typename T > // Type of the integral value
220 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
221  , If_< IsSigned<T>, SIMDint32, SIMDuint32 > >
222  loada( const T* address ) noexcept
223 {
224  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
225 
226 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
227  return _mm512_load_epi32( address );
228 #elif BLAZE_AVX2_MODE
229  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
230 #elif BLAZE_SSE2_MODE
231  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
232 #else
233  return *address;
234 #endif
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
250 template< typename T > // Type of the integral value
251 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
252  , If_< IsSigned<T>, SIMDcint32, SIMDcuint32 > >
253  loada( const complex<T>* address ) noexcept
254 {
255  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
256  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
257 
258 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
259  return _mm512_load_epi32( address );
260 #elif BLAZE_AVX2_MODE
261  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
262 #elif BLAZE_SSE2_MODE
263  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
264 #else
265  return If_< IsSigned<T>, SIMDcint32, SIMDcuint32 >( *address );
266 #endif
267 }
268 //*************************************************************************************************
269 
270 
271 
272 
273 //=================================================================================================
274 //
275 // 64-BIT INTEGRAL SIMD TYPES
276 //
277 //=================================================================================================
278 
279 //*************************************************************************************************
290 template< typename T > // Type of the integral value
291 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
292  , If_< IsSigned<T>, SIMDint64, SIMDuint64 > >
293  loada( const T* address ) noexcept
294 {
295  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
296 
297 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
298  return _mm512_load_epi64( address );
299 #elif BLAZE_AVX2_MODE
300  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
301 #elif BLAZE_SSE2_MODE
302  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
303 #else
304  return *address;
305 #endif
306 }
307 //*************************************************************************************************
308 
309 
310 //*************************************************************************************************
321 template< typename T > // Type of the integral value
322 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
323  , If_< IsSigned<T>, SIMDcint64, SIMDcuint64 > >
324  loada( const complex<T>* address ) noexcept
325 {
326  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
327  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
328 
329 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
330  return _mm512_load_epi64( address );
331 #elif BLAZE_AVX2_MODE
332  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
333 #elif BLAZE_SSE2_MODE
334  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
335 #else
336  return If_< IsSigned<T>, SIMDcint64, SIMDcuint64 >( *address );
337 #endif
338 }
339 //*************************************************************************************************
340 
341 
342 
343 
344 //=================================================================================================
345 //
346 // 32-BIT FLOATING POINT SIMD TYPES
347 //
348 //=================================================================================================
349 
350 //*************************************************************************************************
361 BLAZE_ALWAYS_INLINE const SIMDfloat loada( const float* address ) noexcept
362 {
363  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
364 
365 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
366  return _mm512_load_ps( address );
367 #elif BLAZE_AVX_MODE
368  return _mm256_load_ps( address );
369 #elif BLAZE_SSE_MODE
370  return _mm_load_ps( address );
371 #else
372  return *address;
373 #endif
374 }
375 //*************************************************************************************************
376 
377 
378 //*************************************************************************************************
389 BLAZE_ALWAYS_INLINE const SIMDcfloat loada( const complex<float>* address ) noexcept
390 {
391  BLAZE_STATIC_ASSERT ( sizeof( complex<float> ) == 2UL*sizeof( float ) );
392  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
393 
394 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
395  return _mm512_load_ps( reinterpret_cast<const float*>( address ) );
396 #elif BLAZE_AVX_MODE
397  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
398 #elif BLAZE_SSE_MODE
399  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
400 #else
401  return *address;
402 #endif
403 }
404 //*************************************************************************************************
405 
406 
407 
408 
409 //=================================================================================================
410 //
411 // 64-BIT FLOATING POINT SIMD TYPES
412 //
413 //=================================================================================================
414 
415 //*************************************************************************************************
426 BLAZE_ALWAYS_INLINE const SIMDdouble loada( const double* address ) noexcept
427 {
428  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
429 
430 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
431  return _mm512_load_pd( address );
432 #elif BLAZE_AVX_MODE
433  return _mm256_load_pd( address );
434 #elif BLAZE_SSE2_MODE
435  return _mm_load_pd( address );
436 #else
437  return *address;
438 #endif
439 }
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
454 BLAZE_ALWAYS_INLINE const SIMDcdouble loada( const complex<double>* address ) noexcept
455 {
456  BLAZE_STATIC_ASSERT ( sizeof( complex<double> ) == 2UL*sizeof( double ) );
457  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
458 
459 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
460  return _mm512_load_pd( reinterpret_cast<const double*>( address ) );
461 #elif BLAZE_AVX_MODE
462  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
463 #elif BLAZE_SSE2_MODE
464  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
465 #else
466  return *address;
467 #endif
468 }
469 //*************************************************************************************************
470 
471 } // namespace blaze
472 
473 #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:58
#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