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/If.h>
51 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // 8-BIT INTEGRAL SIMD TYPES
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
72 template< typename T > // Type of the integral value
73 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,1UL>
74  , If_t< IsSigned_v<T>, SIMDint8, SIMDuint8 > >
75  set( T value ) noexcept
76 {
77 #if BLAZE_AVX512BW_MODE
78  return _mm512_set1_epi8( value );
79 #elif BLAZE_AVX2_MODE
80  return _mm256_set1_epi8( value );
81 #elif BLAZE_SSE2_MODE
82  return _mm_set1_epi8( value );
83 #else
84  return value;
85 #endif
86 }
87 //*************************************************************************************************
88 
89 
90 //*************************************************************************************************
97 template< typename T > // Type of the integral value
98 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,1UL>
99  , If_t< IsSigned_v<T>, SIMDcint8, SIMDcuint8 > >
100  set( complex<T> value ) noexcept
101 {
102 #if BLAZE_AVX512BW_MODE
103  __m512i dst( _mm512_maskz_set1_epi8( 0XAAAAAAAA, value.imag() ) );
104  dst = _mm512_maskz_set1_epi8( 0x55555555, value.real() );
105  return dst;
106 #elif BLAZE_AVX2_MODE
107  return _mm256_set_epi8( 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  value.imag(), value.real(), value.imag(), value.real(),
111  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 #elif BLAZE_SSE2_MODE
116  return _mm_set_epi8( value.imag(), value.real(), value.imag(), value.real(),
117  value.imag(), value.real(), value.imag(), value.real(),
118  value.imag(), value.real(), value.imag(), value.real(),
119  value.imag(), value.real(), value.imag(), value.real() );
120 #else
121  return value;
122 #endif
123  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
124 }
125 //*************************************************************************************************
126 
127 
128 
129 
130 //=================================================================================================
131 //
132 // 16-BIT INTEGRAL SIMD TYPES
133 //
134 //=================================================================================================
135 
136 //*************************************************************************************************
143 template< typename T > // Type of the integral value
144 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,2UL>
145  , If_t< IsSigned_v<T>, SIMDint16, SIMDuint16 > >
146  set( T value ) noexcept
147 {
148 #if BLAZE_AVX512BW_MODE
149  return _mm512_set1_epi16( value );
150 #elif BLAZE_AVX2_MODE
151  return _mm256_set1_epi16( value );
152 #elif BLAZE_SSE2_MODE
153  return _mm_set1_epi16( value );
154 #else
155  return value;
156 #endif
157 }
158 //*************************************************************************************************
159 
160 
161 //*************************************************************************************************
168 template< typename T > // Type of the integral value
169 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,2UL>
170  , If_t< IsSigned_v<T>, SIMDcint16, SIMDcuint16 > >
171  set( complex<T> value ) noexcept
172 {
173 #if BLAZE_AVX512BW_MODE
174  __m512i dst( _mm512_maskz_set1_epi16( 0XAAAA, value.imag() ) );
175  dst = _mm512_maskz_set1_epi16( 0x5555, value.real() );
176  return dst;
177 #elif BLAZE_AVX2_MODE
178  return _mm256_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
179  value.imag(), value.real(), value.imag(), value.real(),
180  value.imag(), value.real(), value.imag(), value.real(),
181  value.imag(), value.real(), value.imag(), value.real() );
182 #elif BLAZE_SSE2_MODE
183  return _mm_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
184  value.imag(), value.real(), value.imag(), value.real() );
185 #else
186  return value;
187 #endif
188  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
189 }
190 //*************************************************************************************************
191 
192 
193 
194 
195 //=================================================================================================
196 //
197 // 32-BIT INTEGRAL SIMD TYPES
198 //
199 //=================================================================================================
200 
201 //*************************************************************************************************
208 template< typename T > // Type of the integral value
209 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,4UL>
210  , If_t< IsSigned_v<T>, SIMDint32, SIMDuint32 > >
211  set( T value ) noexcept
212 {
213 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
214  return _mm512_set1_epi32( value );
215 #elif BLAZE_AVX2_MODE
216  return _mm256_set1_epi32( value );
217 #elif BLAZE_SSE2_MODE
218  return _mm_set1_epi32( value );
219 #else
220  return value;
221 #endif
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
233 template< typename T > // Type of the integral value
234 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,4UL>
235  , If_t< IsSigned_v<T>, SIMDcint32, SIMDcuint32 > >
236  set( complex<T> value ) noexcept
237 {
238 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
239  return _mm512_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
240  value.imag(), value.real(), value.imag(), value.real(),
241  value.imag(), value.real(), value.imag(), value.real(),
242  value.imag(), value.real(), value.imag(), value.real() );
243 #elif BLAZE_AVX2_MODE
244  return _mm256_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
245  value.imag(), value.real(), value.imag(), value.real() );
246 #elif BLAZE_SSE2_MODE
247  return _mm_set_epi32( value.imag(), value.real(), value.imag(), value.real() );
248 #else
249  return value;
250 #endif
251  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
252 }
253 //*************************************************************************************************
254 
255 
256 
257 
258 //=================================================================================================
259 //
260 // 64-BIT INTEGRAL SIMD TYPES
261 //
262 //=================================================================================================
263 
264 //*************************************************************************************************
271 template< typename T > // Type of the integral value
272 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,8UL>
273  , If_t< IsSigned_v<T>, SIMDint64, SIMDuint64 > >
274  set( T value ) noexcept
275 {
276 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
277  return _mm512_set1_epi64( value );
278 #elif BLAZE_AVX2_MODE
279  return _mm256_set1_epi64x( value );
280 #elif BLAZE_SSE2_MODE
281  return _mm_set1_epi64( value );
282 #else
283  return value;
284 #endif
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
296 template< typename T > // Type of the integral value
297 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,8UL>
298  , If_t< IsSigned_v<T>, SIMDcint64, SIMDcuint64 > >
299  set( complex<T> value ) noexcept
300 {
301 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
302  return _mm512_set_epi64( value.imag(), value.real(), value.imag(), value.real(),
303  value.imag(), value.real(), value.imag(), value.real() );
304 #elif BLAZE_AVX2_MODE
305  return _mm256_set_epi64x( value.imag(), value.real(), value.imag(), value.real() );
306 #elif BLAZE_SSE2_MODE
307  return _mm_set_epi64( value.imag(), value.real() );
308 #else
309  return value;
310 #endif
311  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
312 }
313 //*************************************************************************************************
314 
315 
316 
317 
318 //=================================================================================================
319 //
320 // 32-BIT FLOATING POINT SIMD TYPES
321 //
322 //=================================================================================================
323 
324 //*************************************************************************************************
331 BLAZE_ALWAYS_INLINE const SIMDfloat set( float value ) noexcept
332 {
333 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
334  return _mm512_set1_ps( value );
335 #elif BLAZE_AVX_MODE
336  return _mm256_set1_ps( value );
337 #elif BLAZE_SSE_MODE
338  return _mm_set1_ps( value );
339 #else
340  return value;
341 #endif
342 }
343 //*************************************************************************************************
344 
345 
346 //*************************************************************************************************
353 BLAZE_ALWAYS_INLINE const SIMDcfloat set( const complex<float>& value ) noexcept
354 {
355 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
356  return _mm512_set_ps( value.imag(), value.real(), value.imag(), value.real(),
357  value.imag(), value.real(), value.imag(), value.real(),
358  value.imag(), value.real(), value.imag(), value.real(),
359  value.imag(), value.real(), value.imag(), value.real() );
360 #elif BLAZE_AVX_MODE
361  return _mm256_set_ps( value.imag(), value.real(), value.imag(), value.real(),
362  value.imag(), value.real(), value.imag(), value.real() );
363 #elif BLAZE_SSE_MODE
364  return _mm_set_ps( value.imag(), value.real(), value.imag(), value.real() );
365 #else
366  return value;
367 #endif
368  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
369 }
370 //*************************************************************************************************
371 
372 
373 
374 
375 //=================================================================================================
376 //
377 // 64-BIT FLOATING POINT SIMD TYPES
378 //
379 //=================================================================================================
380 
381 //*************************************************************************************************
388 BLAZE_ALWAYS_INLINE const SIMDdouble set( double value ) noexcept
389 {
390 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
391  return _mm512_set1_pd( value );
392 #elif BLAZE_AVX_MODE
393  return _mm256_set1_pd( value );
394 #elif BLAZE_SSE2_MODE
395  return _mm_set1_pd( value );
396 #else
397  return value;
398 #endif
399 }
400 //*************************************************************************************************
401 
402 
403 //*************************************************************************************************
410 BLAZE_ALWAYS_INLINE const SIMDcdouble set( const complex<double>& value ) noexcept
411 {
412 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
413  return _mm512_set_pd( value.imag(), value.real(), value.imag(), value.real(),
414  value.imag(), value.real(), value.imag(), value.real() );
415 #elif BLAZE_AVX_MODE
416  return _mm256_set_pd( value.imag(), value.real(), value.imag(), value.real() );
417 #elif BLAZE_SSE2_MODE
418  return _mm_set_pd( value.imag(), value.real() );
419 #else
420  return value;
421 #endif
422  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
423 }
424 //*************************************************************************************************
425 
426 } // namespace blaze
427 
428 #endif
Header file for basic type definitions.
Header file for the IsIntegral type trait.
SIMD type for 64-bit double precision floating point data values.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#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.
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.