GNU Radio Manual and C++ API Reference  3.7.5.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
volk_32fc_x2_multiply_32fc.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32fc_x2_multiply_32fc_u_H
2 #define INCLUDED_volk_32fc_x2_multiply_32fc_u_H
3 
4 #include <inttypes.h>
5 #include <stdio.h>
6 #include <volk/volk_complex.h>
7 #include <float.h>
8 
9 #ifdef LV_HAVE_SSE3
10 #include <pmmintrin.h>
11  /*!
12  \brief Multiplies the two input complex vectors and stores their results in the third vector
13  \param cVector The vector where the results will be stored
14  \param aVector One of the vectors to be multiplied
15  \param bVector One of the vectors to be multiplied
16  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
17  */
18 static inline void volk_32fc_x2_multiply_32fc_u_sse3(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
19  unsigned int number = 0;
20  const unsigned int halfPoints = num_points / 2;
21 
22  __m128 x, y, yl, yh, z, tmp1, tmp2;
23  lv_32fc_t* c = cVector;
24  const lv_32fc_t* a = aVector;
25  const lv_32fc_t* b = bVector;
26 
27  for(;number < halfPoints; number++){
28 
29  x = _mm_loadu_ps((float*)a); // Load the ar + ai, br + bi as ar,ai,br,bi
30  y = _mm_loadu_ps((float*)b); // Load the cr + ci, dr + di as cr,ci,dr,di
31 
32  yl = _mm_moveldup_ps(y); // Load yl with cr,cr,dr,dr
33  yh = _mm_movehdup_ps(y); // Load yh with ci,ci,di,di
34 
35  tmp1 = _mm_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr
36 
37  x = _mm_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br
38 
39  tmp2 = _mm_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di
40 
41  z = _mm_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
42 
43  _mm_storeu_ps((float*)c,z); // Store the results back into the C container
44 
45  a += 2;
46  b += 2;
47  c += 2;
48  }
49 
50  if((num_points % 2) != 0) {
51  *c = (*a) * (*b);
52  }
53 }
54 #endif /* LV_HAVE_SSE */
55 
56 #ifdef LV_HAVE_GENERIC
57  /*!
58  \brief Multiplies the two input complex vectors and stores their results in the third vector
59  \param cVector The vector where the results will be stored
60  \param aVector One of the vectors to be multiplied
61  \param bVector One of the vectors to be multiplied
62  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
63  */
64 static inline void volk_32fc_x2_multiply_32fc_generic(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
65  lv_32fc_t* cPtr = cVector;
66  const lv_32fc_t* aPtr = aVector;
67  const lv_32fc_t* bPtr= bVector;
68  unsigned int number = 0;
69 
70  for(number = 0; number < num_points; number++){
71  *cPtr++ = (*aPtr++) * (*bPtr++);
72  }
73 }
74 #endif /* LV_HAVE_GENERIC */
75 
76 
77 #endif /* INCLUDED_volk_32fc_x2_multiply_32fc_u_H */
78 #ifndef INCLUDED_volk_32fc_x2_multiply_32fc_a_H
79 #define INCLUDED_volk_32fc_x2_multiply_32fc_a_H
80 
81 #include <inttypes.h>
82 #include <stdio.h>
83 #include <volk/volk_complex.h>
84 #include <float.h>
85 
86 #ifdef LV_HAVE_SSE3
87 #include <pmmintrin.h>
88  /*!
89  \brief Multiplies the two input complex vectors and stores their results in the third vector
90  \param cVector The vector where the results will be stored
91  \param aVector One of the vectors to be multiplied
92  \param bVector One of the vectors to be multiplied
93  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
94  */
95 static inline void volk_32fc_x2_multiply_32fc_a_sse3(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
96  unsigned int number = 0;
97  const unsigned int halfPoints = num_points / 2;
98 
99  __m128 x, y, yl, yh, z, tmp1, tmp2;
100  lv_32fc_t* c = cVector;
101  const lv_32fc_t* a = aVector;
102  const lv_32fc_t* b = bVector;
103  for(;number < halfPoints; number++){
104 
105  x = _mm_load_ps((float*)a); // Load the ar + ai, br + bi as ar,ai,br,bi
106  y = _mm_load_ps((float*)b); // Load the cr + ci, dr + di as cr,ci,dr,di
107 
108  yl = _mm_moveldup_ps(y); // Load yl with cr,cr,dr,dr
109  yh = _mm_movehdup_ps(y); // Load yh with ci,ci,di,di
110 
111  tmp1 = _mm_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr
112 
113  x = _mm_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br
114 
115  tmp2 = _mm_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di
116 
117  z = _mm_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di
118 
119  _mm_store_ps((float*)c,z); // Store the results back into the C container
120 
121  a += 2;
122  b += 2;
123  c += 2;
124  }
125 
126  if((num_points % 2) != 0) {
127  *c = (*a) * (*b);
128  }
129 }
130 #endif /* LV_HAVE_SSE */
131 
132 #ifdef LV_HAVE_GENERIC
133  /*!
134  \brief Multiplies the two input complex vectors and stores their results in the third vector
135  \param cVector The vector where the results will be stored
136  \param aVector One of the vectors to be multiplied
137  \param bVector One of the vectors to be multiplied
138  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
139  */
140 static inline void volk_32fc_x2_multiply_32fc_a_generic(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
141  lv_32fc_t* cPtr = cVector;
142  const lv_32fc_t* aPtr = aVector;
143  const lv_32fc_t* bPtr= bVector;
144  unsigned int number = 0;
145 
146  for(number = 0; number < num_points; number++){
147  *cPtr++ = (*aPtr++) * (*bPtr++);
148  }
149 }
150 #endif /* LV_HAVE_GENERIC */
151 
152 #ifdef LV_HAVE_NEON
153 #include <arm_neon.h>
154 
155  /*!
156  \brief Multiplies the two input complex vectors and stores their results in the third vector
157  \param cVector The vector where the results will be stored
158  \param aVector One of the vectors to be multiplied
159  \param bVector One of the vectors to be multiplied
160  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
161  */
162 static inline void volk_32fc_x2_multiply_32fc_neon(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
163 
164  lv_32fc_t *a_ptr = (lv_32fc_t*) aVector;
165  lv_32fc_t *b_ptr = (lv_32fc_t*) bVector;
166  unsigned int quarter_points = num_points / 4;
167  float32x4x2_t a_val, b_val, c_val;
168  float32x4x2_t tmp_real, tmp_imag;
169  unsigned int number = 0;
170 
171  for(number = 0; number < quarter_points; ++number) {
172  a_val = vld2q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
173  b_val = vld2q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
174  __builtin_prefetch(a_ptr+4);
175  __builtin_prefetch(b_ptr+4);
176 
177  // multiply the real*real and imag*imag to get real result
178  // a0r*b0r|a1r*b1r|a2r*b2r|a3r*b3r
179  tmp_real.val[0] = vmulq_f32(a_val.val[0], b_val.val[0]);
180  // a0i*b0i|a1i*b1i|a2i*b2i|a3i*b3i
181  tmp_real.val[1] = vmulq_f32(a_val.val[1], b_val.val[1]);
182 
183  // Multiply cross terms to get the imaginary result
184  // a0r*b0i|a1r*b1i|a2r*b2i|a3r*b3i
185  tmp_imag.val[0] = vmulq_f32(a_val.val[0], b_val.val[1]);
186  // a0i*b0r|a1i*b1r|a2i*b2r|a3i*b3r
187  tmp_imag.val[1] = vmulq_f32(a_val.val[1], b_val.val[0]);
188 
189  // store the results
190  c_val.val[0] = vsubq_f32(tmp_real.val[0], tmp_real.val[1]);
191  c_val.val[1] = vaddq_f32(tmp_imag.val[0], tmp_imag.val[1]);
192  vst2q_f32((float*)cVector, c_val);
193 
194  a_ptr += 4;
195  b_ptr += 4;
196  cVector += 4;
197  }
198 
199  for(number = quarter_points*4; number < num_points; number++){
200  *cVector++ = (*a_ptr++) * (*b_ptr++);
201  }
202 
203 }
204 #endif /* LV_HAVE_NEON */
205 
206 #ifdef LV_HAVE_NEON
207  /*!
208  \brief Multiplies the two input complex vectors and stores their results in the third vector
209  \param cVector The vector where the results will be stored
210  \param aVector One of the vectors to be multiplied
211  \param bVector One of the vectors to be multiplied
212  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
213  */
214 static inline void volk_32fc_x2_multiply_32fc_neon_opttests(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
215 
216  lv_32fc_t *a_ptr = (lv_32fc_t*) aVector;
217  lv_32fc_t *b_ptr = (lv_32fc_t*) bVector;
218  unsigned int quarter_points = num_points / 4;
219  float32x4x2_t a_val, b_val;
220  float32x4x2_t tmp_imag;
221  unsigned int number = 0;
222 
223  for(number = 0; number < quarter_points; ++number) {
224  a_val = vld2q_f32((float*)a_ptr); // a0r|a1r|a2r|a3r || a0i|a1i|a2i|a3i
225  b_val = vld2q_f32((float*)b_ptr); // b0r|b1r|b2r|b3r || b0i|b1i|b2i|b3i
226  __builtin_prefetch(a_ptr+4);
227  __builtin_prefetch(b_ptr+4);
228 
229  // do the first multiply
230  tmp_imag.val[1] = vmulq_f32(a_val.val[1], b_val.val[0]);
231  tmp_imag.val[0] = vmulq_f32(a_val.val[0], b_val.val[0]);
232 
233  // use multiply accumulate/subtract to get result
234  tmp_imag.val[1] = vmlaq_f32(tmp_imag.val[1], a_val.val[0], b_val.val[1]);
235  tmp_imag.val[0] = vmlsq_f32(tmp_imag.val[0], a_val.val[1], b_val.val[1]);
236 
237  // store
238  vst2q_f32((float*)cVector, tmp_imag);
239  // increment pointers
240  a_ptr += 4;
241  b_ptr += 4;
242  cVector += 4;
243  }
244 
245  for(number = quarter_points*4; number < num_points; number++){
246  *cVector++ = (*a_ptr++) * (*b_ptr++);
247  }
248 
249 }
250 #endif /* LV_HAVE_NEON */
251 
252 #ifdef LV_HAVE_NEON
253  /*!
254  \brief Multiplies the two input complex vectors and stores their results in the third vector
255  \param cVector The vector where the results will be stored
256  \param aVector One of the vectors to be multiplied
257  \param bVector One of the vectors to be multiplied
258  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
259  */
260 extern void volk_32fc_x2_multiply_32fc_neonasm(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points);
261 #endif /* LV_HAVE_NEON */
262 
263 #ifdef LV_HAVE_ORC
264  /*!
265  \brief Multiplies the two input complex vectors and stores their results in the third vector
266  \param cVector The vector where the results will be stored
267  \param aVector One of the vectors to be multiplied
268  \param bVector One of the vectors to be multiplied
269  \param num_points The number of complex values in aVector and bVector to be multiplied together and stored into cVector
270  */
271 extern void volk_32fc_x2_multiply_32fc_a_orc_impl(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points);
272 static inline void volk_32fc_x2_multiply_32fc_u_orc(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points){
273  volk_32fc_x2_multiply_32fc_a_orc_impl(cVector, aVector, bVector, num_points);
274 }
275 #endif /* LV_HAVE_ORC */
276 
277 
278 
279 
280 
281 #endif /* INCLUDED_volk_32fc_x2_multiply_32fc_a_H */
float complex lv_32fc_t
Definition: volk_complex.h:56