Blaze  3.6
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_AVX512F_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_AVX512F_MODE
103  return _mm512_set1_epi16( reinterpret_cast<const int16_t&>( value ) );
104 #elif BLAZE_AVX2_MODE
105  return _mm256_set_epi8( 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  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 #elif BLAZE_SSE2_MODE
114  return _mm_set_epi8( value.imag(), value.real(), value.imag(), value.real(),
115  value.imag(), value.real(), value.imag(), value.real(),
116  value.imag(), value.real(), value.imag(), value.real(),
117  value.imag(), value.real(), value.imag(), value.real() );
118 #else
119  return value;
120 #endif
121  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
122 }
123 //*************************************************************************************************
124 
125 
126 
127 
128 //=================================================================================================
129 //
130 // 16-BIT INTEGRAL SIMD TYPES
131 //
132 //=================================================================================================
133 
134 //*************************************************************************************************
141 template< typename T > // Type of the integral value
142 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,2UL>
143  , If_t< IsSigned_v<T>, SIMDint16, SIMDuint16 > >
144  set( T value ) noexcept
145 {
146 #if BLAZE_AVX512F_MODE
147  return _mm512_set1_epi16( value );
148 #elif BLAZE_AVX2_MODE
149  return _mm256_set1_epi16( value );
150 #elif BLAZE_SSE2_MODE
151  return _mm_set1_epi16( value );
152 #else
153  return value;
154 #endif
155 }
156 //*************************************************************************************************
157 
158 
159 //*************************************************************************************************
166 template< typename T > // Type of the integral value
167 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,2UL>
168  , If_t< IsSigned_v<T>, SIMDcint16, SIMDcuint16 > >
169  set( complex<T> value ) noexcept
170 {
171 #if BLAZE_AVX512F_MODE
172  return _mm512_set1_epi32( reinterpret_cast<const int32_t&>( value ) );
173 #elif BLAZE_AVX2_MODE
174  return _mm256_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
175  value.imag(), value.real(), value.imag(), value.real(),
176  value.imag(), value.real(), value.imag(), value.real(),
177  value.imag(), value.real(), value.imag(), value.real() );
178 #elif BLAZE_SSE2_MODE
179  return _mm_set_epi16( value.imag(), value.real(), value.imag(), value.real(),
180  value.imag(), value.real(), value.imag(), value.real() );
181 #else
182  return value;
183 #endif
184  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
185 }
186 //*************************************************************************************************
187 
188 
189 
190 
191 //=================================================================================================
192 //
193 // 32-BIT INTEGRAL SIMD TYPES
194 //
195 //=================================================================================================
196 
197 //*************************************************************************************************
204 template< typename T > // Type of the integral value
205 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,4UL>
206  , If_t< IsSigned_v<T>, SIMDint32, SIMDuint32 > >
207  set( T value ) noexcept
208 {
209 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
210  return _mm512_set1_epi32( value );
211 #elif BLAZE_AVX2_MODE
212  return _mm256_set1_epi32( value );
213 #elif BLAZE_SSE2_MODE
214  return _mm_set1_epi32( value );
215 #else
216  return value;
217 #endif
218 }
219 //*************************************************************************************************
220 
221 
222 //*************************************************************************************************
229 template< typename T > // Type of the integral value
230 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,4UL>
231  , If_t< IsSigned_v<T>, SIMDcint32, SIMDcuint32 > >
232  set( complex<T> value ) noexcept
233 {
234 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
235  return _mm512_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
236  value.imag(), value.real(), value.imag(), value.real(),
237  value.imag(), value.real(), value.imag(), value.real(),
238  value.imag(), value.real(), value.imag(), value.real() );
239 #elif BLAZE_AVX2_MODE
240  return _mm256_set_epi32( value.imag(), value.real(), value.imag(), value.real(),
241  value.imag(), value.real(), value.imag(), value.real() );
242 #elif BLAZE_SSE2_MODE
243  return _mm_set_epi32( value.imag(), value.real(), value.imag(), value.real() );
244 #else
245  return value;
246 #endif
247  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
248 }
249 //*************************************************************************************************
250 
251 
252 
253 
254 //=================================================================================================
255 //
256 // 64-BIT INTEGRAL SIMD TYPES
257 //
258 //=================================================================================================
259 
260 //*************************************************************************************************
267 template< typename T > // Type of the integral value
268 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,8UL>
269  , If_t< IsSigned_v<T>, SIMDint64, SIMDuint64 > >
270  set( T value ) noexcept
271 {
272 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
273  return _mm512_set1_epi64( value );
274 #elif BLAZE_AVX2_MODE
275  return _mm256_set1_epi64x( value );
276 #elif BLAZE_SSE2_MODE
277  return _mm_set1_epi64x( value );
278 #else
279  return value;
280 #endif
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
292 template< typename T > // Type of the integral value
293 BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v<T> && HasSize_v<T,8UL>
294  , If_t< IsSigned_v<T>, SIMDcint64, SIMDcuint64 > >
295  set( complex<T> value ) noexcept
296 {
297 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
298  return _mm512_set_epi64( value.imag(), value.real(), value.imag(), value.real(),
299  value.imag(), value.real(), value.imag(), value.real() );
300 #elif BLAZE_AVX2_MODE
301  return _mm256_set_epi64x( value.imag(), value.real(), value.imag(), value.real() );
302 #elif BLAZE_SSE2_MODE
303  return _mm_set_epi64x( value.imag(), value.real() );
304 #else
305  return value;
306 #endif
307  BLAZE_STATIC_ASSERT( sizeof( complex<T> ) == 2UL*sizeof( T ) );
308 }
309 //*************************************************************************************************
310 
311 
312 
313 
314 //=================================================================================================
315 //
316 // 32-BIT FLOATING POINT SIMD TYPES
317 //
318 //=================================================================================================
319 
320 //*************************************************************************************************
327 BLAZE_ALWAYS_INLINE const SIMDfloat set( float value ) noexcept
328 {
329 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
330  return _mm512_set1_ps( value );
331 #elif BLAZE_AVX_MODE
332  return _mm256_set1_ps( value );
333 #elif BLAZE_SSE_MODE
334  return _mm_set1_ps( value );
335 #else
336  return value;
337 #endif
338 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
349 BLAZE_ALWAYS_INLINE const SIMDcfloat set( const complex<float>& value ) noexcept
350 {
351 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
352  return _mm512_set_ps( value.imag(), value.real(), value.imag(), value.real(),
353  value.imag(), value.real(), value.imag(), value.real(),
354  value.imag(), value.real(), value.imag(), value.real(),
355  value.imag(), value.real(), value.imag(), value.real() );
356 #elif BLAZE_AVX_MODE
357  return _mm256_set_ps( value.imag(), value.real(), value.imag(), value.real(),
358  value.imag(), value.real(), value.imag(), value.real() );
359 #elif BLAZE_SSE_MODE
360  return _mm_set_ps( value.imag(), value.real(), value.imag(), value.real() );
361 #else
362  return value;
363 #endif
364  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
365 }
366 //*************************************************************************************************
367 
368 
369 
370 
371 //=================================================================================================
372 //
373 // 64-BIT FLOATING POINT SIMD TYPES
374 //
375 //=================================================================================================
376 
377 //*************************************************************************************************
384 BLAZE_ALWAYS_INLINE const SIMDdouble set( double value ) noexcept
385 {
386 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
387  return _mm512_set1_pd( value );
388 #elif BLAZE_AVX_MODE
389  return _mm256_set1_pd( value );
390 #elif BLAZE_SSE2_MODE
391  return _mm_set1_pd( value );
392 #else
393  return value;
394 #endif
395 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
406 BLAZE_ALWAYS_INLINE const SIMDcdouble set( const complex<double>& value ) noexcept
407 {
408 #if BLAZE_AVX512F_MODE || BLAZE_MIC_MODE
409  return _mm512_set_pd( value.imag(), value.real(), value.imag(), value.real(),
410  value.imag(), value.real(), value.imag(), value.real() );
411 #elif BLAZE_AVX_MODE
412  return _mm256_set_pd( value.imag(), value.real(), value.imag(), value.real() );
413 #elif BLAZE_SSE2_MODE
414  return _mm_set_pd( value.imag(), value.real() );
415 #else
416  return value;
417 #endif
418  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
419 }
420 //*************************************************************************************************
421 
422 } // namespace blaze
423 
424 #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.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
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.