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_32fc_x2_dot_prod_32fc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 2013, 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_32fc_x2_dot_prod_32fc
25  *
26  * \b Overview
27  *
28  * This block computes the dot product (or inner product) between two
29  * vectors, the \p input and \p taps vectors. Given a set of \p
30  * num_points taps, the result is the sum of products between the two
31  * vectors. The result is a single value stored in the \p result
32  * address and is returned as a complex float.
33  *
34  * <b>Dispatcher Prototype</b>
35  * \code
36  * void volk_32fc_x2_dot_prod_32fc(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points)
37  * \endcode
38  *
39  * \b Inputs
40  * \li input: vector of complex floats.
41  * \li taps: complex float taps.
42  * \li num_points: number of samples in both \p input and \p taps.
43  *
44  * \b Outputs
45  * \li result: pointer to a complex float value to hold the dot product result.
46  *
47  * \b Example
48  * \code
49  * int N = 10000;
50  *
51  * <FIXME>
52  *
53  * volk_32fc_x2_dot_prod_32fc();
54  *
55  * \endcode
56  */
57 
58 #ifndef INCLUDED_volk_32fc_x2_dot_prod_32fc_u_H
59 #define INCLUDED_volk_32fc_x2_dot_prod_32fc_u_H
60 
61 #include <volk/volk_common.h>
62 #include <volk/volk_complex.h>
63 #include <stdio.h>
64 #include <string.h>
65 
66 
67 #ifdef LV_HAVE_GENERIC
68 
69 
70 static inline void volk_32fc_x2_dot_prod_32fc_generic(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
71 
72  float * res = (float*) result;
73  float * in = (float*) input;
74  float * tp = (float*) taps;
75  unsigned int n_2_ccomplex_blocks = num_points/2;
76  unsigned int isodd = num_points & 1;
77 
78  float sum0[2] = {0,0};
79  float sum1[2] = {0,0};
80  unsigned int i = 0;
81 
82  for(i = 0; i < n_2_ccomplex_blocks; ++i) {
83  sum0[0] += in[0] * tp[0] - in[1] * tp[1];
84  sum0[1] += in[0] * tp[1] + in[1] * tp[0];
85  sum1[0] += in[2] * tp[2] - in[3] * tp[3];
86  sum1[1] += in[2] * tp[3] + in[3] * tp[2];
87 
88  in += 4;
89  tp += 4;
90  }
91 
92  res[0] = sum0[0] + sum1[0];
93  res[1] = sum0[1] + sum1[1];
94 
95  // Cleanup if we had an odd number of points
96  for(i = 0; i < isodd; ++i) {
97  *result += input[num_points - 1] * taps[num_points - 1];
98  }
99 }
100 
101 #endif /*LV_HAVE_GENERIC*/
102 
103 
104 
105 #if LV_HAVE_SSE && LV_HAVE_64
106 
107 static inline void volk_32fc_x2_dot_prod_32fc_u_sse_64(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
108 
109  const unsigned int num_bytes = num_points*8;
110  unsigned int isodd = num_points & 1;
111 
112  asm
113  (
114  "# ccomplex_dotprod_generic (float* result, const float *input,\n\t"
115  "# const float *taps, unsigned num_bytes)\n\t"
116  "# float sum0 = 0;\n\t"
117  "# float sum1 = 0;\n\t"
118  "# float sum2 = 0;\n\t"
119  "# float sum3 = 0;\n\t"
120  "# do {\n\t"
121  "# sum0 += input[0] * taps[0] - input[1] * taps[1];\n\t"
122  "# sum1 += input[0] * taps[1] + input[1] * taps[0];\n\t"
123  "# sum2 += input[2] * taps[2] - input[3] * taps[3];\n\t"
124  "# sum3 += input[2] * taps[3] + input[3] * taps[2];\n\t"
125  "# input += 4;\n\t"
126  "# taps += 4; \n\t"
127  "# } while (--n_2_ccomplex_blocks != 0);\n\t"
128  "# result[0] = sum0 + sum2;\n\t"
129  "# result[1] = sum1 + sum3;\n\t"
130  "# TODO: prefetch and better scheduling\n\t"
131  " xor %%r9, %%r9\n\t"
132  " xor %%r10, %%r10\n\t"
133  " movq %%rcx, %%rax\n\t"
134  " movq %%rcx, %%r8\n\t"
135  " movq %[rsi], %%r9\n\t"
136  " movq %[rdx], %%r10\n\t"
137  " xorps %%xmm6, %%xmm6 # zero accumulators\n\t"
138  " movups 0(%%r9), %%xmm0\n\t"
139  " xorps %%xmm7, %%xmm7 # zero accumulators\n\t"
140  " movups 0(%%r10), %%xmm2\n\t"
141  " shr $5, %%rax # rax = n_2_ccomplex_blocks / 2\n\t"
142  " shr $4, %%r8\n\t"
143  " jmp .%=L1_test\n\t"
144  " # 4 taps / loop\n\t"
145  " # something like ?? cycles / loop\n\t"
146  ".%=Loop1: \n\t"
147  "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t"
148  "# movups (%%r9), %%xmmA\n\t"
149  "# movups (%%r10), %%xmmB\n\t"
150  "# movups %%xmmA, %%xmmZ\n\t"
151  "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t"
152  "# mulps %%xmmB, %%xmmA\n\t"
153  "# mulps %%xmmZ, %%xmmB\n\t"
154  "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t"
155  "# xorps %%xmmPN, %%xmmA\n\t"
156  "# movups %%xmmA, %%xmmZ\n\t"
157  "# unpcklps %%xmmB, %%xmmA\n\t"
158  "# unpckhps %%xmmB, %%xmmZ\n\t"
159  "# movups %%xmmZ, %%xmmY\n\t"
160  "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t"
161  "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t"
162  "# addps %%xmmZ, %%xmmA\n\t"
163  "# addps %%xmmA, %%xmmC\n\t"
164  "# A=xmm0, B=xmm2, Z=xmm4\n\t"
165  "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t"
166  " movups 16(%%r9), %%xmm1\n\t"
167  " movups %%xmm0, %%xmm4\n\t"
168  " mulps %%xmm2, %%xmm0\n\t"
169  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
170  " movups 16(%%r10), %%xmm3\n\t"
171  " movups %%xmm1, %%xmm5\n\t"
172  " addps %%xmm0, %%xmm6\n\t"
173  " mulps %%xmm3, %%xmm1\n\t"
174  " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t"
175  " addps %%xmm1, %%xmm6\n\t"
176  " mulps %%xmm4, %%xmm2\n\t"
177  " movups 32(%%r9), %%xmm0\n\t"
178  " addps %%xmm2, %%xmm7\n\t"
179  " mulps %%xmm5, %%xmm3\n\t"
180  " add $32, %%r9\n\t"
181  " movups 32(%%r10), %%xmm2\n\t"
182  " addps %%xmm3, %%xmm7\n\t"
183  " add $32, %%r10\n\t"
184  ".%=L1_test:\n\t"
185  " dec %%rax\n\t"
186  " jge .%=Loop1\n\t"
187  " # We've handled the bulk of multiplies up to here.\n\t"
188  " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t"
189  " # If so, we've got 2 more taps to do.\n\t"
190  " and $1, %%r8\n\t"
191  " je .%=Leven\n\t"
192  " # The count was odd, do 2 more taps.\n\t"
193  " # Note that we've already got mm0/mm2 preloaded\n\t"
194  " # from the main loop.\n\t"
195  " movups %%xmm0, %%xmm4\n\t"
196  " mulps %%xmm2, %%xmm0\n\t"
197  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
198  " addps %%xmm0, %%xmm6\n\t"
199  " mulps %%xmm4, %%xmm2\n\t"
200  " addps %%xmm2, %%xmm7\n\t"
201  ".%=Leven:\n\t"
202  " # neg inversor\n\t"
203  " xorps %%xmm1, %%xmm1\n\t"
204  " mov $0x80000000, %%r9\n\t"
205  " movd %%r9, %%xmm1\n\t"
206  " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t"
207  " # pfpnacc\n\t"
208  " xorps %%xmm1, %%xmm6\n\t"
209  " movups %%xmm6, %%xmm2\n\t"
210  " unpcklps %%xmm7, %%xmm6\n\t"
211  " unpckhps %%xmm7, %%xmm2\n\t"
212  " movups %%xmm2, %%xmm3\n\t"
213  " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t"
214  " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t"
215  " addps %%xmm2, %%xmm6\n\t"
216  " # xmm6 = r1 i2 r3 i4\n\t"
217  " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t"
218  " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t"
219  " movlps %%xmm6, (%[rdi]) # store low 2x32 bits (complex) to memory\n\t"
220  :
221  :[rsi] "r" (input), [rdx] "r" (taps), "c" (num_bytes), [rdi] "r" (result)
222  :"rax", "r8", "r9", "r10"
223  );
224 
225 
226  if(isodd) {
227  *result += input[num_points - 1] * taps[num_points - 1];
228  }
229 
230  return;
231 
232 }
233 
234 #endif /* LV_HAVE_SSE && LV_HAVE_64 */
235 
236 
237 
238 
239 #ifdef LV_HAVE_SSE3
240 
241 #include <pmmintrin.h>
242 
243 static inline void volk_32fc_x2_dot_prod_32fc_u_sse3(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
244 
245  lv_32fc_t dotProduct;
246  memset(&dotProduct, 0x0, 2*sizeof(float));
247 
248  unsigned int number = 0;
249  const unsigned int halfPoints = num_points/2;
250  unsigned int isodd = num_points & 1;
251 
252  __m128 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
253 
254  const lv_32fc_t* a = input;
255  const lv_32fc_t* b = taps;
256 
257  dotProdVal = _mm_setzero_ps();
258 
259  for(;number < halfPoints; number++){
260 
261  x = _mm_loadu_ps((float*)a); // Load the ar + ai, br + bi as ar,ai,br,bi
262  y = _mm_loadu_ps((float*)b); // Load the cr + ci, dr + di as cr,ci,dr,di
263 
264  yl = _mm_moveldup_ps(y); // Load yl with cr,cr,dr,dr
265  yh = _mm_movehdup_ps(y); // Load yh with ci,ci,di,di
266 
267  tmp1 = _mm_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr
268 
269  x = _mm_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br
270 
271  tmp2 = _mm_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di
272 
273  z = _mm_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
274 
275  dotProdVal = _mm_add_ps(dotProdVal, z); // Add the complex multiplication results together
276 
277  a += 2;
278  b += 2;
279  }
280 
281  __VOLK_ATTR_ALIGNED(16) lv_32fc_t dotProductVector[2];
282 
283  _mm_storeu_ps((float*)dotProductVector,dotProdVal); // Store the results back into the dot product vector
284 
285  dotProduct += ( dotProductVector[0] + dotProductVector[1] );
286 
287  if(isodd) {
288  dotProduct += input[num_points - 1] * taps[num_points - 1];
289  }
290 
291  *result = dotProduct;
292 }
293 
294 #endif /*LV_HAVE_SSE3*/
295 
296 #ifdef LV_HAVE_SSE4_1
297 
298 #include <smmintrin.h>
299 
300 static inline void volk_32fc_x2_dot_prod_32fc_u_sse4_1(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
301 
302  unsigned int i = 0;
303  const unsigned int qtr_points = num_points/4;
304  const unsigned int isodd = num_points & 3;
305 
306  __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, real0, real1, im0, im1;
307  float *p_input, *p_taps;
308  __m64 *p_result;
309 
310  p_result = (__m64*)result;
311  p_input = (float*)input;
312  p_taps = (float*)taps;
313 
314  static const __m128i neg = {0x000000000000000080000000};
315 
316  real0 = _mm_setzero_ps();
317  real1 = _mm_setzero_ps();
318  im0 = _mm_setzero_ps();
319  im1 = _mm_setzero_ps();
320 
321  for(; i < qtr_points; ++i) {
322  xmm0 = _mm_loadu_ps(p_input);
323  xmm1 = _mm_loadu_ps(p_taps);
324 
325  p_input += 4;
326  p_taps += 4;
327 
328  xmm2 = _mm_loadu_ps(p_input);
329  xmm3 = _mm_loadu_ps(p_taps);
330 
331  p_input += 4;
332  p_taps += 4;
333 
334  xmm4 = _mm_unpackhi_ps(xmm0, xmm2);
335  xmm5 = _mm_unpackhi_ps(xmm1, xmm3);
336  xmm0 = _mm_unpacklo_ps(xmm0, xmm2);
337  xmm2 = _mm_unpacklo_ps(xmm1, xmm3);
338 
339  //imaginary vector from input
340  xmm1 = _mm_unpackhi_ps(xmm0, xmm4);
341  //real vector from input
342  xmm3 = _mm_unpacklo_ps(xmm0, xmm4);
343  //imaginary vector from taps
344  xmm0 = _mm_unpackhi_ps(xmm2, xmm5);
345  //real vector from taps
346  xmm2 = _mm_unpacklo_ps(xmm2, xmm5);
347 
348  xmm4 = _mm_dp_ps(xmm3, xmm2, 0xf1);
349  xmm5 = _mm_dp_ps(xmm1, xmm0, 0xf1);
350 
351  xmm6 = _mm_dp_ps(xmm3, xmm0, 0xf2);
352  xmm7 = _mm_dp_ps(xmm1, xmm2, 0xf2);
353 
354  real0 = _mm_add_ps(xmm4, real0);
355  real1 = _mm_add_ps(xmm5, real1);
356  im0 = _mm_add_ps(xmm6, im0);
357  im1 = _mm_add_ps(xmm7, im1);
358  }
359 
360  real1 = _mm_xor_ps(real1, bit128_p(&neg)->float_vec);
361 
362  im0 = _mm_add_ps(im0, im1);
363  real0 = _mm_add_ps(real0, real1);
364 
365  im0 = _mm_add_ps(im0, real0);
366 
367  _mm_storel_pi(p_result, im0);
368 
369  for(i = num_points-isodd; i < num_points; i++) {
370  *result += input[i] * taps[i];
371  }
372 }
373 
374 #endif /*LV_HAVE_SSE4_1*/
375 
376 #ifdef LV_HAVE_AVX
377 
378 #include <immintrin.h>
379 
380 static inline void volk_32fc_x2_dot_prod_32fc_u_avx(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
381 
382  unsigned int isodd = num_points & 3;
383  unsigned int i = 0;
384  lv_32fc_t dotProduct;
385  memset(&dotProduct, 0x0, 2*sizeof(float));
386 
387  unsigned int number = 0;
388  const unsigned int quarterPoints = num_points / 4;
389 
390  __m256 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
391 
392  const lv_32fc_t* a = input;
393  const lv_32fc_t* b = taps;
394 
395  dotProdVal = _mm256_setzero_ps();
396 
397  for(;number < quarterPoints; number++){
398  x = _mm256_loadu_ps((float*)a); // Load a,b,e,f as ar,ai,br,bi,er,ei,fr,fi
399  y = _mm256_loadu_ps((float*)b); // Load c,d,g,h as cr,ci,dr,di,gr,gi,hr,hi
400 
401  yl = _mm256_moveldup_ps(y); // Load yl with cr,cr,dr,dr,gr,gr,hr,hr
402  yh = _mm256_movehdup_ps(y); // Load yh with ci,ci,di,di,gi,gi,hi,hi
403 
404  tmp1 = _mm256_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr ...
405 
406  x = _mm256_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br,ei,er,fi,fr
407 
408  tmp2 = _mm256_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di ...
409 
410  z = _mm256_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
411 
412  dotProdVal = _mm256_add_ps(dotProdVal, z); // Add the complex multiplication results together
413 
414  a += 4;
415  b += 4;
416  }
417 
418  __VOLK_ATTR_ALIGNED(32) lv_32fc_t dotProductVector[4];
419 
420  _mm256_storeu_ps((float*)dotProductVector,dotProdVal); // Store the results back into the dot product vector
421 
422  dotProduct += ( dotProductVector[0] + dotProductVector[1] + dotProductVector[2] + dotProductVector[3]);
423 
424  for(i = num_points-isodd; i < num_points; i++) {
425  dotProduct += input[i] * taps[i];
426  }
427 
428  *result = dotProduct;
429 }
430 
431 #endif /*LV_HAVE_AVX*/
432 
433 
434 #endif /*INCLUDED_volk_32fc_x2_dot_prod_32fc_u_H*/
435 
436 #ifndef INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H
437 #define INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H
438 
439 #include <volk/volk_common.h>
440 #include <volk/volk_complex.h>
441 #include <stdio.h>
442 #include <string.h>
443 
444 
445 #ifdef LV_HAVE_GENERIC
446 
447 
448 static inline void volk_32fc_x2_dot_prod_32fc_a_generic(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
449 
450  const unsigned int num_bytes = num_points*8;
451 
452  float * res = (float*) result;
453  float * in = (float*) input;
454  float * tp = (float*) taps;
455  unsigned int n_2_ccomplex_blocks = num_bytes >> 4;
456  unsigned int isodd = num_points & 1;
457 
458  float sum0[2] = {0,0};
459  float sum1[2] = {0,0};
460  unsigned int i = 0;
461 
462  for(i = 0; i < n_2_ccomplex_blocks; ++i) {
463  sum0[0] += in[0] * tp[0] - in[1] * tp[1];
464  sum0[1] += in[0] * tp[1] + in[1] * tp[0];
465  sum1[0] += in[2] * tp[2] - in[3] * tp[3];
466  sum1[1] += in[2] * tp[3] + in[3] * tp[2];
467 
468  in += 4;
469  tp += 4;
470  }
471 
472  res[0] = sum0[0] + sum1[0];
473  res[1] = sum0[1] + sum1[1];
474 
475  for(i = 0; i < isodd; ++i) {
476  *result += input[num_points - 1] * taps[num_points - 1];
477  }
478 }
479 
480 #endif /*LV_HAVE_GENERIC*/
481 
482 
483 #if LV_HAVE_SSE && LV_HAVE_64
484 
485 
486 static inline void volk_32fc_x2_dot_prod_32fc_a_sse_64(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
487 
488  const unsigned int num_bytes = num_points*8;
489  unsigned int isodd = num_points & 1;
490 
491  asm
492  (
493  "# ccomplex_dotprod_generic (float* result, const float *input,\n\t"
494  "# const float *taps, unsigned num_bytes)\n\t"
495  "# float sum0 = 0;\n\t"
496  "# float sum1 = 0;\n\t"
497  "# float sum2 = 0;\n\t"
498  "# float sum3 = 0;\n\t"
499  "# do {\n\t"
500  "# sum0 += input[0] * taps[0] - input[1] * taps[1];\n\t"
501  "# sum1 += input[0] * taps[1] + input[1] * taps[0];\n\t"
502  "# sum2 += input[2] * taps[2] - input[3] * taps[3];\n\t"
503  "# sum3 += input[2] * taps[3] + input[3] * taps[2];\n\t"
504  "# input += 4;\n\t"
505  "# taps += 4; \n\t"
506  "# } while (--n_2_ccomplex_blocks != 0);\n\t"
507  "# result[0] = sum0 + sum2;\n\t"
508  "# result[1] = sum1 + sum3;\n\t"
509  "# TODO: prefetch and better scheduling\n\t"
510  " xor %%r9, %%r9\n\t"
511  " xor %%r10, %%r10\n\t"
512  " movq %%rcx, %%rax\n\t"
513  " movq %%rcx, %%r8\n\t"
514  " movq %[rsi], %%r9\n\t"
515  " movq %[rdx], %%r10\n\t"
516  " xorps %%xmm6, %%xmm6 # zero accumulators\n\t"
517  " movaps 0(%%r9), %%xmm0\n\t"
518  " xorps %%xmm7, %%xmm7 # zero accumulators\n\t"
519  " movaps 0(%%r10), %%xmm2\n\t"
520  " shr $5, %%rax # rax = n_2_ccomplex_blocks / 2\n\t"
521  " shr $4, %%r8\n\t"
522  " jmp .%=L1_test\n\t"
523  " # 4 taps / loop\n\t"
524  " # something like ?? cycles / loop\n\t"
525  ".%=Loop1: \n\t"
526  "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t"
527  "# movaps (%%r9), %%xmmA\n\t"
528  "# movaps (%%r10), %%xmmB\n\t"
529  "# movaps %%xmmA, %%xmmZ\n\t"
530  "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t"
531  "# mulps %%xmmB, %%xmmA\n\t"
532  "# mulps %%xmmZ, %%xmmB\n\t"
533  "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t"
534  "# xorps %%xmmPN, %%xmmA\n\t"
535  "# movaps %%xmmA, %%xmmZ\n\t"
536  "# unpcklps %%xmmB, %%xmmA\n\t"
537  "# unpckhps %%xmmB, %%xmmZ\n\t"
538  "# movaps %%xmmZ, %%xmmY\n\t"
539  "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t"
540  "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t"
541  "# addps %%xmmZ, %%xmmA\n\t"
542  "# addps %%xmmA, %%xmmC\n\t"
543  "# A=xmm0, B=xmm2, Z=xmm4\n\t"
544  "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t"
545  " movaps 16(%%r9), %%xmm1\n\t"
546  " movaps %%xmm0, %%xmm4\n\t"
547  " mulps %%xmm2, %%xmm0\n\t"
548  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
549  " movaps 16(%%r10), %%xmm3\n\t"
550  " movaps %%xmm1, %%xmm5\n\t"
551  " addps %%xmm0, %%xmm6\n\t"
552  " mulps %%xmm3, %%xmm1\n\t"
553  " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t"
554  " addps %%xmm1, %%xmm6\n\t"
555  " mulps %%xmm4, %%xmm2\n\t"
556  " movaps 32(%%r9), %%xmm0\n\t"
557  " addps %%xmm2, %%xmm7\n\t"
558  " mulps %%xmm5, %%xmm3\n\t"
559  " add $32, %%r9\n\t"
560  " movaps 32(%%r10), %%xmm2\n\t"
561  " addps %%xmm3, %%xmm7\n\t"
562  " add $32, %%r10\n\t"
563  ".%=L1_test:\n\t"
564  " dec %%rax\n\t"
565  " jge .%=Loop1\n\t"
566  " # We've handled the bulk of multiplies up to here.\n\t"
567  " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t"
568  " # If so, we've got 2 more taps to do.\n\t"
569  " and $1, %%r8\n\t"
570  " je .%=Leven\n\t"
571  " # The count was odd, do 2 more taps.\n\t"
572  " # Note that we've already got mm0/mm2 preloaded\n\t"
573  " # from the main loop.\n\t"
574  " movaps %%xmm0, %%xmm4\n\t"
575  " mulps %%xmm2, %%xmm0\n\t"
576  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
577  " addps %%xmm0, %%xmm6\n\t"
578  " mulps %%xmm4, %%xmm2\n\t"
579  " addps %%xmm2, %%xmm7\n\t"
580  ".%=Leven:\n\t"
581  " # neg inversor\n\t"
582  " xorps %%xmm1, %%xmm1\n\t"
583  " mov $0x80000000, %%r9\n\t"
584  " movd %%r9, %%xmm1\n\t"
585  " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t"
586  " # pfpnacc\n\t"
587  " xorps %%xmm1, %%xmm6\n\t"
588  " movaps %%xmm6, %%xmm2\n\t"
589  " unpcklps %%xmm7, %%xmm6\n\t"
590  " unpckhps %%xmm7, %%xmm2\n\t"
591  " movaps %%xmm2, %%xmm3\n\t"
592  " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t"
593  " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t"
594  " addps %%xmm2, %%xmm6\n\t"
595  " # xmm6 = r1 i2 r3 i4\n\t"
596  " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t"
597  " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t"
598  " movlps %%xmm6, (%[rdi]) # store low 2x32 bits (complex) to memory\n\t"
599  :
600  :[rsi] "r" (input), [rdx] "r" (taps), "c" (num_bytes), [rdi] "r" (result)
601  :"rax", "r8", "r9", "r10"
602  );
603 
604 
605  if(isodd) {
606  *result += input[num_points - 1] * taps[num_points - 1];
607  }
608 
609  return;
610 
611 }
612 
613 #endif
614 
615 #if LV_HAVE_SSE && LV_HAVE_32
616 
617 static inline void volk_32fc_x2_dot_prod_32fc_a_sse_32(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
618 
619  volk_32fc_x2_dot_prod_32fc_a_generic(result, input, taps, num_points);
620 
621 #if 0
622  const unsigned int num_bytes = num_points*8;
623  unsigned int isodd = num_points & 1;
624 
625  asm volatile
626  (
627  " #pushl %%ebp\n\t"
628  " #movl %%esp, %%ebp\n\t"
629  " movl 12(%%ebp), %%eax # input\n\t"
630  " movl 16(%%ebp), %%edx # taps\n\t"
631  " movl 20(%%ebp), %%ecx # n_bytes\n\t"
632  " xorps %%xmm6, %%xmm6 # zero accumulators\n\t"
633  " movaps 0(%%eax), %%xmm0\n\t"
634  " xorps %%xmm7, %%xmm7 # zero accumulators\n\t"
635  " movaps 0(%%edx), %%xmm2\n\t"
636  " shrl $5, %%ecx # ecx = n_2_ccomplex_blocks / 2\n\t"
637  " jmp .%=L1_test\n\t"
638  " # 4 taps / loop\n\t"
639  " # something like ?? cycles / loop\n\t"
640  ".%=Loop1: \n\t"
641  "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t"
642  "# movaps (%%eax), %%xmmA\n\t"
643  "# movaps (%%edx), %%xmmB\n\t"
644  "# movaps %%xmmA, %%xmmZ\n\t"
645  "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t"
646  "# mulps %%xmmB, %%xmmA\n\t"
647  "# mulps %%xmmZ, %%xmmB\n\t"
648  "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t"
649  "# xorps %%xmmPN, %%xmmA\n\t"
650  "# movaps %%xmmA, %%xmmZ\n\t"
651  "# unpcklps %%xmmB, %%xmmA\n\t"
652  "# unpckhps %%xmmB, %%xmmZ\n\t"
653  "# movaps %%xmmZ, %%xmmY\n\t"
654  "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t"
655  "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t"
656  "# addps %%xmmZ, %%xmmA\n\t"
657  "# addps %%xmmA, %%xmmC\n\t"
658  "# A=xmm0, B=xmm2, Z=xmm4\n\t"
659  "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t"
660  " movaps 16(%%eax), %%xmm1\n\t"
661  " movaps %%xmm0, %%xmm4\n\t"
662  " mulps %%xmm2, %%xmm0\n\t"
663  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
664  " movaps 16(%%edx), %%xmm3\n\t"
665  " movaps %%xmm1, %%xmm5\n\t"
666  " addps %%xmm0, %%xmm6\n\t"
667  " mulps %%xmm3, %%xmm1\n\t"
668  " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t"
669  " addps %%xmm1, %%xmm6\n\t"
670  " mulps %%xmm4, %%xmm2\n\t"
671  " movaps 32(%%eax), %%xmm0\n\t"
672  " addps %%xmm2, %%xmm7\n\t"
673  " mulps %%xmm5, %%xmm3\n\t"
674  " addl $32, %%eax\n\t"
675  " movaps 32(%%edx), %%xmm2\n\t"
676  " addps %%xmm3, %%xmm7\n\t"
677  " addl $32, %%edx\n\t"
678  ".%=L1_test:\n\t"
679  " decl %%ecx\n\t"
680  " jge .%=Loop1\n\t"
681  " # We've handled the bulk of multiplies up to here.\n\t"
682  " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t"
683  " # If so, we've got 2 more taps to do.\n\t"
684  " movl 20(%%ebp), %%ecx # n_2_ccomplex_blocks\n\t"
685  " shrl $4, %%ecx\n\t"
686  " andl $1, %%ecx\n\t"
687  " je .%=Leven\n\t"
688  " # The count was odd, do 2 more taps.\n\t"
689  " # Note that we've already got mm0/mm2 preloaded\n\t"
690  " # from the main loop.\n\t"
691  " movaps %%xmm0, %%xmm4\n\t"
692  " mulps %%xmm2, %%xmm0\n\t"
693  " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
694  " addps %%xmm0, %%xmm6\n\t"
695  " mulps %%xmm4, %%xmm2\n\t"
696  " addps %%xmm2, %%xmm7\n\t"
697  ".%=Leven:\n\t"
698  " # neg inversor\n\t"
699  " movl 8(%%ebp), %%eax \n\t"
700  " xorps %%xmm1, %%xmm1\n\t"
701  " movl $0x80000000, (%%eax)\n\t"
702  " movss (%%eax), %%xmm1\n\t"
703  " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t"
704  " # pfpnacc\n\t"
705  " xorps %%xmm1, %%xmm6\n\t"
706  " movaps %%xmm6, %%xmm2\n\t"
707  " unpcklps %%xmm7, %%xmm6\n\t"
708  " unpckhps %%xmm7, %%xmm2\n\t"
709  " movaps %%xmm2, %%xmm3\n\t"
710  " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t"
711  " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t"
712  " addps %%xmm2, %%xmm6\n\t"
713  " # xmm6 = r1 i2 r3 i4\n\t"
714  " #movl 8(%%ebp), %%eax # @result\n\t"
715  " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t"
716  " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t"
717  " movlps %%xmm6, (%%eax) # store low 2x32 bits (complex) to memory\n\t"
718  " #popl %%ebp\n\t"
719  :
720  :
721  : "eax", "ecx", "edx"
722  );
723 
724 
725  int getem = num_bytes % 16;
726 
727  if(isodd) {
728  *result += (input[num_points - 1] * taps[num_points - 1]);
729  }
730 
731  return;
732 #endif
733 }
734 
735 #endif /*LV_HAVE_SSE*/
736 
737 #ifdef LV_HAVE_SSE3
738 
739 #include <pmmintrin.h>
740 
741 static inline void volk_32fc_x2_dot_prod_32fc_a_sse3(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
742 
743  const unsigned int num_bytes = num_points*8;
744  unsigned int isodd = num_points & 1;
745 
746  lv_32fc_t dotProduct;
747  memset(&dotProduct, 0x0, 2*sizeof(float));
748 
749  unsigned int number = 0;
750  const unsigned int halfPoints = num_bytes >> 4;
751 
752  __m128 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
753 
754  const lv_32fc_t* a = input;
755  const lv_32fc_t* b = taps;
756 
757  dotProdVal = _mm_setzero_ps();
758 
759  for(;number < halfPoints; number++){
760 
761  x = _mm_load_ps((float*)a); // Load the ar + ai, br + bi as ar,ai,br,bi
762  y = _mm_load_ps((float*)b); // Load the cr + ci, dr + di as cr,ci,dr,di
763 
764  yl = _mm_moveldup_ps(y); // Load yl with cr,cr,dr,dr
765  yh = _mm_movehdup_ps(y); // Load yh with ci,ci,di,di
766 
767  tmp1 = _mm_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr
768 
769  x = _mm_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br
770 
771  tmp2 = _mm_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di
772 
773  z = _mm_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
774 
775  dotProdVal = _mm_add_ps(dotProdVal, z); // Add the complex multiplication results together
776 
777  a += 2;
778  b += 2;
779  }
780 
781  __VOLK_ATTR_ALIGNED(16) lv_32fc_t dotProductVector[2];
782 
783  _mm_store_ps((float*)dotProductVector,dotProdVal); // Store the results back into the dot product vector
784 
785  dotProduct += ( dotProductVector[0] + dotProductVector[1] );
786 
787  if(isodd) {
788  dotProduct += input[num_points - 1] * taps[num_points - 1];
789  }
790 
791  *result = dotProduct;
792 }
793 
794 #endif /*LV_HAVE_SSE3*/
795 
796 
797 #ifdef LV_HAVE_SSE4_1
798 
799 #include <smmintrin.h>
800 
801 static inline void volk_32fc_x2_dot_prod_32fc_a_sse4_1(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
802 
803  unsigned int i = 0;
804  const unsigned int qtr_points = num_points/4;
805  const unsigned int isodd = num_points & 3;
806 
807  __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, real0, real1, im0, im1;
808  float *p_input, *p_taps;
809  __m64 *p_result;
810 
811  static const __m128i neg = {0x000000000000000080000000};
812 
813  p_result = (__m64*)result;
814  p_input = (float*)input;
815  p_taps = (float*)taps;
816 
817  real0 = _mm_setzero_ps();
818  real1 = _mm_setzero_ps();
819  im0 = _mm_setzero_ps();
820  im1 = _mm_setzero_ps();
821 
822  for(; i < qtr_points; ++i) {
823  xmm0 = _mm_load_ps(p_input);
824  xmm1 = _mm_load_ps(p_taps);
825 
826  p_input += 4;
827  p_taps += 4;
828 
829  xmm2 = _mm_load_ps(p_input);
830  xmm3 = _mm_load_ps(p_taps);
831 
832  p_input += 4;
833  p_taps += 4;
834 
835  xmm4 = _mm_unpackhi_ps(xmm0, xmm2);
836  xmm5 = _mm_unpackhi_ps(xmm1, xmm3);
837  xmm0 = _mm_unpacklo_ps(xmm0, xmm2);
838  xmm2 = _mm_unpacklo_ps(xmm1, xmm3);
839 
840  //imaginary vector from input
841  xmm1 = _mm_unpackhi_ps(xmm0, xmm4);
842  //real vector from input
843  xmm3 = _mm_unpacklo_ps(xmm0, xmm4);
844  //imaginary vector from taps
845  xmm0 = _mm_unpackhi_ps(xmm2, xmm5);
846  //real vector from taps
847  xmm2 = _mm_unpacklo_ps(xmm2, xmm5);
848 
849  xmm4 = _mm_dp_ps(xmm3, xmm2, 0xf1);
850  xmm5 = _mm_dp_ps(xmm1, xmm0, 0xf1);
851 
852  xmm6 = _mm_dp_ps(xmm3, xmm0, 0xf2);
853  xmm7 = _mm_dp_ps(xmm1, xmm2, 0xf2);
854 
855  real0 = _mm_add_ps(xmm4, real0);
856  real1 = _mm_add_ps(xmm5, real1);
857  im0 = _mm_add_ps(xmm6, im0);
858  im1 = _mm_add_ps(xmm7, im1);
859  }
860 
861  real1 = _mm_xor_ps(real1, bit128_p(&neg)->float_vec);
862 
863  im0 = _mm_add_ps(im0, im1);
864  real0 = _mm_add_ps(real0, real1);
865 
866  im0 = _mm_add_ps(im0, real0);
867 
868  _mm_storel_pi(p_result, im0);
869 
870  for(i = num_points-isodd; i < num_points; i++) {
871  *result += input[i] * taps[i];
872  }
873 }
874 
875 #endif /*LV_HAVE_SSE4_1*/
876 
877 #ifdef LV_HAVE_NEON
878 #include <arm_neon.h>
879 
880 static inline void volk_32fc_x2_dot_prod_32fc_neon(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
881 
882  unsigned int quarter_points = num_points / 4;
883  unsigned int number;
884 
885  lv_32fc_t* a_ptr = (lv_32fc_t*) taps;
886  lv_32fc_t* b_ptr = (lv_32fc_t*) input;
887  // for 2-lane vectors, 1st lane holds the real part,
888  // 2nd lane holds the imaginary part
889  float32x4x2_t a_val, b_val, c_val, accumulator;
890  float32x4x2_t tmp_real, tmp_imag;
891  accumulator.val[0] = vdupq_n_f32(0);
892  accumulator.val[1] = vdupq_n_f32(0);
893 
894  for(number = 0; number < quarter_points; ++number) {
895  a_val = vld2q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
896  b_val = vld2q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
897  __builtin_prefetch(a_ptr+8);
898  __builtin_prefetch(b_ptr+8);
899 
900  // multiply the real*real and imag*imag to get real result
901  // a0r*b0r|a1r*b1r|a2r*b2r|a3r*b3r
902  tmp_real.val[0] = vmulq_f32(a_val.val[0], b_val.val[0]);
903  // a0i*b0i|a1i*b1i|a2i*b2i|a3i*b3i
904  tmp_real.val[1] = vmulq_f32(a_val.val[1], b_val.val[1]);
905 
906  // Multiply cross terms to get the imaginary result
907  // a0r*b0i|a1r*b1i|a2r*b2i|a3r*b3i
908  tmp_imag.val[0] = vmulq_f32(a_val.val[0], b_val.val[1]);
909  // a0i*b0r|a1i*b1r|a2i*b2r|a3i*b3r
910  tmp_imag.val[1] = vmulq_f32(a_val.val[1], b_val.val[0]);
911 
912  c_val.val[0] = vsubq_f32(tmp_real.val[0], tmp_real.val[1]);
913  c_val.val[1] = vaddq_f32(tmp_imag.val[0], tmp_imag.val[1]);
914 
915  accumulator.val[0] = vaddq_f32(accumulator.val[0], c_val.val[0]);
916  accumulator.val[1] = vaddq_f32(accumulator.val[1], c_val.val[1]);
917 
918  a_ptr += 4;
919  b_ptr += 4;
920  }
921  lv_32fc_t accum_result[4];
922  vst2q_f32((float*)accum_result, accumulator);
923  *result = accum_result[0] + accum_result[1] + accum_result[2] + accum_result[3];
924 
925  // tail case
926  for(number = quarter_points*4; number < num_points; ++number) {
927  *result += (*a_ptr++) * (*b_ptr++);
928  }
929 
930 }
931 #endif /*LV_HAVE_NEON*/
932 
933 #ifdef LV_HAVE_NEON
934 #include <arm_neon.h>
935 static inline void volk_32fc_x2_dot_prod_32fc_neon_opttests(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
936 
937  unsigned int quarter_points = num_points / 4;
938  unsigned int number;
939 
940  lv_32fc_t* a_ptr = (lv_32fc_t*) taps;
941  lv_32fc_t* b_ptr = (lv_32fc_t*) input;
942  // for 2-lane vectors, 1st lane holds the real part,
943  // 2nd lane holds the imaginary part
944  float32x4x2_t a_val, b_val, accumulator;
945  float32x4x2_t tmp_imag;
946  accumulator.val[0] = vdupq_n_f32(0);
947  accumulator.val[1] = vdupq_n_f32(0);
948 
949  for(number = 0; number < quarter_points; ++number) {
950  a_val = vld2q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
951  b_val = vld2q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
952  __builtin_prefetch(a_ptr+8);
953  __builtin_prefetch(b_ptr+8);
954 
955  // do the first multiply
956  tmp_imag.val[1] = vmulq_f32(a_val.val[1], b_val.val[0]);
957  tmp_imag.val[0] = vmulq_f32(a_val.val[0], b_val.val[0]);
958 
959  // use multiply accumulate/subtract to get result
960  tmp_imag.val[1] = vmlaq_f32(tmp_imag.val[1], a_val.val[0], b_val.val[1]);
961  tmp_imag.val[0] = vmlsq_f32(tmp_imag.val[0], a_val.val[1], b_val.val[1]);
962 
963  accumulator.val[0] = vaddq_f32(accumulator.val[0], tmp_imag.val[0]);
964  accumulator.val[1] = vaddq_f32(accumulator.val[1], tmp_imag.val[1]);
965 
966  // increment pointers
967  a_ptr += 4;
968  b_ptr += 4;
969  }
970  lv_32fc_t accum_result[4];
971  vst2q_f32((float*)accum_result, accumulator);
972  *result = accum_result[0] + accum_result[1] + accum_result[2] + accum_result[3];
973 
974  // tail case
975  for(number = quarter_points*4; number < num_points; ++number) {
976  *result += (*a_ptr++) * (*b_ptr++);
977  }
978 
979 }
980 #endif /*LV_HAVE_NEON*/
981 
982 #ifdef LV_HAVE_NEON
983 static inline void volk_32fc_x2_dot_prod_32fc_neon_optfma(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
984 
985  unsigned int quarter_points = num_points / 4;
986  unsigned int number;
987 
988  lv_32fc_t* a_ptr = (lv_32fc_t*) taps;
989  lv_32fc_t* b_ptr = (lv_32fc_t*) input;
990  // for 2-lane vectors, 1st lane holds the real part,
991  // 2nd lane holds the imaginary part
992  float32x4x2_t a_val, b_val, accumulator1, accumulator2;
993  accumulator1.val[0] = vdupq_n_f32(0);
994  accumulator1.val[1] = vdupq_n_f32(0);
995  accumulator2.val[0] = vdupq_n_f32(0);
996  accumulator2.val[1] = vdupq_n_f32(0);
997 
998  for(number = 0; number < quarter_points; ++number) {
999  a_val = vld2q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
1000  b_val = vld2q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
1001  __builtin_prefetch(a_ptr+8);
1002  __builtin_prefetch(b_ptr+8);
1003 
1004  // use 2 accumulators to remove inter-instruction data dependencies
1005  accumulator1.val[0] = vmlaq_f32(accumulator1.val[0], a_val.val[0], b_val.val[0]);
1006  accumulator1.val[1] = vmlaq_f32(accumulator1.val[1], a_val.val[0], b_val.val[1]);
1007  accumulator2.val[0] = vmlsq_f32(accumulator2.val[0], a_val.val[1], b_val.val[1]);
1008  accumulator2.val[1] = vmlaq_f32(accumulator2.val[1], a_val.val[1], b_val.val[0]);
1009  // increment pointers
1010  a_ptr += 4;
1011  b_ptr += 4;
1012  }
1013  accumulator1.val[0] = vaddq_f32(accumulator1.val[0], accumulator2.val[0]);
1014  accumulator1.val[1] = vaddq_f32(accumulator1.val[1], accumulator2.val[1]);
1015  lv_32fc_t accum_result[4];
1016  vst2q_f32((float*)accum_result, accumulator1);
1017  *result = accum_result[0] + accum_result[1] + accum_result[2] + accum_result[3];
1018 
1019  // tail case
1020  for(number = quarter_points*4; number < num_points; ++number) {
1021  *result += (*a_ptr++) * (*b_ptr++);
1022  }
1023 
1024 }
1025 #endif /*LV_HAVE_NEON*/
1026 
1027 #ifdef LV_HAVE_NEON
1028 static inline void volk_32fc_x2_dot_prod_32fc_neon_optfmaunroll(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
1029 // NOTE: GCC does a poor job with this kernel, but the euivalent ASM code is very fast
1030 
1031  unsigned int quarter_points = num_points / 8;
1032  unsigned int number;
1033 
1034  lv_32fc_t* a_ptr = (lv_32fc_t*) taps;
1035  lv_32fc_t* b_ptr = (lv_32fc_t*) input;
1036  // for 2-lane vectors, 1st lane holds the real part,
1037  // 2nd lane holds the imaginary part
1038  float32x4x4_t a_val, b_val, accumulator1, accumulator2;
1039  float32x4x2_t reduced_accumulator;
1040  accumulator1.val[0] = vdupq_n_f32(0);
1041  accumulator1.val[1] = vdupq_n_f32(0);
1042  accumulator1.val[2] = vdupq_n_f32(0);
1043  accumulator1.val[3] = vdupq_n_f32(0);
1044  accumulator2.val[0] = vdupq_n_f32(0);
1045  accumulator2.val[1] = vdupq_n_f32(0);
1046  accumulator2.val[2] = vdupq_n_f32(0);
1047  accumulator2.val[3] = vdupq_n_f32(0);
1048 
1049  // 8 input regs, 8 accumulators -> 16/16 neon regs are used
1050  for(number = 0; number < quarter_points; ++number) {
1051  a_val = vld4q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
1052  b_val = vld4q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
1053  __builtin_prefetch(a_ptr+8);
1054  __builtin_prefetch(b_ptr+8);
1055 
1056  // use 2 accumulators to remove inter-instruction data dependencies
1057  accumulator1.val[0] = vmlaq_f32(accumulator1.val[0], a_val.val[0], b_val.val[0]);
1058  accumulator1.val[1] = vmlaq_f32(accumulator1.val[1], a_val.val[0], b_val.val[1]);
1059 
1060  accumulator1.val[2] = vmlaq_f32(accumulator1.val[2], a_val.val[2], b_val.val[2]);
1061  accumulator1.val[3] = vmlaq_f32(accumulator1.val[3], a_val.val[2], b_val.val[3]);
1062 
1063  accumulator2.val[0] = vmlsq_f32(accumulator2.val[0], a_val.val[1], b_val.val[1]);
1064  accumulator2.val[1] = vmlaq_f32(accumulator2.val[1], a_val.val[1], b_val.val[0]);
1065 
1066  accumulator2.val[2] = vmlsq_f32(accumulator2.val[2], a_val.val[3], b_val.val[3]);
1067  accumulator2.val[3] = vmlaq_f32(accumulator2.val[3], a_val.val[3], b_val.val[2]);
1068  // increment pointers
1069  a_ptr += 8;
1070  b_ptr += 8;
1071  }
1072  // reduce 8 accumulator lanes down to 2 (1 real and 1 imag)
1073  accumulator1.val[0] = vaddq_f32(accumulator1.val[0], accumulator1.val[2]);
1074  accumulator1.val[1] = vaddq_f32(accumulator1.val[1], accumulator1.val[3]);
1075  accumulator2.val[0] = vaddq_f32(accumulator2.val[0], accumulator2.val[2]);
1076  accumulator2.val[1] = vaddq_f32(accumulator2.val[1], accumulator2.val[3]);
1077  reduced_accumulator.val[0] = vaddq_f32(accumulator1.val[0], accumulator2.val[0]);
1078  reduced_accumulator.val[1] = vaddq_f32(accumulator1.val[1], accumulator2.val[1]);
1079  // now reduce accumulators to scalars
1080  lv_32fc_t accum_result[4];
1081  vst2q_f32((float*)accum_result, reduced_accumulator);
1082  *result = accum_result[0] + accum_result[1] + accum_result[2] + accum_result[3];
1083 
1084  // tail case
1085  for(number = quarter_points*8; number < num_points; ++number) {
1086  *result += (*a_ptr++) * (*b_ptr++);
1087  }
1088 
1089 }
1090 #endif /*LV_HAVE_NEON*/
1091 
1092 
1093 #ifdef LV_HAVE_AVX
1094 
1095 #include <immintrin.h>
1096 
1097 static inline void volk_32fc_x2_dot_prod_32fc_a_avx(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_points) {
1098 
1099  unsigned int isodd = num_points & 3;
1100  unsigned int i = 0;
1101  lv_32fc_t dotProduct;
1102  memset(&dotProduct, 0x0, 2*sizeof(float));
1103 
1104  unsigned int number = 0;
1105  const unsigned int quarterPoints = num_points / 4;
1106 
1107  __m256 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
1108 
1109  const lv_32fc_t* a = input;
1110  const lv_32fc_t* b = taps;
1111 
1112  dotProdVal = _mm256_setzero_ps();
1113 
1114  for(;number < quarterPoints; number++){
1115 
1116  x = _mm256_load_ps((float*)a); // Load a,b,e,f as ar,ai,br,bi,er,ei,fr,fi
1117  y = _mm256_load_ps((float*)b); // Load c,d,g,h as cr,ci,dr,di,gr,gi,hr,hi
1118 
1119  yl = _mm256_moveldup_ps(y); // Load yl with cr,cr,dr,dr,gr,gr,hr,hr
1120  yh = _mm256_movehdup_ps(y); // Load yh with ci,ci,di,di,gi,gi,hi,hi
1121 
1122  tmp1 = _mm256_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr ...
1123 
1124  x = _mm256_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br,ei,er,fi,fr
1125 
1126  tmp2 = _mm256_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di ...
1127 
1128  z = _mm256_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
1129 
1130  dotProdVal = _mm256_add_ps(dotProdVal, z); // Add the complex multiplication results together
1131 
1132  a += 4;
1133  b += 4;
1134  }
1135 
1136  __VOLK_ATTR_ALIGNED(32) lv_32fc_t dotProductVector[4];
1137 
1138  _mm256_store_ps((float*)dotProductVector,dotProdVal); // Store the results back into the dot product vector
1139 
1140  dotProduct += ( dotProductVector[0] + dotProductVector[1] + dotProductVector[2] + dotProductVector[3]);
1141 
1142  for(i = num_points-isodd; i < num_points; i++) {
1143  dotProduct += input[i] * taps[i];
1144  }
1145 
1146  *result = dotProduct;
1147 }
1148 
1149 #endif /*LV_HAVE_AVX*/
1150 
1151 #endif /*INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H*/
#define bit128_p(x)
Definition: volk_common.h:94
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:27
static const float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
float complex lv_32fc_t
Definition: volk_complex.h:56