Loada.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_INTRINSICS_LOADA_H_
36 #define _BLAZE_MATH_INTRINSICS_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>
54 
55 
56 namespace blaze {
57 
58 //=================================================================================================
59 //
60 // INTRINSIC LOAD FUNCTIONS
61 //
62 //=================================================================================================
63 
64 //*************************************************************************************************
75 template< typename T > // Type of the integral value
76 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,2UL> >, simd_int16_t >::Type
77  loada( const T* address )
78 {
79  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
80 
81 #if BLAZE_AVX2_MODE
82  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
83 #elif BLAZE_SSE2_MODE
84  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
85 #else
86  return *address;
87 #endif
88 }
89 //*************************************************************************************************
90 
91 
92 //*************************************************************************************************
103 template< typename T > // Type of the integral value
104 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,4UL> >, simd_int32_t >::Type
105  loada( const T* address )
106 {
107  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
108 
109 #if BLAZE_MIC_MODE
110  return _mm512_load_epi32( address );
111 #elif BLAZE_AVX2_MODE
112  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
113 #elif BLAZE_SSE2_MODE
114  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
115 #else
116  return *address;
117 #endif
118 }
119 //*************************************************************************************************
120 
121 
122 //*************************************************************************************************
133 template< typename T > // Type of the integral value
134 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,8UL> >, simd_int64_t >::Type
135  loada( const T* address )
136 {
137  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
138 
139 #if BLAZE_MIC_MODE
140  return _mm512_load_epi64( address );
141 #elif BLAZE_AVX2_MODE
142  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
143 #elif BLAZE_SSE2_MODE
144  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
145 #else
146  return *address;
147 #endif
148 }
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
163 BLAZE_ALWAYS_INLINE simd_float_t loada( const float* address )
164 {
165  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
166 
167 #if BLAZE_MIC_MODE
168  return _mm512_load_ps( address );
169 #elif BLAZE_AVX_MODE
170  return _mm256_load_ps( address );
171 #elif BLAZE_SSE_MODE
172  return _mm_load_ps( address );
173 #else
174  return *address;
175 #endif
176 }
177 //*************************************************************************************************
178 
179 
180 //*************************************************************************************************
191 BLAZE_ALWAYS_INLINE simd_double_t loada( const double* address )
192 {
193  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
194 
195 #if BLAZE_MIC_MODE
196  return _mm512_load_pd( address );
197 #elif BLAZE_AVX_MODE
198  return _mm256_load_pd( address );
199 #elif BLAZE_SSE2_MODE
200  return _mm_load_pd( address );
201 #else
202  return *address;
203 #endif
204 }
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
219 template< typename T > // Type of the integral value
220 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,2UL> >, simd_cint16_t >::Type
221  loada( const complex<T>* address )
222 {
223  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
224  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
225 
226 #if BLAZE_AVX2_MODE
227  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
228 #elif BLAZE_SSE2_MODE
229  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
230 #else
231  return *address;
232 #endif
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
248 template< typename T > // Type of the integral value
249 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,4UL> >, simd_cint32_t >::Type
250  loada( const complex<T>* address )
251 {
252  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
253  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
254 
255 #if BLAZE_MIC_MODE
256  return _mm512_load_epi32( address );
257 #elif BLAZE_AVX2_MODE
258  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
259 #elif BLAZE_SSE2_MODE
260  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
261 #else
262  return *address;
263 #endif
264 }
265 //*************************************************************************************************
266 
267 
268 //*************************************************************************************************
279 template< typename T > // Type of the integral value
280 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,8UL> >, simd_cint64_t >::Type
281  loada( const complex<T>* address )
282 {
283  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
284  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
285 
286 #if BLAZE_MIC_MODE
287  return _mm512_load_epi64( address );
288 #elif BLAZE_AVX2_MODE
289  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
290 #elif BLAZE_SSE2_MODE
291  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
292 #else
293  return *address;
294 #endif
295 }
296 //*************************************************************************************************
297 
298 
299 //*************************************************************************************************
310 BLAZE_ALWAYS_INLINE simd_cfloat_t loada( const complex<float>* address )
311 {
312  BLAZE_STATIC_ASSERT ( sizeof( complex<float> ) == 2UL*sizeof( float ) );
313  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
314 
315 #if BLAZE_MIC_MODE
316  return _mm512_load_ps( reinterpret_cast<const float*>( address ) );
317 #elif BLAZE_AVX_MODE
318  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
319 #elif BLAZE_SSE_MODE
320  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
321 #else
322  return *address;
323 #endif
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
339 BLAZE_ALWAYS_INLINE simd_cdouble_t loada( const complex<double>* address )
340 {
341  BLAZE_STATIC_ASSERT ( sizeof( complex<double> ) == 2UL*sizeof( double ) );
342  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
343 
344 #if BLAZE_MIC_MODE
345  return _mm512_load_pd( reinterpret_cast<const double*>( address ) );
346 #elif BLAZE_AVX_MODE
347  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
348 #elif BLAZE_SSE2_MODE
349  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
350 #else
351  return *address;
352 #endif
353 }
354 //*************************************************************************************************
355 
356 } // namespace blaze
357 
358 #endif
Header file for the IsIntegral type trait.
Header file for the And class template.
Intrinsic type for 64-bit double precision floating point data 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
Compile time assertion.
Header file for the EnableIf class template.
Header file for the basic intrinsic types.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loada(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loada.h:77
Intrinsic type for 32-bit single precision floating point data values.
Header file for run time assertion macros.
Header file for the HasSize type trait.
Intrinsic type for 64-bit double precision complex values.
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
Intrinsic type for 32-bit single precision complex values.
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
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