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_AVX512BW_MODE
79  return _mm512_set1_epi8( value );
80 #elif BLAZE_AVX2_MODE
81  return _mm256_set1_epi8( value );
82 #elif BLAZE_SSE2_MODE
83  return _mm_set1_epi8( value );
84 #else
85  return value;
86 #endif
87 }
88 //*************************************************************************************************
89 
90 
91 //*************************************************************************************************
98 template< typename T > // Type of the integral value
99 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,1UL> >
100  , If_< IsSigned<T>, SIMDcint8, SIMDcuint8 > >
101  set( complex<T> value ) noexcept
102 {
103 #if BLAZE_AVX512BW_MODE
104  __m512i dst( _mm512_maskz_set1_epi8( 0XAAAAAAAA, value.imag() ) );
105  dst = _mm512_maskz_set1_epi8( 0x55555555, value.real() );
106  return dst;
107 #elif BLAZE_AVX2_MODE
108  return _mm256_set_epi8( 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  value.imag(), value.real(), value.imag(), value.real() );
116 #elif BLAZE_SSE2_MODE
117  return _mm_set_epi8( 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  value.imag(), value.real(), value.imag(), value.real() );
121 #else
122  return value;
123 #endif
124  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
125 }
126 //*************************************************************************************************
127 
128 
129 
130 
131 //=================================================================================================
132 //
133 // 16-BIT INTEGRAL SIMD TYPES
134 //
135 //=================================================================================================
136 
137 //*************************************************************************************************
144 template< typename T > // Type of the integral value
145 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
146  , If_< IsSigned<T>, SIMDint16, SIMDuint16 > >
147  set( T value ) noexcept
148 {
149 #if BLAZE_AVX512BW_MODE
150  return _mm512_set1_epi16( value );
151 #elif BLAZE_AVX2_MODE
152  return _mm256_set1_epi16( value );
153 #elif BLAZE_SSE2_MODE
154  return _mm_set1_epi16( value );
155 #else
156  return value;
157 #endif
158 }
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
169 template< typename T > // Type of the integral value
170 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,2UL> >
171  , If_< IsSigned<T>, SIMDcint16, SIMDcuint16 > >
172  set( complex<T> value ) noexcept
173 {
174 #if BLAZE_AVX512BW_MODE
175  __m512i dst( _mm512_maskz_set1_epi16( 0XAAAA, value.imag() ) );
176  dst = _mm512_maskz_set1_epi16( 0x5555, value.real() );
177  return dst;
178 #elif BLAZE_AVX2_MODE
179  return _mm256_set_epi16( 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  value.imag(), value.real(), value.imag(), value.real() );
183 #elif BLAZE_SSE2_MODE
184  return _mm_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
185  value.imag(), value.real(), value.imag(), value.real() );
186 #else
187  return value;
188 #endif
189  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
190 }
191 //*************************************************************************************************
192 
193 
194 
195 
196 //=================================================================================================
197 //
198 // 32-BIT INTEGRAL SIMD TYPES
199 //
200 //=================================================================================================
201 
202 //*************************************************************************************************
209 template< typename T > // Type of the integral value
210 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
211  , If_< IsSigned<T>, SIMDint32, SIMDuint32 > >
212  set( T value ) noexcept
213 {
214 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
215  return _mm512_set1_epi32( value );
216 #elif BLAZE_AVX2_MODE
217  return _mm256_set1_epi32( value );
218 #elif BLAZE_SSE2_MODE
219  return _mm_set1_epi32( value );
220 #else
221  return value;
222 #endif
223 }
224 //*************************************************************************************************
225 
226 
227 //*************************************************************************************************
234 template< typename T > // Type of the integral value
235 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,4UL> >
236  , If_< IsSigned<T>, SIMDcint32, SIMDcuint32 > >
237  set( complex<T> value ) noexcept
238 {
239 #if BLAZE_AVX512F_MODE
240  __m512i dst( _mm512_maskz_set1_epi32( 0xAA, value.imag() ) );
241  dst = _mm512_maskz_set1_epi32( 0x55, value.real() );
242  return dst;
243 #elif BLAZE_MIC_MODE
244  return _mm512_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
245  value.imag(), value.real(), value.imag(), value.real(),
246  value.imag(), value.real(), value.imag(), value.real(),
247  value.imag(), value.real(), value.imag(), value.real() );
248 #elif BLAZE_AVX2_MODE
249  return _mm256_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
250  value.imag(), value.real(), value.imag(), value.real() );
251 #elif BLAZE_SSE2_MODE
252  return _mm_set_epi32( value.imag(), value.real(), value.imag(), value.real() );
253 #else
254  return value;
255 #endif
256  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
257 }
258 //*************************************************************************************************
259 
260 
261 
262 
263 //=================================================================================================
264 //
265 // 64-BIT INTEGRAL SIMD TYPES
266 //
267 //=================================================================================================
268 
269 //*************************************************************************************************
276 template< typename T > // Type of the integral value
277 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
278  , If_< IsSigned<T>, SIMDint64, SIMDuint64 > >
279  set( T value ) noexcept
280 {
281 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
282  return _mm512_set1_epi64( value );
283 #elif BLAZE_AVX2_MODE
284  return _mm256_set1_epi64x( value );
285 #elif BLAZE_SSE2_MODE
286  return _mm_set1_epi64( value );
287 #else
288  return value;
289 #endif
290 }
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
301 template< typename T > // Type of the integral value
302 BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral<T>, HasSize<T,8UL> >
303  , If_< IsSigned<T>, SIMDcint64, SIMDcuint64 > >
304  set( complex<T> value ) noexcept
305 {
306 #if BLAZE_AVX512F_MODE
307  __m512i dst( _mm512_maskz_set1_epi64( 0xA, value.imag() ) );
308  dst = _mm512_maskz_set1_epi32( 0x5, value.real() );
309  return dst;
310 #elif BLAZE_MIC_MODE
311  return _mm512_set_epi64( value.imag(), value.real(), value.imag(), value.real(),
312  value.imag(), value.real(), value.imag(), value.real() );
313 #elif BLAZE_AVX2_MODE
314  return _mm256_set_epi64( value.imag(), value.real(), value.imag(), value.real() );
315 #elif BLAZE_SSE2_MODE
316  return _mm_set_epi64( value.imag(), value.real() );
317 #else
318  return value;
319 #endif
320  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
321 }
322 //*************************************************************************************************
323 
324 
325 
326 
327 //=================================================================================================
328 //
329 // 32-BIT FLOATING POINT SIMD TYPES
330 //
331 //=================================================================================================
332 
333 //*************************************************************************************************
340 BLAZE_ALWAYS_INLINE const SIMDfloat set( float value ) noexcept
341 {
342 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
343  return _mm512_set1_ps( value );
344 #elif BLAZE_AVX_MODE
345  return _mm256_set1_ps( value );
346 #elif BLAZE_SSE_MODE
347  return _mm_set1_ps( value );
348 #else
349  return value;
350 #endif
351 }
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
362 BLAZE_ALWAYS_INLINE const SIMDcfloat set( const complex<float>& value ) noexcept
363 {
364 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
365  return _mm512_set_ps( value.imag(), value.real(), value.imag(), value.real(),
366  value.imag(), value.real(), value.imag(), value.real(),
367  value.imag(), value.real(), value.imag(), value.real(),
368  value.imag(), value.real(), value.imag(), value.real() );
369 #elif BLAZE_AVX_MODE
370  return _mm256_set_ps( value.imag(), value.real(), value.imag(), value.real(),
371  value.imag(), value.real(), value.imag(), value.real() );
372 #elif BLAZE_SSE_MODE
373  return _mm_set_ps( value.imag(), value.real(), value.imag(), value.real() );
374 #else
375  return value;
376 #endif
377  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
378 }
379 //*************************************************************************************************
380 
381 
382 
383 
384 //=================================================================================================
385 //
386 // 64-BIT FLOATING POINT SIMD TYPES
387 //
388 //=================================================================================================
389 
390 //*************************************************************************************************
397 BLAZE_ALWAYS_INLINE const SIMDdouble set( double value ) noexcept
398 {
399 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
400  return _mm512_set1_pd( value );
401 #elif BLAZE_AVX_MODE
402  return _mm256_set1_pd( value );
403 #elif BLAZE_SSE2_MODE
404  return _mm_set1_pd( value );
405 #else
406  return value;
407 #endif
408 }
409 //*************************************************************************************************
410 
411 
412 //*************************************************************************************************
419 BLAZE_ALWAYS_INLINE const SIMDcdouble set( const complex<double>& value ) noexcept
420 {
421 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
422  return _mm512_set_pd( value.imag(), value.real(), value.imag(), value.real(),
423  value.imag(), value.real(), value.imag(), value.real() );
424 #elif BLAZE_AVX_MODE
425  return _mm256_set_pd( value.imag(), value.real(), value.imag(), value.real() );
426 #elif BLAZE_SSE2_MODE
427  return _mm_set_pd( value.imag(), value.real() );
428 #else
429  return value;
430 #endif
431  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
432 }
433 //*************************************************************************************************
434 
435 } // namespace blaze
436 
437 #endif
SIMD type for 16-bit signed integral data values.
SIMD type for 32-bit unsigned integral complex values.
Header file for basic type definitions.
SIMD type for 16-bit unsigned integral complex values.
SIMD type for 32-bit signed integral complex values.
Header file for the IsIntegral type trait.
Header file for the And class template.
SIMD type for 32-bit unsigned integral data values.
SIMD type for 64-bit double precision floating point data values.
SIMD type for 64-bit unsigned integral complex values.
SIMD type for 16-bit signed integral complex 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.
SIMD type for 16-bit unsigned integral data values.
SIMD type for 32-bit signed integral data values.
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.
SIMD type for 8-bit signed integral complex values.
Header file for the HasSize type trait.
SIMD type for 32-bit single precision complex values.
SIMD type for 64-bit signed integral 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 unsigned integral data values.
SIMD type for 64-bit integral data values.
SIMD type for 8-bit unsigned integral complex 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.