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>
34 #include <blaze/util/EnableIf.h>
35 
36 
37 namespace blaze {
38 
39 //=================================================================================================
40 //
41 // CLASS DEFINITION
42 //
43 //=================================================================================================
44 
45 //*************************************************************************************************
54 template< typename T // Type of the integral
55  , size_t N > // Size of the integral
56 struct Load;
58 //*************************************************************************************************
59 
60 
61 
62 
63 //=================================================================================================
64 //
65 // SPECIALIZATIONS OF THE LOAD CLASS TEMPLATE
66 //
67 //=================================================================================================
68 
69 //*************************************************************************************************
74 template< typename T > // Type of the integral
75 struct Load<T,2UL>
76 {
77  public:
78  //**Type definitions****************************************************************************
79  typedef sse_int16_t Type;
80  //**********************************************************************************************
81 
82  //**Set function********************************************************************************
83  static inline Type load( const T* address )
84  {
85 #if BLAZE_SSE2_MODE
86  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
87  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
88 #else
89  return *address;
90 #endif
91  }
92  //**********************************************************************************************
93 
94  private:
95  //**Compile time checks*************************************************************************
97  //**********************************************************************************************
98 };
100 //*************************************************************************************************
101 
102 
103 //*************************************************************************************************
108 template< typename T > // Type of the integral
109 struct Load<T,4UL>
110 {
111  public:
112  //**Type definitions****************************************************************************
113  typedef sse_int32_t Type;
114  //**********************************************************************************************
115 
116  //**Set function********************************************************************************
117  static inline Type load( const T* address )
118  {
119 #if BLAZE_MIC_MODE
120  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
121  return _mm512_load_epi32( address );
122 #elif BLAZE_SSE2_MODE
123  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
124  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
125 #else
126  return *address;
127 #endif
128  }
129  //**********************************************************************************************
130 
131  private:
132  //**Compile time checks*************************************************************************
134  //**********************************************************************************************
135 };
137 //*************************************************************************************************
138 
139 
140 //*************************************************************************************************
145 template< typename T > // Type of the integral
146 struct Load<T,8UL>
147 {
148  public:
149  //**Type definitions****************************************************************************
150  typedef sse_int64_t Type;
151  //**********************************************************************************************
152 
153  //**Set function********************************************************************************
154  static inline Type load( const T* address )
155  {
156 #if BLAZE_MIC_MODE
157  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
158  return _mm512_load_epi64( address );
159 #elif BLAZE_SSE2_MODE
160  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
161  return _mm_load_si128( reinterpret_cast<const __m128i*>( address ) );
162 #else
163  return *address;
164 #endif
165  }
166  //**********************************************************************************************
167 
168  private:
169  //**Compile time checks*************************************************************************
171  //**********************************************************************************************
172 };
174 //*************************************************************************************************
175 
176 
177 
178 
179 //=================================================================================================
180 //
181 // INTRINSIC LOAD FUNCTIONS
182 //
183 //=================================================================================================
184 
185 //*************************************************************************************************
192 template< typename T > // Type of the integral value
193 inline typename EnableIf< IsIntegral<T>, Load<T,sizeof(T)> >::Type::Type
194  load( const T* address )
195 {
196  return Load<T,sizeof(T)>::load( address );
197 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
208 inline sse_float_t load( const float* address )
209 {
210 #if BLAZE_MIC_MODE
211  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
212  return _mm512_load_ps( address );
213 #elif BLAZE_AVX_MODE
214  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
215  return _mm256_load_ps( address );
216 #elif BLAZE_SSE_MODE
217  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
218  return _mm_load_ps( address );
219 #else
220  return *address;
221 #endif
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
233 inline sse_double_t load( const double* address )
234 {
235 #if BLAZE_MIC_MODE
236  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
237  return _mm512_load_pd( address );
238 #elif BLAZE_AVX_MODE
239  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
240  return _mm256_load_pd( address );
241 #elif BLAZE_SSE2_MODE
242  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
243  return _mm_load_pd( address );
244 #else
245  return *address;
246 #endif
247 }
248 //*************************************************************************************************
249 
250 } // namespace blaze
251 
252 #endif