All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Store.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_INTRINSICS_STORE_H_
23 #define _BLAZE_MATH_INTRINSICS_STORE_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
31 #include <blaze/system/SSE.h>
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 Store;
58 //*************************************************************************************************
59 
60 
61 
62 
63 //=================================================================================================
64 //
65 // SPECIALIZATIONS OF THE STORE CLASS TEMPLATE
66 //
67 //=================================================================================================
68 
69 //*************************************************************************************************
74 template< typename T > // Type of the integral
75 struct Store<T,2UL>
76 {
77  public:
78  //**Type definitions****************************************************************************
79  typedef sse_int16_t Type;
80  //**********************************************************************************************
81 
82  //**Set function********************************************************************************
83  static inline void store( T* address, const Type& value )
84  {
85 #if BLAZE_SSE2_MODE
86  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
87  _mm_store_si128( reinterpret_cast<__m128i*>( address ), value.value );
88 #else
89  *address = value.value;
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 Store<T,4UL>
110 {
111  public:
112  //**Type definitions****************************************************************************
113  typedef sse_int32_t Type;
114  //**********************************************************************************************
115 
116  //**Set function********************************************************************************
117  static inline void store( T* address, const Type& value )
118  {
119 #if BLAZE_MIC_MODE
120  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
121  _mm512_store_epi32( address, value.value );
122 #elif BLAZE_SSE2_MODE
123  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
124  _mm_store_si128( reinterpret_cast<__m128i*>( address ), value.value );
125 #else
126  *address = value.value;
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 Store<T,8UL>
147 {
148  public:
149  //**Type definitions****************************************************************************
150  typedef sse_int64_t Type;
151  //**********************************************************************************************
152 
153  //**Set function********************************************************************************
154  static inline void store( T* address, const Type& value )
155  {
156 #if BLAZE_MIC_MODE
157  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
158  _mm512_store_epi64( address, value.value );
159 #elif BLAZE_SSE2_MODE
160  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
161  _mm_store_si128( reinterpret_cast<__m128i*>( address ), value.value );
162 #else
163  *address = value.value;
164 #endif
165  }
166  //**********************************************************************************************
167 
168  private:
169  //**Compile time checks*************************************************************************
171  //**********************************************************************************************
172 };
174 //*************************************************************************************************
175 
176 
177 
178 
179 //=================================================================================================
180 //
181 // INTRINSIC STORE FUNCTIONS
182 //
183 //=================================================================================================
184 
185 //*************************************************************************************************
193 template< typename T > // Type of the integral value
194 inline typename EnableIf< IsIntegral<T> >::Type
195  store( T* address, const typename Store<T,sizeof(T)>::Type& value )
196 {
197  Store<T,sizeof(T)>::store( address, value );
198 }
199 //*************************************************************************************************
200 
201 
202 //*************************************************************************************************
210 inline void store( float* address, const sse_float_t& value )
211 {
212 #if BLAZE_MIC_MODE
213  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
214  _mm512_store_ps( address, value.value );
215 #elif BLAZE_AVX_MODE
216  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
217  _mm256_store_ps( address, value.value );
218 #elif BLAZE_SSE_MODE
219  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
220  _mm_store_ps( address, value.value );
221 #else
222  *address = value.value;
223 #endif
224 }
225 //*************************************************************************************************
226 
227 
228 //*************************************************************************************************
236 inline void store( double* address, const sse_double_t& value )
237 {
238 #if BLAZE_MIC_MODE
239  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 64UL ), "Invalid alignment detected" );
240  _mm512_store_pd( address, value.value );
241 #elif BLAZE_AVX_MODE
242  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 32UL ), "Invalid alignment detected" );
243  _mm256_store_pd( address, value.value );
244 #elif BLAZE_SSE2_MODE
245  BLAZE_INTERNAL_ASSERT( !( reinterpret_cast<size_t>( address ) % 16UL ), "Invalid alignment detected" );
246  _mm_store_pd( address, value.value );
247 #else
248  *address = value.value;
249 #endif
250 }
251 //*************************************************************************************************
252 
253 } // namespace blaze
254 
255 #endif