GNU Radio Manual and C++ API Reference  3.7.6.1
The Free & Open Software Radio Ecosystem
volk_32f_accumulator_s32f.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 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 #ifndef INCLUDED_volk_32f_accumulator_s32f_a_H
24 #define INCLUDED_volk_32f_accumulator_s32f_a_H
25 
26 #include <volk/volk_common.h>
27 #include <inttypes.h>
28 #include <stdio.h>
29 
30 #ifdef LV_HAVE_SSE
31 #include <xmmintrin.h>
32 /*!
33  \brief Accumulates the values in the input buffer
34  \param result The accumulated result
35  \param inputBuffer The buffer of data to be accumulated
36  \param num_points The number of values in inputBuffer to be accumulated
37 */
38 static inline void volk_32f_accumulator_s32f_a_sse(float* result, const float* inputBuffer, unsigned int num_points){
39  float returnValue = 0;
40  unsigned int number = 0;
41  const unsigned int quarterPoints = num_points / 4;
42 
43  const float* aPtr = inputBuffer;
44  __VOLK_ATTR_ALIGNED(16) float tempBuffer[4];
45 
46  __m128 accumulator = _mm_setzero_ps();
47  __m128 aVal = _mm_setzero_ps();
48 
49  for(;number < quarterPoints; number++){
50  aVal = _mm_load_ps(aPtr);
51  accumulator = _mm_add_ps(accumulator, aVal);
52  aPtr += 4;
53  }
54  _mm_store_ps(tempBuffer,accumulator); // Store the results back into the C container
55  returnValue = tempBuffer[0];
56  returnValue += tempBuffer[1];
57  returnValue += tempBuffer[2];
58  returnValue += tempBuffer[3];
59 
60  number = quarterPoints * 4;
61  for(;number < num_points; number++){
62  returnValue += (*aPtr++);
63  }
64  *result = returnValue;
65 }
66 #endif /* LV_HAVE_SSE */
67 
68 #ifdef LV_HAVE_GENERIC
69 /*!
70  \brief Accumulates the values in the input buffer
71  \param result The accumulated result
72  \param inputBuffer The buffer of data to be accumulated
73  \param num_points The number of values in inputBuffer to be accumulated
74 */
75 static inline void volk_32f_accumulator_s32f_generic(float* result, const float* inputBuffer, unsigned int num_points){
76  const float* aPtr = inputBuffer;
77  unsigned int number = 0;
78  float returnValue = 0;
79 
80  for(;number < num_points; number++){
81  returnValue += (*aPtr++);
82  }
83  *result = returnValue;
84 }
85 #endif /* LV_HAVE_GENERIC */
86 
87 
88 
89 
90 #endif /* INCLUDED_volk_32f_accumulator_s32f_a_H */
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:27