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 
31 #include <blaze/system/SSE.h>
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_SSSE3_MODE
52  const sse_int16_t b( _mm_hadd_epi16( a.value, a.value ) );
53  const sse_int16_t c( _mm_hadd_epi16( b.value, b.value ) );
54  const sse_int16_t d( _mm_hadd_epi16( c.value, c.value ) );
55  return d.values[0];
56 #elif BLAZE_SSE2_MODE
57  return a.values[0] + a.values[1] + a.values[2] + a.values[3] +
58  a.values[4] + a.values[5] + a.values[6] + a.values[7];
59 #else
60  return a.value;
61 #endif
62 }
63 //*************************************************************************************************
64 
65 
66 //*************************************************************************************************
73 inline int32_t sum( const sse_int32_t& a )
74 {
75 #if BLAZE_MIC_MODE
76  return _mm512_reduce_add_epi32( a.value );
77 #elif BLAZE_SSSE3_MODE
78  const sse_int32_t b( _mm_hadd_epi32( a.value, a.value ) );
79  const sse_int32_t c( _mm_hadd_epi32( b.value, b.value ) );
80  return c.values[0];
81 #elif BLAZE_SSE2_MODE
82  return a.values[0] + a.values[1] + a.values[2] + a.values[3];
83 #else
84  return a.value;
85 #endif
86 }
87 //*************************************************************************************************
88 
89 
90 //*************************************************************************************************
97 inline float sum( const sse_float_t& a )
98 {
99 #if BLAZE_MIC_MODE
100  return _mm512_reduce_add_ps( a.value );
101 #elif BLAZE_AVX_MODE
102  const sse_float_t b( _mm256_hadd_ps( a.value, a.value ) );
103  const sse_float_t c( _mm256_hadd_ps( b.value, b.value ) );
104  const sse_float_t d( _mm256_hadd_ps( c.value, c.value ) );
105  return d.values[0];
106 #elif BLAZE_SSE3_MODE
107  const sse_float_t b( _mm_hadd_ps( a.value, a.value ) );
108  const sse_float_t c( _mm_hadd_ps( b.value, b.value ) );
109  return c.values[0];
110 #elif BLAZE_SSE_MODE
111  return a.values[0] + a.values[1] + a.values[2] + a.values[3];
112 #else
113  return a.value;
114 #endif
115 }
116 //*************************************************************************************************
117 
118 
119 //*************************************************************************************************
126 inline double sum( const sse_double_t& a )
127 {
128 #if BLAZE_MIC_MODE
129  return _mm512_reduce_add_pd( a.value );
130 #elif BLAZE_AVX_MODE
131  const sse_double_t b( _mm256_hadd_pd( a.value, a.value ) );
132  const sse_double_t c( _mm256_hadd_pd( b.value, b.value ) );
133  return c.values[0];
134 #elif BLAZE_SSE3_MODE
135  const sse_double_t b( _mm_hadd_pd( a.value, a.value ) );
136  return b.values[0];
137 #elif BLAZE_SSE2_MODE
138  return a.values[0] + a.values[1];
139 #else
140  return a.value;
141 #endif
142 }
143 //*************************************************************************************************
144 
145 } // namespace blaze
146 
147 #endif