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 
44 #include <blaze/system/Inline.h>
47 #include <blaze/util/Assert.h>
48 #include <blaze/util/Complex.h>
50 #include <blaze/util/EnableIf.h>
51 #include <blaze/util/mpl/And.h>
53 #include <blaze/util/Types.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // INTRINSIC LOAD FUNCTIONS
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
77 template< typename T > // Type of the integral value
78 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,2UL> >, sse_int16_t >::Type
79  load( const T* address )
80 {
81  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
82 
83 #if BLAZE_AVX2_MODE
84  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
85 #elif BLAZE_SSE2_MODE
86  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
87 #else
88  return *address;
89 #endif
90 }
91 //*************************************************************************************************
92 
93 
94 //*************************************************************************************************
105 template< typename T > // Type of the integral value
106 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,4UL> >, sse_int32_t >::Type
107  load( const T* address )
108 {
109  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
110 
111 #if BLAZE_MIC_MODE
112  return _mm512_load_epi32( address );
113 #elif BLAZE_AVX2_MODE
114  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
115 #elif BLAZE_SSE2_MODE
116  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
117 #else
118  return *address;
119 #endif
120 }
121 //*************************************************************************************************
122 
123 
124 //*************************************************************************************************
135 template< typename T > // Type of the integral value
136 BLAZE_ALWAYS_INLINE typename EnableIf< And< IsIntegral<T>, HasSize<T,8UL> >, sse_int64_t >::Type
137  load( const T* address )
138 {
139  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
140 
141 #if BLAZE_MIC_MODE
142  return _mm512_load_epi64( 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 
154 //*************************************************************************************************
165 BLAZE_ALWAYS_INLINE sse_float_t load( const float* address )
166 {
167  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
168 
169 #if BLAZE_MIC_MODE
170  return _mm512_load_ps( address );
171 #elif BLAZE_AVX_MODE
172  return _mm256_load_ps( address );
173 #elif BLAZE_SSE_MODE
174  return _mm_load_ps( address );
175 #else
176  return *address;
177 #endif
178 }
179 //*************************************************************************************************
180 
181 
182 //*************************************************************************************************
193 BLAZE_ALWAYS_INLINE sse_double_t load( const double* address )
194 {
195  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
196 
197 #if BLAZE_MIC_MODE
198  return _mm512_load_pd( address );
199 #elif BLAZE_AVX_MODE
200  return _mm256_load_pd( address );
201 #elif BLAZE_SSE2_MODE
202  return _mm_load_pd( address );
203 #else
204  return *address;
205 #endif
206 }
207 //*************************************************************************************************
208 
209 
210 //*************************************************************************************************
221 BLAZE_ALWAYS_INLINE sse_cfloat_t load( const complex<float>* address )
222 {
223  BLAZE_STATIC_ASSERT ( sizeof( complex<float> ) == 2UL*sizeof( float ) );
224  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
225 
226 #if BLAZE_MIC_MODE
227  return _mm512_load_ps( reinterpret_cast<const float*>( address ) );
228 #elif BLAZE_AVX_MODE
229  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
230 #elif BLAZE_SSE_MODE
231  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
232 #else
233  return *address;
234 #endif
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
250 BLAZE_ALWAYS_INLINE sse_cdouble_t load( const complex<double>* address )
251 {
252  BLAZE_STATIC_ASSERT ( sizeof( complex<double> ) == 2UL*sizeof( double ) );
253  BLAZE_INTERNAL_ASSERT( checkAlignment( address ), "Invalid alignment detected" );
254 
255 #if BLAZE_MIC_MODE
256  return _mm512_load_pd( reinterpret_cast<const double*>( address ) );
257 #elif BLAZE_AVX_MODE
258  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
259 #elif BLAZE_SSE2_MODE
260  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
261 #else
262  return *address;
263 #endif
264 }
265 //*************************************************************************************************
266 
267 } // namespace blaze
268 
269 #endif
Intrinsic type for 32-bit single precision complex values.
Header file for basic type definitions.
Header file for the IsIntegral type trait.
Header file for the And class template.
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.
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.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type load(const T *address)
Loads a vector of 2-byte integral values.
Definition: Load.h:79
Header file for the basic intrinsic types.
Header file for run time assertion macros.
Header file for the HasSize type trait.
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
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