Loadu.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SIMD_LOADU_H_
36 #define _BLAZE_MATH_SIMD_LOADU_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Inline.h>
46 #include <blaze/util/Complex.h>
47 #include <blaze/util/EnableIf.h>
48 #include <blaze/util/mpl/And.h>
49 #include <blaze/util/mpl/If.h>
54 
55 
56 namespace blaze {
57 
58 //=================================================================================================
59 //
60 // 8-BIT INTEGRAL SIMD TYPES
61 //
62 //=================================================================================================
63 
64 //*************************************************************************************************
74 template< typename T > // Type of the integral value
75 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
76  , If_< IsSigned<T>, SIMDint8, SIMDuint8 > >
77  loadu( const T* address ) noexcept
78 {
79 #if BLAZE_AVX2_MODE
80  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
81 #elif BLAZE_SSE2_MODE
82  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
83 #else
84  return *address;
85 #endif
86 }
87 //*************************************************************************************************
88 
89 
90 //*************************************************************************************************
100 template< typename T > // Type of the integral value
101 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
102  , If_< IsSigned<T>, SIMDcint8, SIMDcuint8 > >
103  loadu( const complex<T>* address ) noexcept
104 {
105  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
106 
107 #if BLAZE_AVX2_MODE
108  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
109 #elif BLAZE_SSE2_MODE
110  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
111 #else
112  return *address;
113 #endif
114 }
115 //*************************************************************************************************
116 
117 
118 
119 
120 //=================================================================================================
121 //
122 // 16-BIT INTEGRAL SIMD TYPES
123 //
124 //=================================================================================================
125 
126 //*************************************************************************************************
136 template< typename T > // Type of the integral value
137 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
138  , If_< IsSigned<T>, SIMDint16, SIMDuint16 > >
139  loadu( const T* address ) noexcept
140 {
141 #if BLAZE_AVX2_MODE
142  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
143 #elif BLAZE_SSE2_MODE
144  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
145 #else
146  return *address;
147 #endif
148 }
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
162 template< typename T > // Type of the integral value
163 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
164  , If_< IsSigned<T>, SIMDcint16, SIMDcuint16 > >
165  loadu( const complex<T>* address ) noexcept
166 {
167  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
168 
169 #if BLAZE_AVX2_MODE
170  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
171 #elif BLAZE_SSE2_MODE
172  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
173 #else
174  return *address;
175 #endif
176 }
177 //*************************************************************************************************
178 
179 
180 
181 
182 //=================================================================================================
183 //
184 // 32-BIT INTEGRAL SIMD TYPES
185 //
186 //=================================================================================================
187 
188 //*************************************************************************************************
198 template< typename T > // Type of the integral value
199 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
200  , If_< IsSigned<T>, SIMDint32, SIMDuint32 > >
201  loadu( const T* address ) noexcept
202 {
203 #if BLAZE_MIC_MODE
204  __m512i v1 = _mm512_setzero_epi32();
205  v1 = _mm512_loadunpacklo_epi32( v1, address );
206  v1 = _mm512_loadunpackhi_epi32( v1, address+16UL );
207  return v1;
208 #elif BLAZE_AVX2_MODE
209  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
210 #elif BLAZE_SSE2_MODE
211  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
212 #else
213  return *address;
214 #endif
215 }
216 //*************************************************************************************************
217 
218 
219 //*************************************************************************************************
229 template< typename T > // Type of the integral value
230 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
231  , If_< IsSigned<T>, SIMDcint32, SIMDcuint32 > >
232  loadu( const complex<T>* address ) noexcept
233 {
234  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
235 
236 #if BLAZE_MIC_MODE
237  __m512i v1 = _mm512_setzero_epi32();
238  v1 = _mm512_loadunpacklo_epi32( v1, address );
239  v1 = _mm512_loadunpackhi_epi32( v1, address+8UL );
240  return v1;
241 #elif BLAZE_AVX2_MODE
242  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
243 #elif BLAZE_SSE2_MODE
244  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
245 #else
246  return *address;
247 #endif
248 }
249 //*************************************************************************************************
250 
251 
252 
253 
254 //=================================================================================================
255 //
256 // 64-BIT INTEGRAL SIMD TYPES
257 //
258 //=================================================================================================
259 
260 //*************************************************************************************************
270 template< typename T > // Type of the integral value
271 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
272  , If_< IsSigned<T>, SIMDint64, SIMDuint64 > >
273  loadu( const T* address ) noexcept
274 {
275 #if BLAZE_MIC_MODE
276  __m512i v1 = _mm512_setzero_epi32();
277  v1 = _mm512_loadunpacklo_epi64( v1, address );
278  v1 = _mm512_loadunpackhi_epi64( v1, address+8UL );
279  return v1;
280 #elif BLAZE_AVX2_MODE
281  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
282 #elif BLAZE_SSE2_MODE
283  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
284 #else
285  return *address;
286 #endif
287 }
288 //*************************************************************************************************
289 
290 
291 //*************************************************************************************************
301 template< typename T > // Type of the integral value
302 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
303  , If_< IsSigned<T>, SIMDcint64, SIMDcuint64 > >
304  loadu( const complex<T>* address ) noexcept
305 {
306  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
307 
308 #if BLAZE_MIC_MODE
309  __m512i v1 = _mm512_setzero_epi32();
310  v1 = _mm512_loadunpacklo_epi64( v1, address );
311  v1 = _mm512_loadunpackhi_epi64( v1, address+4UL );
312  return v1;
313 #elif BLAZE_AVX2_MODE
314  return _mm256_loadu_si256( reinterpret_cast<const __m256i*>( address ) );
315 #elif BLAZE_SSE2_MODE
316  return _mm_loadu_si128( reinterpret_cast<const __m128i*>( address ) );
317 #else
318  return If_< IsSigned<T>, SIMDcint64, SIMDcuint64 >( *address );
319 #endif
320 }
321 //*************************************************************************************************
322 
323 
324 
325 
326 //=================================================================================================
327 //
328 // 32-BIT FLOATING POINT SIMD TYPES
329 //
330 //=================================================================================================
331 
332 //*************************************************************************************************
342 BLAZE_ALWAYS_INLINE const SIMDfloat loadu( const float* address ) noexcept
343 {
344 #if BLAZE_MIC_MODE
345  __m512 v1 = _mm512_setzero_ps();
346  v1 = _mm512_loadunpacklo_ps( v1, address );
347  v1 = _mm512_loadunpackhi_ps( v1, address+16UL );
348  return v1;
349 #elif BLAZE_AVX_MODE
350  return _mm256_loadu_ps( address );
351 #elif BLAZE_SSE_MODE
352  return _mm_loadu_ps( address );
353 #else
354  return *address;
355 #endif
356 }
357 //*************************************************************************************************
358 
359 
360 //*************************************************************************************************
370 BLAZE_ALWAYS_INLINE const SIMDcfloat loadu( const complex<float>* address ) noexcept
371 {
372  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
373 
374 #if BLAZE_MIC_MODE
375  __m512 v1 = _mm512_setzero_ps();
376  v1 = _mm512_loadunpacklo_ps( v1, reinterpret_cast<const float*>( address ) );
377  v1 = _mm512_loadunpackhi_ps( v1, reinterpret_cast<const float*>( address+8UL ) );
378  return v1;
379 #elif BLAZE_AVX_MODE
380  return _mm256_loadu_ps( reinterpret_cast<const float*>( address ) );
381 #elif BLAZE_SSE_MODE
382  return _mm_loadu_ps( reinterpret_cast<const float*>( address ) );
383 #else
384  return *address;
385 #endif
386 }
387 //*************************************************************************************************
388 
389 
390 
391 
392 //=================================================================================================
393 //
394 // 64-BIT FLOATING POINT SIMD TYPES
395 //
396 //=================================================================================================
397 
398 //*************************************************************************************************
408 BLAZE_ALWAYS_INLINE const SIMDdouble loadu( const double* address ) noexcept
409 {
410 #if BLAZE_MIC_MODE
411  __m512d v1 = _mm512_setzero_pd();
412  v1 = _mm512_loadunpacklo_pd( v1, address );
413  v1 = _mm512_loadunpackhi_pd( v1, address+8UL );
414  return v1;
415 #elif BLAZE_AVX_MODE
416  return _mm256_loadu_pd( address );
417 #elif BLAZE_SSE2_MODE
418  return _mm_loadu_pd( address );
419 #else
420  return *address;
421 #endif
422 }
423 //*************************************************************************************************
424 
425 
426 //*************************************************************************************************
436 BLAZE_ALWAYS_INLINE const SIMDcdouble loadu( const complex<double>* address ) noexcept
437 {
438  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
439 
440 #if BLAZE_MIC_MODE
441  __m512d v1 = _mm512_setzero_pd();
442  v1 = _mm512_loadunpacklo_pd( v1, reinterpret_cast<const double*>( address ) );
443  v1 = _mm512_loadunpackhi_pd( v1, reinterpret_cast<const double*>( address+4UL ) );
444  return v1;
445 #elif BLAZE_AVX_MODE
446  return _mm256_loadu_pd( reinterpret_cast<const double*>( address ) );
447 #elif BLAZE_SSE2_MODE
448  return _mm_loadu_pd( reinterpret_cast<const double*>( address ) );
449 #else
450  return *address;
451 #endif
452 }
453 //*************************************************************************************************
454 
455 } // namespace blaze
456 
457 #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.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loadu(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loadu.h:77
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.
SIMD type for 32-bit signed integral data values.
Header file for the EnableIf class template.
Header file for the basic SIMD types.
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.
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.
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.