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 float sum( const sse_float_t& a )
121 {
122 #if BLAZE_MIC_MODE
123  return _mm512_reduce_add_ps( a.value );
124 #elif BLAZE_AVX_MODE
125  const sse_float_t b( _mm256_hadd_ps( a.value, a.value ) );
126  const sse_float_t c( _mm256_hadd_ps( b.value, b.value ) );
127  const sse_float_t d( _mm256_hadd_ps( c.value, c.value ) );
128  return d[0];
129 #elif BLAZE_SSE3_MODE
130  const sse_float_t b( _mm_hadd_ps( a.value, a.value ) );
131  const sse_float_t c( _mm_hadd_ps( b.value, b.value ) );
132  return c[0];
133 #elif BLAZE_SSE_MODE
134  return a[0] + a[1] + a[2] + a[3];
135 #else
136  return a.value;
137 #endif
138 }
139 //*************************************************************************************************
140 
141 
142 //*************************************************************************************************
149 inline double sum( const sse_double_t& a )
150 {
151 #if BLAZE_MIC_MODE
152  return _mm512_reduce_add_pd( a.value );
153 #elif BLAZE_AVX_MODE
154  const sse_double_t b( _mm256_hadd_pd( a.value, a.value ) );
155  const sse_double_t c( _mm256_hadd_pd( b.value, b.value ) );
156  return c[0];
157 #elif BLAZE_SSE3_MODE
158  const sse_double_t b( _mm_hadd_pd( a.value, a.value ) );
159  return b[0];
160 #elif BLAZE_SSE2_MODE
161  return a[0] + a[1];
162 #else
163  return a.value;
164 #endif
165 }
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
176 inline complex<float> sum( const sse_cfloat_t& a )
177 {
178 #if BLAZE_MIC_MODE
179  return complex<float>( a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] );
180 #elif BLAZE_AVX_MODE
181  return complex<float>( a[0] + a[1] + a[2] + a[3] );
182 #elif BLAZE_SSE_MODE
183  return complex<float>( a[0] + a[1] );
184 #else
185  return a.value;
186 #endif
187 }
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
198 inline complex<double> sum( const sse_cdouble_t& a )
199 {
200 #if BLAZE_MIC_MODE
201  return complex<double>( a[0] + a[1] + a[2] + a[3] );
202 #elif BLAZE_AVX_MODE
203  return complex<double>( a[0] + a[1] );
204 #elif BLAZE_SSE2_MODE
205  return a[0];
206 #else
207  return a.value;
208 #endif
209 }
210 //*************************************************************************************************
211 
212 } // namespace blaze
213 
214 #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 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.
Intrinsic type for 32-bit integral data values.
32-bit signed integer type of the Blaze library.