All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Reduction.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_INTRINSICS_REDUCTION_H_
23 #define _BLAZE_MATH_INTRINSICS_REDUCTION_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // INTRINSIC SUM OPERATION
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
49 inline int16_t sum( const sse_int16_t& a )
50 {
51 #if BLAZE_AVX2_MODE
52  const sse_int16_t b( _mm256_hadd_epi16( a.value, a.value ) );
53  const sse_int16_t c( _mm256_hadd_epi16( b.value, b.value ) );
54  const sse_int16_t d( _mm256_hadd_epi16( c.value, c.value ) );
55  const sse_int16_t e( _mm256_hadd_epi16( d.value, d.value ) );
56  return e[0];
57 #elif BLAZE_SSSE3_MODE
58  const sse_int16_t b( _mm_hadd_epi16( a.value, a.value ) );
59  const sse_int16_t c( _mm_hadd_epi16( b.value, b.value ) );
60  const sse_int16_t d( _mm_hadd_epi16( c.value, c.value ) );
61  return d[0];
62 #elif BLAZE_SSE2_MODE
63  return a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7];
64 #else
65  return a.value;
66 #endif
67 }
68 //*************************************************************************************************
69 
70 
71 //*************************************************************************************************
78 inline int32_t sum( const sse_int32_t& a )
79 {
80 #if BLAZE_MIC_MODE
81  return _mm512_reduce_add_epi32( a.value );
82 #elif BLAZE_AVX2_MODE
83  const sse_int32_t b( _mm256_hadd_epi32( a.value, a.value ) );
84  const sse_int32_t c( _mm256_hadd_epi32( b.value, b.value ) );
85  const sse_int32_t d( _mm256_hadd_epi32( c.value, c.value ) );
86  return d[0];
87 #elif BLAZE_SSSE3_MODE
88  const sse_int32_t b( _mm_hadd_epi32( a.value, a.value ) );
89  const sse_int32_t c( _mm_hadd_epi32( b.value, b.value ) );
90  return c[0];
91 #elif BLAZE_SSE2_MODE
92  return a[0] + a[1] + a[2] + a[3];
93 #else
94  return a.value;
95 #endif
96 }
97 //*************************************************************************************************
98 
99 
100 //*************************************************************************************************
107 inline float sum( const sse_float_t& a )
108 {
109 #if BLAZE_MIC_MODE
110  return _mm512_reduce_add_ps( a.value );
111 #elif BLAZE_AVX_MODE
112  const sse_float_t b( _mm256_hadd_ps( a.value, a.value ) );
113  const sse_float_t c( _mm256_hadd_ps( b.value, b.value ) );
114  const sse_float_t d( _mm256_hadd_ps( c.value, c.value ) );
115  return d[0];
116 #elif BLAZE_SSE3_MODE
117  const sse_float_t b( _mm_hadd_ps( a.value, a.value ) );
118  const sse_float_t c( _mm_hadd_ps( b.value, b.value ) );
119  return c[0];
120 #elif BLAZE_SSE_MODE
121  return a[0] + a[1] + a[2] + a[3];
122 #else
123  return a.value;
124 #endif
125 }
126 //*************************************************************************************************
127 
128 
129 //*************************************************************************************************
136 inline double sum( const sse_double_t& a )
137 {
138 #if BLAZE_MIC_MODE
139  return _mm512_reduce_add_pd( a.value );
140 #elif BLAZE_AVX_MODE
141  const sse_double_t b( _mm256_hadd_pd( a.value, a.value ) );
142  const sse_double_t c( _mm256_hadd_pd( b.value, b.value ) );
143  return c[0];
144 #elif BLAZE_SSE3_MODE
145  const sse_double_t b( _mm_hadd_pd( a.value, a.value ) );
146  return b[0];
147 #elif BLAZE_SSE2_MODE
148  return a[0] + a[1];
149 #else
150  return a.value;
151 #endif
152 }
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
163 inline complex<float> sum( const sse_cfloat_t& a )
164 {
165 #if BLAZE_AVX_MODE
166  return complex<float>( a[0] + a[1] + a[2] + a[3] );
167 #elif BLAZE_SSE_MODE
168  return complex<float>( a[0] + a[1] );
169 #else
170  return a.value;
171 #endif
172 }
173 //*************************************************************************************************
174 
175 
176 //*************************************************************************************************
183 inline complex<double> sum( const sse_cdouble_t& a )
184 {
185 #if BLAZE_AVX_MODE
186  return complex<double>( a[0] + a[1] );
187 #elif BLAZE_SSE2_MODE
188  return a[0];
189 #else
190  return a.value;
191 #endif
192 }
193 //*************************************************************************************************
194 
195 } // namespace blaze
196 
197 #endif