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_multiply_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_multiply_32f
25  *
26  * \b Overview
27  *
28  * Multiplies two input floating point vectors together.
29  *
30  * c[i] = a[i] * b[i]
31  *
32  * <b>Dispatcher Prototype</b>
33  * \code
34  * void volk_32f_x2_multiply_32f(float* cVector, const float* aVector, const float* bVector, unsigned int num_points)
35  * \endcode
36  *
37  * \b Inputs
38  * \li aVector: First input vector.
39  * \li bVector: Second input vector.
40  * \li num_points: The number of values in both input vectors.
41  *
42  * \b Outputs
43  * \li cVector: The output vector.
44  *
45  * \b Example
46  * Multiply elements of an increasing vector by those of a decreasing vector.
47  * \code
48  * int N = 10;
49  * unsigned int alignment = volk_get_alignment();
50  * float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
51  * float* decreasing = (float*)volk_malloc(sizeof(float)*N, alignment);
52  * float* out = (float*)volk_malloc(sizeof(float)*N, alignment);
53  *
54  * for(unsigned int ii = 0; ii < N; ++ii){
55  * increasing[ii] = (float)ii;
56  * decreasing[ii] = 10.f - (float)ii;
57  * }
58  *
59  * volk_32f_x2_multiply_32f(out, increasing, decreasing, N);
60  *
61  * for(unsigned int ii = 0; ii < N; ++ii){
62  * printf("out[%u] = %1.2f\n", ii, out[ii]);
63  * }
64  *
65  * volk_free(increasing);
66  * volk_free(decreasing);
67  * volk_free(out);
68  * \endcode
69  */
70 
71 #ifndef INCLUDED_volk_32f_x2_multiply_32f_u_H
72 #define INCLUDED_volk_32f_x2_multiply_32f_u_H
73 
74 #include <inttypes.h>
75 #include <stdio.h>
76 
77 #ifdef LV_HAVE_SSE
78 #include <xmmintrin.h>
79 
80 static inline void
81 volk_32f_x2_multiply_32f_u_sse(float* cVector, const float* aVector,
82  const float* bVector, unsigned int num_points)
83 {
84  unsigned int number = 0;
85  const unsigned int quarterPoints = num_points / 4;
86 
87  float* cPtr = cVector;
88  const float* aPtr = aVector;
89  const float* bPtr= bVector;
90 
91  __m128 aVal, bVal, cVal;
92  for(;number < quarterPoints; number++){
93 
94  aVal = _mm_loadu_ps(aPtr);
95  bVal = _mm_loadu_ps(bPtr);
96 
97  cVal = _mm_mul_ps(aVal, bVal);
98 
99  _mm_storeu_ps(cPtr,cVal); // Store the results back into the C container
100 
101  aPtr += 4;
102  bPtr += 4;
103  cPtr += 4;
104  }
105 
106  number = quarterPoints * 4;
107  for(;number < num_points; number++){
108  *cPtr++ = (*aPtr++) * (*bPtr++);
109  }
110 }
111 #endif /* LV_HAVE_SSE */
112 
113 
114 #ifdef LV_HAVE_AVX
115 #include <immintrin.h>
116 
117 static inline void
118 volk_32f_x2_multiply_32f_u_avx(float* cVector, const float* aVector,
119  const float* bVector, unsigned int num_points)
120 {
121  unsigned int number = 0;
122  const unsigned int eighthPoints = num_points / 8;
123 
124  float* cPtr = cVector;
125  const float* aPtr = aVector;
126  const float* bPtr= bVector;
127 
128  __m256 aVal, bVal, cVal;
129  for(;number < eighthPoints; number++){
130 
131  aVal = _mm256_loadu_ps(aPtr);
132  bVal = _mm256_loadu_ps(bPtr);
133 
134  cVal = _mm256_mul_ps(aVal, bVal);
135 
136  _mm256_storeu_ps(cPtr,cVal); // Store the results back into the C container
137 
138  aPtr += 8;
139  bPtr += 8;
140  cPtr += 8;
141  }
142 
143  number = eighthPoints * 8;
144  for(;number < num_points; number++){
145  *cPtr++ = (*aPtr++) * (*bPtr++);
146  }
147 }
148 #endif /* LV_HAVE_AVX */
149 
150 
151 #ifdef LV_HAVE_GENERIC
152 
153 static inline void
154 volk_32f_x2_multiply_32f_generic(float* cVector, const float* aVector,
155  const float* bVector, unsigned int num_points)
156 {
157  float* cPtr = cVector;
158  const float* aPtr = aVector;
159  const float* bPtr= bVector;
160  unsigned int number = 0;
161 
162  for(number = 0; number < num_points; number++){
163  *cPtr++ = (*aPtr++) * (*bPtr++);
164  }
165 }
166 #endif /* LV_HAVE_GENERIC */
167 
168 
169 #endif /* INCLUDED_volk_32f_x2_multiply_32f_u_H */
170 
171 
172 #ifndef INCLUDED_volk_32f_x2_multiply_32f_a_H
173 #define INCLUDED_volk_32f_x2_multiply_32f_a_H
174 
175 #include <inttypes.h>
176 #include <stdio.h>
177 
178 #ifdef LV_HAVE_SSE
179 #include <xmmintrin.h>
180 
181 static inline void
182 volk_32f_x2_multiply_32f_a_sse(float* cVector, const float* aVector,
183  const float* bVector, unsigned int num_points)
184 {
185  unsigned int number = 0;
186  const unsigned int quarterPoints = num_points / 4;
187 
188  float* cPtr = cVector;
189  const float* aPtr = aVector;
190  const float* bPtr= bVector;
191 
192  __m128 aVal, bVal, cVal;
193  for(;number < quarterPoints; number++){
194 
195  aVal = _mm_load_ps(aPtr);
196  bVal = _mm_load_ps(bPtr);
197 
198  cVal = _mm_mul_ps(aVal, bVal);
199 
200  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
201 
202  aPtr += 4;
203  bPtr += 4;
204  cPtr += 4;
205  }
206 
207  number = quarterPoints * 4;
208  for(;number < num_points; number++){
209  *cPtr++ = (*aPtr++) * (*bPtr++);
210  }
211 }
212 #endif /* LV_HAVE_SSE */
213 
214 
215 #ifdef LV_HAVE_AVX
216 #include <immintrin.h>
217 
218 static inline void
219 volk_32f_x2_multiply_32f_a_avx(float* cVector, const float* aVector,
220  const float* bVector, unsigned int num_points)
221 {
222  unsigned int number = 0;
223  const unsigned int eighthPoints = num_points / 8;
224 
225  float* cPtr = cVector;
226  const float* aPtr = aVector;
227  const float* bPtr= bVector;
228 
229  __m256 aVal, bVal, cVal;
230  for(;number < eighthPoints; number++){
231 
232  aVal = _mm256_load_ps(aPtr);
233  bVal = _mm256_load_ps(bPtr);
234 
235  cVal = _mm256_mul_ps(aVal, bVal);
236 
237  _mm256_store_ps(cPtr,cVal); // Store the results back into the C container
238 
239  aPtr += 8;
240  bPtr += 8;
241  cPtr += 8;
242  }
243 
244  number = eighthPoints * 8;
245  for(;number < num_points; number++){
246  *cPtr++ = (*aPtr++) * (*bPtr++);
247  }
248 }
249 #endif /* LV_HAVE_AVX */
250 
251 
252 #ifdef LV_HAVE_NEON
253 #include <arm_neon.h>
254 
255 static inline void
256 volk_32f_x2_multiply_32f_neon(float* cVector, const float* aVector,
257  const float* bVector, unsigned int num_points)
258 {
259  const unsigned int quarter_points = num_points / 4;
260  unsigned int number;
261  float32x4_t avec, bvec, cvec;
262  for(number=0; number < quarter_points; ++number) {
263  avec = vld1q_f32(aVector);
264  bvec = vld1q_f32(bVector);
265  cvec = vmulq_f32(avec, bvec);
266  vst1q_f32(cVector, cvec);
267  aVector += 4;
268  bVector += 4;
269  cVector += 4;
270  }
271  for(number=quarter_points*4; number < num_points; ++number) {
272  *cVector++ = *aVector++ * *bVector++;
273  }
274 }
275 #endif /* LV_HAVE_NEON */
276 
277 
278 #ifdef LV_HAVE_GENERIC
279 
280 static inline void
281 volk_32f_x2_multiply_32f_a_generic(float* cVector, const float* aVector,
282  const float* bVector, unsigned int num_points)
283 {
284  float* cPtr = cVector;
285  const float* aPtr = aVector;
286  const float* bPtr= bVector;
287  unsigned int number = 0;
288 
289  for(number = 0; number < num_points; number++){
290  *cPtr++ = (*aPtr++) * (*bPtr++);
291  }
292 }
293 #endif /* LV_HAVE_GENERIC */
294 
295 
296 #ifdef LV_HAVE_ORC
297 extern void
298 volk_32f_x2_multiply_32f_a_orc_impl(float* cVector, const float* aVector,
299  const float* bVector, unsigned int num_points);
300 
301 static inline void
302 volk_32f_x2_multiply_32f_u_orc(float* cVector, const float* aVector,
303  const float* bVector, unsigned int num_points)
304 {
305  volk_32f_x2_multiply_32f_a_orc_impl(cVector, aVector, bVector, num_points);
306 }
307 #endif /* LV_HAVE_ORC */
308 
309 
310 #endif /* INCLUDED_volk_32f_x2_multiply_32f_a_H */