Set.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SIMD_SET_H_
36 #define _BLAZE_MATH_SIMD_SET_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Inline.h>
46 #include <blaze/util/Assert.h>
48 #include <blaze/util/EnableIf.h>
49 #include <blaze/util/mpl/And.h>
50 #include <blaze/util/mpl/If.h>
52 #include <blaze/util/Types.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // 8-BIT INTEGRAL SIMD TYPES
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
73 template< typename T > // Type of the integral value
74 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
75  , If_< IsSigned<T>, SIMDint8, SIMDuint8 > >
76  set( T value ) noexcept
77 {
78 #if BLAZE_AVX2_MODE
79  return _mm256_set1_epi8( value );
80 #elif BLAZE_SSE2_MODE
81  return _mm_set1_epi8( value );
82 #else
83  return value;
84 #endif
85 }
86 //*************************************************************************************************
87 
88 
89 //*************************************************************************************************
96 template< typename T > // Type of the integral value
97 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
98  , If_< IsSigned<T>, SIMDcint8, SIMDcuint8 > >
99  set( complex<T> value ) noexcept
100 {
101 #if BLAZE_AVX2_MODE
102  return _mm256_set_epi8( value.imag(), value.real(), value.imag(), value.real(),
103  value.imag(), value.real(), value.imag(), value.real(),
104  value.imag(), value.real(), value.imag(), value.real(),
105  value.imag(), value.real(), value.imag(), value.real(),
106  value.imag(), value.real(), value.imag(), value.real(),
107  value.imag(), value.real(), value.imag(), value.real(),
108  value.imag(), value.real(), value.imag(), value.real(),
109  value.imag(), value.real(), value.imag(), value.real() );
110 #elif BLAZE_SSE2_MODE
111  return _mm_set_epi8( value.imag(), value.real(), value.imag(), value.real(),
112  value.imag(), value.real(), value.imag(), value.real(),
113  value.imag(), value.real(), value.imag(), value.real(),
114  value.imag(), value.real(), value.imag(), value.real() );
115 #else
116  return value;
117 #endif
118  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
119 }
120 //*************************************************************************************************
121 
122 
123 
124 
125 //=================================================================================================
126 //
127 // 16-BIT INTEGRAL SIMD TYPES
128 //
129 //=================================================================================================
130 
131 //*************************************************************************************************
138 template< typename T > // Type of the integral value
139 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
140  , If_< IsSigned<T>, SIMDint16, SIMDuint16 > >
141  set( T value ) noexcept
142 {
143 #if BLAZE_AVX2_MODE
144  return _mm256_set1_epi16( value );
145 #elif BLAZE_SSE2_MODE
146  return _mm_set1_epi16( value );
147 #else
148  return value;
149 #endif
150 }
151 //*************************************************************************************************
152 
153 
154 //*************************************************************************************************
161 template< typename T > // Type of the integral value
162 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
163  , If_< IsSigned<T>, SIMDcint16, SIMDcuint16 > >
164  set( complex<T> value ) noexcept
165 {
166 #if BLAZE_AVX2_MODE
167  return _mm256_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
168  value.imag(), value.real(), value.imag(), value.real(),
169  value.imag(), value.real(), value.imag(), value.real(),
170  value.imag(), value.real(), value.imag(), value.real() );
171 #elif BLAZE_SSE2_MODE
172  return _mm_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
173  value.imag(), value.real(), value.imag(), value.real() );
174 #else
175  return value;
176 #endif
177  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
178 }
179 //*************************************************************************************************
180 
181 
182 
183 
184 //=================================================================================================
185 //
186 // 32-BIT INTEGRAL SIMD TYPES
187 //
188 //=================================================================================================
189 
190 //*************************************************************************************************
197 template< typename T > // Type of the integral value
198 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
199  , If_< IsSigned<T>, SIMDint32, SIMDuint32 > >
200  set( T value ) noexcept
201 {
202 #if BLAZE_MIC_MODE
203  return _mm512_set1_epi32( value );
204 #elif BLAZE_AVX2_MODE
205  return _mm256_set1_epi32( value );
206 #elif BLAZE_SSE2_MODE
207  return _mm_set1_epi32( value );
208 #else
209  return value;
210 #endif
211 }
212 //*************************************************************************************************
213 
214 
215 //*************************************************************************************************
222 template< typename T > // Type of the integral value
223 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
224  , If_< IsSigned<T>, SIMDcint32, SIMDcuint32 > >
225  set( complex<T> value ) noexcept
226 {
227 #if BLAZE_MIC_MODE
228  return _mm512_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
229  value.imag(), value.real(), value.imag(), value.real(),
230  value.imag(), value.real(), value.imag(), value.real(),
231  value.imag(), value.real(), value.imag(), value.real() );
232 #elif BLAZE_AVX2_MODE
233  return _mm256_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
234  value.imag(), value.real(), value.imag(), value.real() );
235 #elif BLAZE_SSE2_MODE
236  return _mm_set_epi32( value.imag(), value.real(), value.imag(), value.real() );
237 #else
238  return value;
239 #endif
240  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
241 }
242 //*************************************************************************************************
243 
244 
245 
246 
247 //=================================================================================================
248 //
249 // 64-BIT INTEGRAL SIMD TYPES
250 //
251 //=================================================================================================
252 
253 //*************************************************************************************************
260 template< typename T > // Type of the integral value
261 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
262  , If_< IsSigned<T>, SIMDint64, SIMDuint64 > >
263  set( T value ) noexcept
264 {
265 #if BLAZE_MIC_MODE
266  return _mm512_set1_epi64( value );
267 #elif BLAZE_AVX2_MODE
268  return _mm256_set1_epi64x( value );
269 #elif BLAZE_SSE2_MODE
270  return _mm_set1_epi64( value );
271 #else
272  return value;
273 #endif
274 }
275 //*************************************************************************************************
276 
277 
278 //*************************************************************************************************
285 template< typename T > // Type of the integral value
286 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
287  , If_< IsSigned<T>, SIMDcint64, SIMDcuint64 > >
288  set( complex<T> value ) noexcept
289 {
290 #if BLAZE_MIC_MODE
291  return _mm512_set_epi64( value.imag(), value.real(), value.imag(), value.real(),
292  value.imag(), value.real(), value.imag(), value.real() );
293 #elif BLAZE_AVX2_MODE
294  return _mm256_set_epi64( value.imag(), value.real(), value.imag(), value.real() );
295 #elif BLAZE_SSE2_MODE
296  return _mm_set_epi64( value.imag(), value.real() );
297 #else
298  return value;
299 #endif
300  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
301 }
302 //*************************************************************************************************
303 
304 
305 
306 
307 //=================================================================================================
308 //
309 // 32-BIT FLOATING POINT SIMD TYPES
310 //
311 //=================================================================================================
312 
313 //*************************************************************************************************
320 BLAZE_ALWAYS_INLINE const SIMDfloat set( float value ) noexcept
321 {
322 #if BLAZE_MIC_MODE
323  return _mm512_set1_ps( value );
324 #elif BLAZE_AVX_MODE
325  return _mm256_set1_ps( value );
326 #elif BLAZE_SSE_MODE
327  return _mm_set1_ps( value );
328 #else
329  return value;
330 #endif
331 }
332 //*************************************************************************************************
333 
334 
335 //*************************************************************************************************
342 BLAZE_ALWAYS_INLINE const SIMDcfloat set( const complex<float>& value ) noexcept
343 {
344 #if BLAZE_MIC_MODE
345  return _mm512_set_ps( value.imag(), value.real(), value.imag(), value.real(),
346  value.imag(), value.real(), value.imag(), value.real(),
347  value.imag(), value.real(), value.imag(), value.real(),
348  value.imag(), value.real(), value.imag(), value.real() );
349 #elif BLAZE_AVX_MODE
350  return _mm256_set_ps( value.imag(), value.real(), value.imag(), value.real(),
351  value.imag(), value.real(), value.imag(), value.real() );
352 #elif BLAZE_SSE_MODE
353  return _mm_set_ps( value.imag(), value.real(), value.imag(), value.real() );
354 #else
355  return value;
356 #endif
357  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
358 }
359 //*************************************************************************************************
360 
361 
362 
363 
364 //=================================================================================================
365 //
366 // 64-BIT FLOATING POINT SIMD TYPES
367 //
368 //=================================================================================================
369 
370 //*************************************************************************************************
377 BLAZE_ALWAYS_INLINE const SIMDdouble set( double value ) noexcept
378 {
379 #if BLAZE_MIC_MODE
380  return _mm512_set1_pd( value );
381 #elif BLAZE_AVX_MODE
382  return _mm256_set1_pd( value );
383 #elif BLAZE_SSE2_MODE
384  return _mm_set1_pd( value );
385 #else
386  return value;
387 #endif
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
399 BLAZE_ALWAYS_INLINE const SIMDcdouble set( const complex<double>& value ) noexcept
400 {
401 #if BLAZE_MIC_MODE
402  return _mm512_set_pd( value.imag(), value.real(), value.imag(), value.real(),
403  value.imag(), value.real(), value.imag(), value.real() );
404 #elif BLAZE_AVX_MODE
405  return _mm256_set_pd( value.imag(), value.real(), value.imag(), value.real() );
406 #elif BLAZE_SSE2_MODE
407  return _mm_set_pd( value.imag(), value.real() );
408 #else
409  return value;
410 #endif
411  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
412 }
413 //*************************************************************************************************
414 
415 } // namespace blaze
416 
417 #endif
Header file for basic type definitions.
Header file for the IsIntegral type trait.
Header file for the And class template.
SIMD type for 64-bit double precision floating point data values.
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
Header file for the If class template.
Compile time assertion.
Constraint on the data type.
Header file for the EnableIf class template.
Header file for the basic SIMD types.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
Header file for run time assertion macros.
Header file for the HasSize type trait.
SIMD type for 32-bit single precision complex values.
Header file for the IsSigned type trait.
SIMD type for 32-bit single precision floating point data values.
SIMD type for 64-bit double precision complex values.
System settings for the SSE mode.
#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:112
System settings for the inline keywords.