All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Set.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_INTRINSICS_SET_H_
23 #define _BLAZE_MATH_INTRINSICS_SET_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 Set;
59 //*************************************************************************************************
60 
61 
62 
63 
64 //=================================================================================================
65 //
66 // SPECIALIZATIONS OF THE SET CLASS TEMPLATE
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
75 template< typename T > // Type of the integral
76 struct Set<T,2UL>
77 {
78  public:
79  //**Type definitions****************************************************************************
80  typedef sse_int16_t Type;
81  //**********************************************************************************************
82 
83  //**Set function********************************************************************************
84  static inline Type set( T value )
85  {
86 #if BLAZE_AVX2_MODE
87  return _mm256_set1_epi16( value );
88 #elif BLAZE_SSE2_MODE
89  return _mm_set1_epi16( value );
90 #else
91  return value;
92 #endif
93  }
94  //**********************************************************************************************
95 
96  private:
97  //**Compile time checks*************************************************************************
99  //**********************************************************************************************
100 };
102 //*************************************************************************************************
103 
104 
105 //*************************************************************************************************
110 template< typename T > // Type of the integral
111 struct Set<T,4UL>
112 {
113  public:
114  //**Type definitions****************************************************************************
115  typedef sse_int32_t Type;
116  //**********************************************************************************************
117 
118  //**Set function********************************************************************************
119  static inline Type set( T value )
120  {
121 #if BLAZE_MIC_MODE
122  return _mm512_set1_epi32( value );
123 #elif BLAZE_AVX2_MODE
124  return _mm256_set1_epi32( value );
125 #elif BLAZE_SSE2_MODE
126  return _mm_set1_epi32( value );
127 #else
128  return value;
129 #endif
130  }
131  //**********************************************************************************************
132 
133  private:
134  //**Compile time checks*************************************************************************
136  //**********************************************************************************************
137 };
139 //*************************************************************************************************
140 
141 
142 //*************************************************************************************************
147 template< typename T > // Type of the integral
148 struct Set<T,8UL>
149 {
150  public:
151  //**Type definitions****************************************************************************
152  typedef sse_int64_t Type;
153  //**********************************************************************************************
154 
155  //**Set function********************************************************************************
156  static inline Type set( T value )
157  {
158 #if BLAZE_MIC_MODE
159  return _mm512_set1_epi64( value );
160 #elif BLAZE_AVX2_MODE
161  return _mm256_set1_epi64x( value );
162 #elif BLAZE_SSE2_MODE
163  return _mm_set1_epi64( value );
164 #else
165  return value;
166 #endif
167  }
168  //**********************************************************************************************
169 
170  private:
171  //**Compile time checks*************************************************************************
173  //**********************************************************************************************
174 };
176 //*************************************************************************************************
177 
178 
179 
180 
181 //=================================================================================================
182 //
183 // INTRINSIC SET FUNCTIONS
184 //
185 //=================================================================================================
186 
187 //*************************************************************************************************
194 template< typename T > // Type of the integral value
195 inline typename EnableIf< IsIntegral<T>, Set<T,sizeof(T)> >::Type::Type
196  set( T value )
197 {
198  return Set<T,sizeof(T)>::set( value );
199 }
200 //*************************************************************************************************
201 
202 
203 //*************************************************************************************************
210 inline sse_float_t set( float value )
211 {
212 #if BLAZE_MIC_MODE
213  return _mm512_set1_ps( value );
214 #elif BLAZE_AVX_MODE
215  return _mm256_set1_ps( value );
216 #elif BLAZE_SSE_MODE
217  return _mm_set1_ps( value );
218 #else
219  return value;
220 #endif
221 }
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
232 inline sse_double_t set( double value )
233 {
234 #if BLAZE_MIC_MODE
235  return _mm512_set1_pd( value );
236 #elif BLAZE_AVX_MODE
237  return _mm256_set1_pd( value );
238 #elif BLAZE_SSE2_MODE
239  return _mm_set1_pd( value );
240 #else
241  return value;
242 #endif
243 }
244 //*************************************************************************************************
245 
246 
247 //*************************************************************************************************
254 inline sse_cfloat_t set( const complex<float>& value )
255 {
256 #if BLAZE_AVX_MODE
257  return _mm256_set_ps( value.imag(), value.real(), value.imag(), value.real(),
258  value.imag(), value.real(), value.imag(), value.real() );
259 #elif BLAZE_SSE_MODE
260  return _mm_set_ps( value.imag(), value.real(), value.imag(), value.real() );
261 #else
262  return value;
263 #endif
264  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
265 }
266 //*************************************************************************************************
267 
268 
269 //*************************************************************************************************
276 inline sse_cdouble_t set( const complex<double>& value )
277 {
278 #if BLAZE_AVX_MODE
279  return _mm256_set_pd( value.imag(), value.real(), value.imag(), value.real() );
280 #elif BLAZE_SSE2_MODE
281  return _mm_set_pd( value.imag(), value.real() );
282 #else
283  return value;
284 #endif
285  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
286 }
287 //*************************************************************************************************
288 
289 } // namespace blaze
290 
291 #endif