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