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_x2_add_32f.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_x2_add_32f
25  *
26  * \b Overview
27  *
28  * Adds two vectors together element by element:
29  *
30  * c[i] = a[i] + b[i]
31  *
32  * <b>Dispatcher Prototype</b>
33  * \code
34  * void volk_32f_x2_add_32f(float* cVector, const float* aVector, const float* bVector, unsigned int num_points)
35  * \endcode
36  *
37  * \b Inputs
38  * \li aVector: First vector of input points.
39  * \li bVector: Second vector of input points.
40  * \li num_points: The number of values in both input vector.
41  *
42  * \b Outputs
43  * \li cVector: The output vector.
44  *
45  * \b Example
46  *
47  * The follow example adds the increasing and decreasing vectors such that the result of every summation pair is 10
48  *
49  * \code
50  * int N = 10;
51  * unsigned int alignment = volk_get_alignment();
52  * float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
53  * float* decreasing = (float*)volk_malloc(sizeof(float)*N, alignment);
54  * float* out = (float*)volk_malloc(sizeof(float)*N, alignment);
55  *
56  * for(unsigned int ii = 0; ii < N; ++ii){
57  * increasing[ii] = (float)ii;
58  * decreasing[ii] = 10.f - (float)ii;
59  * }
60  *
61  * volk_32f_x2_add_32f(out, increasing, decreasing, N);
62  *
63  * for(unsigned int ii = 0; ii < N; ++ii){
64  * printf("out[%u] = %1.2f\n", ii, out[ii]);
65  * }
66  *
67  * volk_free(increasing);
68  * volk_free(decreasing);
69  * volk_free(out);
70  * \endcode
71  */
72 
73 #ifndef INCLUDED_volk_32f_x2_add_32f_u_H
74 #define INCLUDED_volk_32f_x2_add_32f_u_H
75 
76 #include <inttypes.h>
77 #include <stdio.h>
78 
79 #ifdef LV_HAVE_SSE
80 #include <xmmintrin.h>
81 
82 static inline void
83 volk_32f_x2_add_32f_u_sse(float* cVector, const float* aVector,
84  const float* bVector, unsigned int num_points)
85 {
86  unsigned int number = 0;
87  const unsigned int quarterPoints = num_points / 4;
88 
89  float* cPtr = cVector;
90  const float* aPtr = aVector;
91  const float* bPtr= bVector;
92 
93  __m128 aVal, bVal, cVal;
94  for(;number < quarterPoints; number++){
95 
96  aVal = _mm_loadu_ps(aPtr);
97  bVal = _mm_loadu_ps(bPtr);
98 
99  cVal = _mm_add_ps(aVal, bVal);
100 
101  _mm_storeu_ps(cPtr,cVal); // Store the results back into the C container
102 
103  aPtr += 4;
104  bPtr += 4;
105  cPtr += 4;
106  }
107 
108  number = quarterPoints * 4;
109  for(;number < num_points; number++){
110  *cPtr++ = (*aPtr++) + (*bPtr++);
111  }
112 }
113 #endif /* LV_HAVE_SSE */
114 
115 
116 #ifdef LV_HAVE_GENERIC
117 
118 static inline void
119 volk_32f_x2_add_32f_generic(float* cVector, const float* aVector,
120  const float* bVector, unsigned int num_points)
121 {
122  float* cPtr = cVector;
123  const float* aPtr = aVector;
124  const float* bPtr= bVector;
125  unsigned int number = 0;
126 
127  for(number = 0; number < num_points; number++){
128  *cPtr++ = (*aPtr++) + (*bPtr++);
129  }
130 }
131 #endif /* LV_HAVE_GENERIC */
132 
133 
134 #endif /* INCLUDED_volk_32f_x2_add_32f_u_H */
135 #ifndef INCLUDED_volk_32f_x2_add_32f_a_H
136 #define INCLUDED_volk_32f_x2_add_32f_a_H
137 
138 #include <inttypes.h>
139 #include <stdio.h>
140 
141 #ifdef LV_HAVE_SSE
142 #include <xmmintrin.h>
143 
144 static inline void
145 volk_32f_x2_add_32f_a_sse(float* cVector, const float* aVector, const float* bVector, unsigned int num_points)
146 {
147  unsigned int number = 0;
148  const unsigned int quarterPoints = num_points / 4;
149 
150  float* cPtr = cVector;
151  const float* aPtr = aVector;
152  const float* bPtr= bVector;
153 
154  __m128 aVal, bVal, cVal;
155  for(;number < quarterPoints; number++){
156  aVal = _mm_load_ps(aPtr);
157  bVal = _mm_load_ps(bPtr);
158 
159  cVal = _mm_add_ps(aVal, bVal);
160 
161  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
162 
163  aPtr += 4;
164  bPtr += 4;
165  cPtr += 4;
166  }
167 
168  number = quarterPoints * 4;
169  for(;number < num_points; number++){
170  *cPtr++ = (*aPtr++) + (*bPtr++);
171  }
172 }
173 #endif /* LV_HAVE_SSE */
174 
175 
176 #ifdef LV_HAVE_NEON
177 #include <arm_neon.h>
178 
179 static inline void
180 volk_32f_x2_add_32f_u_neon(float* cVector, const float* aVector,
181  const float* bVector, unsigned int num_points)
182 {
183  unsigned int number = 0;
184  const unsigned int quarterPoints = num_points / 4;
185 
186  float* cPtr = cVector;
187  const float* aPtr = aVector;
188  const float* bPtr= bVector;
189  float32x4_t aVal, bVal, cVal;
190  for(number=0; number < quarterPoints; number++){
191  // Load in to NEON registers
192  aVal = vld1q_f32(aPtr);
193  bVal = vld1q_f32(bPtr);
194  __builtin_prefetch(aPtr+4);
195  __builtin_prefetch(bPtr+4);
196 
197  // vector add
198  cVal = vaddq_f32(aVal, bVal);
199  // Store the results back into the C container
200  vst1q_f32(cPtr,cVal);
201 
202  aPtr += 4; // q uses quadwords, 4 floats per vadd
203  bPtr += 4;
204  cPtr += 4;
205  }
206 
207  number = quarterPoints * 4; // should be = num_points
208  for(;number < num_points; number++){
209  *cPtr++ = (*aPtr++) + (*bPtr++);
210  }
211 }
212 
213 #endif /* LV_HAVE_NEON */
214 
215 
216 #ifdef LV_HAVE_GENERIC
217 
218 static inline void
219 volk_32f_x2_add_32f_a_generic(float* cVector, const float* aVector,
220  const float* bVector, unsigned int num_points)
221 {
222  float* cPtr = cVector;
223  const float* aPtr = aVector;
224  const float* bPtr= bVector;
225  unsigned int number = 0;
226 
227  for(number = 0; number < num_points; number++){
228  *cPtr++ = (*aPtr++) + (*bPtr++);
229  }
230 }
231 #endif /* LV_HAVE_GENERIC */
232 
233 
234 #ifdef LV_HAVE_ORC
235 
236 extern void
237 volk_32f_x2_add_32f_a_orc_impl(float* cVector, const float* aVector,
238  const float* bVector, unsigned int num_points);
239 
240 static inline void
241 volk_32f_x2_add_32f_u_orc(float* cVector, const float* aVector,
242  const float* bVector, unsigned int num_points){
243  volk_32f_x2_add_32f_a_orc_impl(cVector, aVector, bVector, num_points);
244 }
245 
246 #endif /* LV_HAVE_ORC */
247 
248 
249 #endif /* INCLUDED_volk_32f_x2_add_32f_a_H */