GNU Radio Manual and C++ API Reference  3.7.7
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
volk_32f_accumulator_s32f.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 /*!
24  * \page volk_32f_accumulator_s32f
25  *
26  * \b Overview
27  *
28  * Accumulates the values in the input buffer.
29  *
30  * <b>Dispatcher Prototype</b>
31  * \code
32  * void volk_32f_accumulator_s32f(float* result, const float* inputBuffer, unsigned int num_points)
33  * \endcode
34  *
35  * \b Inputs
36  * \li inputBuffer The buffer of data to be accumulated
37  * \li num_points: The number of data points.
38  *
39  * \b Outputs
40  * \li result The accumulated result.
41  *
42  * \b Example
43  * Calculate the sum of numbers 0 through 99
44  * \code
45  * int N = 100;
46  * unsigned int alignment = volk_get_alignment();
47  * float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
48  * float* out = (float*)volk_malloc(sizeof(float), alignment);
49  *
50  * for(unsigned int ii = 0; ii < N; ++ii){
51  * increasing[ii] = (float)ii;
52  * }
53  *
54  * volk_32f_accumulator_s32f(out, increasing, N);
55  *
56  * printf("sum(1..100) = %1.2f\n", out[0]);
57  *
58  * volk_free(increasing);
59  * volk_free(out);
60  * \endcode
61  */
62 
63 #ifndef INCLUDED_volk_32f_accumulator_s32f_a_H
64 #define INCLUDED_volk_32f_accumulator_s32f_a_H
65 
66 #include <volk/volk_common.h>
67 #include <inttypes.h>
68 #include <stdio.h>
69 
70 #ifdef LV_HAVE_SSE
71 
72 #include <xmmintrin.h>
73 
74 static inline void
75 volk_32f_accumulator_s32f_a_sse(float* result, const float* inputBuffer, unsigned int num_points)
76 {
77  float returnValue = 0;
78  unsigned int number = 0;
79  const unsigned int quarterPoints = num_points / 4;
80 
81  const float* aPtr = inputBuffer;
82  __VOLK_ATTR_ALIGNED(16) float tempBuffer[4];
83 
84  __m128 accumulator = _mm_setzero_ps();
85  __m128 aVal = _mm_setzero_ps();
86 
87  for(;number < quarterPoints; number++){
88  aVal = _mm_load_ps(aPtr);
89  accumulator = _mm_add_ps(accumulator, aVal);
90  aPtr += 4;
91  }
92 
93  _mm_store_ps(tempBuffer,accumulator); // Store the results back into the C container
94 
95  returnValue = tempBuffer[0];
96  returnValue += tempBuffer[1];
97  returnValue += tempBuffer[2];
98  returnValue += tempBuffer[3];
99 
100  number = quarterPoints * 4;
101  for(;number < num_points; number++){
102  returnValue += (*aPtr++);
103  }
104  *result = returnValue;
105 }
106 
107 #endif /* LV_HAVE_SSE */
108 
109 
110 
111 #ifdef LV_HAVE_GENERIC
112 
113 static inline void
114 volk_32f_accumulator_s32f_generic(float* result, const float* inputBuffer, unsigned int num_points)
115 {
116  const float* aPtr = inputBuffer;
117  unsigned int number = 0;
118  float returnValue = 0;
119 
120  for(;number < num_points; number++){
121  returnValue += (*aPtr++);
122  }
123  *result = returnValue;
124 }
125 
126 #endif /* LV_HAVE_GENERIC */
127 
128 #endif /* INCLUDED_volk_32f_accumulator_s32f_a_H */
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:27