All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Reduction.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_INTRINSICS_REDUCTION_H_
36 #define _BLAZE_MATH_INTRINSICS_REDUCTION_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // INTRINSIC SUM OPERATION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
62 inline int16_t sum( const sse_int16_t& a )
63 {
64 #if BLAZE_AVX2_MODE
65  const sse_int16_t b( _mm256_hadd_epi16( a.value, a.value ) );
66  const sse_int16_t c( _mm256_hadd_epi16( b.value, b.value ) );
67  const sse_int16_t d( _mm256_hadd_epi16( c.value, c.value ) );
68  const sse_int16_t e( _mm256_hadd_epi16( d.value, d.value ) );
69  return e[0];
70 #elif BLAZE_SSSE3_MODE
71  const sse_int16_t b( _mm_hadd_epi16( a.value, a.value ) );
72  const sse_int16_t c( _mm_hadd_epi16( b.value, b.value ) );
73  const sse_int16_t d( _mm_hadd_epi16( c.value, c.value ) );
74  return d[0];
75 #elif BLAZE_SSE2_MODE
76  return a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7];
77 #else
78  return a.value;
79 #endif
80 }
81 //*************************************************************************************************
82 
83 
84 //*************************************************************************************************
91 inline int32_t sum( const sse_int32_t& a )
92 {
93 #if BLAZE_MIC_MODE
94  return _mm512_reduce_add_epi32( a.value );
95 #elif BLAZE_AVX2_MODE
96  const sse_int32_t b( _mm256_hadd_epi32( a.value, a.value ) );
97  const sse_int32_t c( _mm256_hadd_epi32( b.value, b.value ) );
98  const sse_int32_t d( _mm256_hadd_epi32( c.value, c.value ) );
99  return d[0];
100 #elif BLAZE_SSSE3_MODE
101  const sse_int32_t b( _mm_hadd_epi32( a.value, a.value ) );
102  const sse_int32_t c( _mm_hadd_epi32( b.value, b.value ) );
103  return c[0];
104 #elif BLAZE_SSE2_MODE
105  return a[0] + a[1] + a[2] + a[3];
106 #else
107  return a.value;
108 #endif
109 }
110 //*************************************************************************************************
111 
112 
113 //*************************************************************************************************
120 inline int64_t sum( const sse_int64_t& a )
121 {
122 #if BLAZE_MIC_MODE
123  return _mm512_reduce_add_epi64( a.value );
124 #elif BLAZE_AVX2_MODE
125  return a[0] + a[1] + a[2] + a[3];
126 #elif BLAZE_SSE2_MODE
127  return a[0] + a[1];
128 #else
129  return a.value;
130 #endif
131 }
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
142 inline float sum( const sse_float_t& a )
143 {
144 #if BLAZE_MIC_MODE
145  return _mm512_reduce_add_ps( a.value );
146 #elif BLAZE_AVX_MODE
147  const sse_float_t b( _mm256_hadd_ps( a.value, a.value ) );
148  const sse_float_t c( _mm256_hadd_ps( b.value, b.value ) );
149  const __m128 d = _mm_add_ps( _mm256_extractf128_ps( c.value, 1 )
150  , _mm256_castps256_ps128( c.value ) );
151  return *reinterpret_cast<const float*>( &d );
152 #elif BLAZE_SSE3_MODE
153  const sse_float_t b( _mm_hadd_ps( a.value, a.value ) );
154  const sse_float_t c( _mm_hadd_ps( b.value, b.value ) );
155  return c[0];
156 #elif BLAZE_SSE_MODE
157  return a[0] + a[1] + a[2] + a[3];
158 #else
159  return a.value;
160 #endif
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
172 inline double sum( const sse_double_t& a )
173 {
174 #if BLAZE_MIC_MODE
175  return _mm512_reduce_add_pd( a.value );
176 #elif BLAZE_AVX_MODE
177  const sse_double_t b( _mm256_hadd_pd( a.value, a.value ) );
178  const __m128d c = _mm_add_pd( _mm256_extractf128_pd( b.value, 1 )
179  , _mm256_castpd256_pd128( b.value ) );
180  return *reinterpret_cast<const double*>( &c );
181 #elif BLAZE_SSE3_MODE
182  const sse_double_t b( _mm_hadd_pd( a.value, a.value ) );
183  return b[0];
184 #elif BLAZE_SSE2_MODE
185  return a[0] + a[1];
186 #else
187  return a.value;
188 #endif
189 }
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
200 inline complex<float> sum( const sse_cfloat_t& a )
201 {
202 #if BLAZE_MIC_MODE
203  return complex<float>( a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] );
204 #elif BLAZE_AVX_MODE
205  return complex<float>( a[0] + a[1] + a[2] + a[3] );
206 #elif BLAZE_SSE_MODE
207  return complex<float>( a[0] + a[1] );
208 #else
209  return a.value;
210 #endif
211 }
212 //*************************************************************************************************
213 
214 
215 //*************************************************************************************************
222 inline complex<double> sum( const sse_cdouble_t& a )
223 {
224 #if BLAZE_MIC_MODE
225  return complex<double>( a[0] + a[1] + a[2] + a[3] );
226 #elif BLAZE_AVX_MODE
227  return complex<double>( a[0] + a[1] );
228 #elif BLAZE_SSE2_MODE
229  return a[0];
230 #else
231  return a.value;
232 #endif
233 }
234 //*************************************************************************************************
235 
236 } // namespace blaze
237 
238 #endif
Intrinsic type for 32-bit single precision complex values.
int16_t sum(const sse_int16_t &a)
Returns the sum of all elements in the 16-bit integral intrinsic vector.
Definition: Reduction.h:62
16-bit signed integer type of the Blaze library.
Intrinsic type for 64-bit integral data values.
Intrinsic type for 16-bit integral data values.
Intrinsic type for 32-bit single precision floating point data values.
Intrinsic type for 64-bit double precision complex values.
Intrinsic type for 64-bit double precision floating point data values.
Header file for the basic intrinsic types.
System settings for the SSE mode.
64-bit signed integer type of the Blaze library.
Intrinsic type for 32-bit integral data values.
32-bit signed integer type of the Blaze library.