All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Load.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_INTRINSICS_LOAD_H_
23 #define _BLAZE_MATH_INTRINSICS_LOAD_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
32 #include <blaze/util/Assert.h>
33 #include <blaze/util/Complex.h>
35 #include <blaze/util/EnableIf.h>
37 
38 
39 namespace blaze {
40 
41 //=================================================================================================
42 //
43 // CLASS DEFINITION
44 //
45 //=================================================================================================
46 
47 //*************************************************************************************************
56 template< typename T // Type of the integral
57  , size_t N > // Size of the integral
58 struct Load;
60 //*************************************************************************************************
61 
62 
63 
64 
65 //=================================================================================================
66 //
67 // SPECIALIZATIONS OF THE LOAD CLASS TEMPLATE
68 //
69 //=================================================================================================
70 
71 //*************************************************************************************************
76 template< typename T > // Type of the integral
77 struct Load<T,2UL>
78 {
79  public:
80  //**Type definitions****************************************************************************
81  typedef sse_int16_t Type;
82  //**********************************************************************************************
83 
84  //**Set function********************************************************************************
85  static inline Type load( const T* address )
86  {
87 #if BLAZE_AVX2_MODE
88  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
89  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
90 #elif BLAZE_SSE2_MODE
91  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
92  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
93 #else
94  return *address;
95 #endif
96  }
97  //**********************************************************************************************
98 
99  private:
100  //**Compile time checks*************************************************************************
102  //**********************************************************************************************
103 };
105 //*************************************************************************************************
106 
107 
108 //*************************************************************************************************
113 template< typename T > // Type of the integral
114 struct Load<T,4UL>
115 {
116  public:
117  //**Type definitions****************************************************************************
118  typedef sse_int32_t Type;
119  //**********************************************************************************************
120 
121  //**Set function********************************************************************************
122  static inline Type load( const T* address )
123  {
124 #if BLAZE_MIC_MODE
125  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
126  return _mm512_load_epi32( address );
127 #elif BLAZE_AVX2_MODE
128  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
129  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
130 #elif BLAZE_SSE2_MODE
131  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
132  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
133 #else
134  return *address;
135 #endif
136  }
137  //**********************************************************************************************
138 
139  private:
140  //**Compile time checks*************************************************************************
142  //**********************************************************************************************
143 };
145 //*************************************************************************************************
146 
147 
148 //*************************************************************************************************
153 template< typename T > // Type of the integral
154 struct Load<T,8UL>
155 {
156  public:
157  //**Type definitions****************************************************************************
158  typedef sse_int64_t Type;
159  //**********************************************************************************************
160 
161  //**Set function********************************************************************************
162  static inline Type load( const T* address )
163  {
164 #if BLAZE_MIC_MODE
165  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
166  return _mm512_load_epi64( address );
167 #elif BLAZE_AVX2_MODE
168  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
169  return _mm256_load_si256( reinterpret_cast<const __m256i*>( address ) );
170 #elif BLAZE_SSE2_MODE
171  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
172  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
173 #else
174  return *address;
175 #endif
176  }
177  //**********************************************************************************************
178 
179  private:
180  //**Compile time checks*************************************************************************
182  //**********************************************************************************************
183 };
185 //*************************************************************************************************
186 
187 
188 
189 
190 //=================================================================================================
191 //
192 // INTRINSIC LOAD FUNCTIONS
193 //
194 //=================================================================================================
195 
196 //*************************************************************************************************
203 template< typename T > // Type of the integral value
204 inline typename EnableIf< IsIntegral<T>, Load<T,sizeof(T)> >::Type::Type
205  load( const T* address )
206 {
207  return Load<T,sizeof(T)>::load( address );
208 }
209 //*************************************************************************************************
210 
211 
212 //*************************************************************************************************
219 inline sse_float_t load( const float* address )
220 {
221 #if BLAZE_MIC_MODE
222  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
223  return _mm512_load_ps( address );
224 #elif BLAZE_AVX_MODE
225  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
226  return _mm256_load_ps( address );
227 #elif BLAZE_SSE_MODE
228  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
229  return _mm_load_ps( address );
230 #else
231  return *address;
232 #endif
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
244 inline sse_double_t load( const double* address )
245 {
246 #if BLAZE_MIC_MODE
247  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
248  return _mm512_load_pd( address );
249 #elif BLAZE_AVX_MODE
250  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
251  return _mm256_load_pd( address );
252 #elif BLAZE_SSE2_MODE
253  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
254  return _mm_load_pd( address );
255 #else
256  return *address;
257 #endif
258 }
259 //*************************************************************************************************
260 
261 
262 //*************************************************************************************************
269 inline sse_cfloat_t load( const complex<float>* address )
270 {
271 #if BLAZE_AVX_MODE
272  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
273  return _mm256_load_ps( reinterpret_cast<const float*>( address ) );
274 #elif BLAZE_SSE_MODE
275  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
276  return _mm_load_ps( reinterpret_cast<const float*>( address ) );
277 #else
278  return *address;
279 #endif
280  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
292 inline sse_cdouble_t load( const complex<double>* address )
293 {
294 #if BLAZE_AVX_MODE
295  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
296  return _mm256_load_pd( reinterpret_cast<const double*>( address ) );
297 #elif BLAZE_SSE2_MODE
298  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
299  return _mm_load_pd( reinterpret_cast<const double*>( address ) );
300 #else
301  return *address;
302 #endif
303  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
304 }
305 //*************************************************************************************************
306 
307 } // namespace blaze
308 
309 #endif