1 #ifndef INCLUDED_volk_32fc_x2_dot_prod_32fc_u_H
2 #define INCLUDED_volk_32fc_x2_dot_prod_32fc_u_H
10 #ifdef LV_HAVE_GENERIC
15 float * res = (
float*) result;
16 float * in = (
float*) input;
17 float * tp = (
float*) taps;
18 unsigned int n_2_ccomplex_blocks = num_points/2;
19 unsigned int isodd = num_points &1;
23 float sum0[2] = {0,0};
24 float sum1[2] = {0,0};
28 for(i = 0; i < n_2_ccomplex_blocks; ++i) {
31 sum0[0] += in[0] * tp[0] - in[1] * tp[1];
32 sum0[1] += in[0] * tp[1] + in[1] * tp[0];
33 sum1[0] += in[2] * tp[2] - in[3] * tp[3];
34 sum1[1] += in[2] * tp[3] + in[3] * tp[2];
43 res[0] = sum0[0] + sum1[0];
44 res[1] = sum0[1] + sum1[1];
48 for(i = 0; i < isodd; ++i) {
51 *result += input[num_points - 1] * taps[num_points - 1];
61 #include <pmmintrin.h>
63 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) {
67 memset(&dotProduct, 0x0, 2*
sizeof(
float));
69 unsigned int number = 0;
70 const unsigned int halfPoints = num_points/2;
72 __m128 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
77 dotProdVal = _mm_setzero_ps();
79 for(;number < halfPoints; number++){
81 x = _mm_loadu_ps((
float*)a);
82 y = _mm_loadu_ps((
float*)b);
84 yl = _mm_moveldup_ps(y);
85 yh = _mm_movehdup_ps(y);
87 tmp1 = _mm_mul_ps(x,yl);
89 x = _mm_shuffle_ps(x,x,0xB1);
91 tmp2 = _mm_mul_ps(x,yh);
93 z = _mm_addsub_ps(tmp1,tmp2);
95 dotProdVal = _mm_add_ps(dotProdVal, z);
103 _mm_storeu_ps((
float*)dotProductVector,dotProdVal);
105 dotProduct += ( dotProductVector[0] + dotProductVector[1] );
107 if(num_points % 1 != 0) {
108 dotProduct += (*a) * (*b);
111 *result = dotProduct;
117 #ifndef INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H
118 #define INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H
126 #ifdef LV_HAVE_GENERIC
129 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) {
131 const unsigned int num_bytes = num_points*8;
133 float * res = (
float*) result;
134 float * in = (
float*) input;
135 float * tp = (
float*) taps;
136 unsigned int n_2_ccomplex_blocks = num_bytes >> 4;
137 unsigned int isodd = (num_bytes >> 3) &1;
139 float sum0[2] = {0,0};
140 float sum1[2] = {0,0};
143 for(i = 0; i < n_2_ccomplex_blocks; ++i) {
144 sum0[0] += in[0] * tp[0] - in[1] * tp[1];
145 sum0[1] += in[0] * tp[1] + in[1] * tp[0];
146 sum1[0] += in[2] * tp[2] - in[3] * tp[3];
147 sum1[1] += in[2] * tp[3] + in[3] * tp[2];
153 res[0] = sum0[0] + sum1[0];
154 res[1] = sum0[1] + sum1[1];
156 for(i = 0; i < isodd; ++i) {
157 *result += input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1];
164 #if LV_HAVE_SSE && LV_HAVE_64
167 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) {
169 const unsigned int num_bytes = num_points*8;
173 "# ccomplex_dotprod_generic (float* result, const float *input,\n\t"
174 "# const float *taps, unsigned num_bytes)\n\t"
175 "# float sum0 = 0;\n\t"
176 "# float sum1 = 0;\n\t"
177 "# float sum2 = 0;\n\t"
178 "# float sum3 = 0;\n\t"
180 "# sum0 += input[0] * taps[0] - input[1] * taps[1];\n\t"
181 "# sum1 += input[0] * taps[1] + input[1] * taps[0];\n\t"
182 "# sum2 += input[2] * taps[2] - input[3] * taps[3];\n\t"
183 "# sum3 += input[2] * taps[3] + input[3] * taps[2];\n\t"
186 "# } while (--n_2_ccomplex_blocks != 0);\n\t"
187 "# result[0] = sum0 + sum2;\n\t"
188 "# result[1] = sum1 + sum3;\n\t"
189 "# TODO: prefetch and better scheduling\n\t"
190 " xor %%r9, %%r9\n\t"
191 " xor %%r10, %%r10\n\t"
192 " movq %%rcx, %%rax\n\t"
193 " movq %%rcx, %%r8\n\t"
194 " movq %[rsi], %%r9\n\t"
195 " movq %[rdx], %%r10\n\t"
196 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t"
197 " movaps 0(%%r9), %%xmm0\n\t"
198 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t"
199 " movaps 0(%%r10), %%xmm2\n\t"
200 " shr $5, %%rax # rax = n_2_ccomplex_blocks / 2\n\t"
202 " jmp .%=L1_test\n\t"
203 " # 4 taps / loop\n\t"
204 " # something like ?? cycles / loop\n\t"
206 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t"
207 "# movaps (%%r9), %%xmmA\n\t"
208 "# movaps (%%r10), %%xmmB\n\t"
209 "# movaps %%xmmA, %%xmmZ\n\t"
210 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t"
211 "# mulps %%xmmB, %%xmmA\n\t"
212 "# mulps %%xmmZ, %%xmmB\n\t"
213 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t"
214 "# xorps %%xmmPN, %%xmmA\n\t"
215 "# movaps %%xmmA, %%xmmZ\n\t"
216 "# unpcklps %%xmmB, %%xmmA\n\t"
217 "# unpckhps %%xmmB, %%xmmZ\n\t"
218 "# movaps %%xmmZ, %%xmmY\n\t"
219 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t"
220 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t"
221 "# addps %%xmmZ, %%xmmA\n\t"
222 "# addps %%xmmA, %%xmmC\n\t"
223 "# A=xmm0, B=xmm2, Z=xmm4\n\t"
224 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t"
225 " movaps 16(%%r9), %%xmm1\n\t"
226 " movaps %%xmm0, %%xmm4\n\t"
227 " mulps %%xmm2, %%xmm0\n\t"
228 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
229 " movaps 16(%%r10), %%xmm3\n\t"
230 " movaps %%xmm1, %%xmm5\n\t"
231 " addps %%xmm0, %%xmm6\n\t"
232 " mulps %%xmm3, %%xmm1\n\t"
233 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t"
234 " addps %%xmm1, %%xmm6\n\t"
235 " mulps %%xmm4, %%xmm2\n\t"
236 " movaps 32(%%r9), %%xmm0\n\t"
237 " addps %%xmm2, %%xmm7\n\t"
238 " mulps %%xmm5, %%xmm3\n\t"
240 " movaps 32(%%r10), %%xmm2\n\t"
241 " addps %%xmm3, %%xmm7\n\t"
242 " add $32, %%r10\n\t"
246 " # We've handled the bulk of multiplies up to here.\n\t"
247 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t"
248 " # If so, we've got 2 more taps to do.\n\t"
251 " # The count was odd, do 2 more taps.\n\t"
252 " # Note that we've already got mm0/mm2 preloaded\n\t"
253 " # from the main loop.\n\t"
254 " movaps %%xmm0, %%xmm4\n\t"
255 " mulps %%xmm2, %%xmm0\n\t"
256 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
257 " addps %%xmm0, %%xmm6\n\t"
258 " mulps %%xmm4, %%xmm2\n\t"
259 " addps %%xmm2, %%xmm7\n\t"
261 " # neg inversor\n\t"
262 " xorps %%xmm1, %%xmm1\n\t"
263 " mov $0x80000000, %%r9\n\t"
264 " movd %%r9, %%xmm1\n\t"
265 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t"
267 " xorps %%xmm1, %%xmm6\n\t"
268 " movaps %%xmm6, %%xmm2\n\t"
269 " unpcklps %%xmm7, %%xmm6\n\t"
270 " unpckhps %%xmm7, %%xmm2\n\t"
271 " movaps %%xmm2, %%xmm3\n\t"
272 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t"
273 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t"
274 " addps %%xmm2, %%xmm6\n\t"
275 " # xmm6 = r1 i2 r3 i4\n\t"
276 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t"
277 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t"
278 " movlps %%xmm6, (%[rdi]) # store low 2x32 bits (complex) to memory\n\t"
280 :[rsi]
"r" (input), [rdx]
"r" (taps),
"c" (num_bytes), [rdi]
"r" (result)
281 :
"rax",
"r8",
"r9",
"r10"
285 if(((num_bytes >> 3) & 1)) {
286 *result += (input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1]);
295 #if LV_HAVE_SSE && LV_HAVE_32
297 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) {
298 volk_32fc_x2_dot_prod_32fc_a_generic(result, input, taps, num_points);
301 const unsigned int num_bytes = num_points*8;
305 " #movl %%esp, %%ebp\n\t"
306 " movl 12(%%ebp), %%eax # input\n\t"
307 " movl 16(%%ebp), %%edx # taps\n\t"
308 " movl 20(%%ebp), %%ecx # n_bytes\n\t"
309 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t"
310 " movaps 0(%%eax), %%xmm0\n\t"
311 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t"
312 " movaps 0(%%edx), %%xmm2\n\t"
313 " shrl $5, %%ecx # ecx = n_2_ccomplex_blocks / 2\n\t"
314 " jmp .%=L1_test\n\t"
315 " # 4 taps / loop\n\t"
316 " # something like ?? cycles / loop\n\t"
318 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t"
319 "# movaps (%%eax), %%xmmA\n\t"
320 "# movaps (%%edx), %%xmmB\n\t"
321 "# movaps %%xmmA, %%xmmZ\n\t"
322 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t"
323 "# mulps %%xmmB, %%xmmA\n\t"
324 "# mulps %%xmmZ, %%xmmB\n\t"
325 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t"
326 "# xorps %%xmmPN, %%xmmA\n\t"
327 "# movaps %%xmmA, %%xmmZ\n\t"
328 "# unpcklps %%xmmB, %%xmmA\n\t"
329 "# unpckhps %%xmmB, %%xmmZ\n\t"
330 "# movaps %%xmmZ, %%xmmY\n\t"
331 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t"
332 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t"
333 "# addps %%xmmZ, %%xmmA\n\t"
334 "# addps %%xmmA, %%xmmC\n\t"
335 "# A=xmm0, B=xmm2, Z=xmm4\n\t"
336 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t"
337 " movaps 16(%%eax), %%xmm1\n\t"
338 " movaps %%xmm0, %%xmm4\n\t"
339 " mulps %%xmm2, %%xmm0\n\t"
340 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
341 " movaps 16(%%edx), %%xmm3\n\t"
342 " movaps %%xmm1, %%xmm5\n\t"
343 " addps %%xmm0, %%xmm6\n\t"
344 " mulps %%xmm3, %%xmm1\n\t"
345 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t"
346 " addps %%xmm1, %%xmm6\n\t"
347 " mulps %%xmm4, %%xmm2\n\t"
348 " movaps 32(%%eax), %%xmm0\n\t"
349 " addps %%xmm2, %%xmm7\n\t"
350 " mulps %%xmm5, %%xmm3\n\t"
351 " addl $32, %%eax\n\t"
352 " movaps 32(%%edx), %%xmm2\n\t"
353 " addps %%xmm3, %%xmm7\n\t"
354 " addl $32, %%edx\n\t"
358 " # We've handled the bulk of multiplies up to here.\n\t"
359 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t"
360 " # If so, we've got 2 more taps to do.\n\t"
361 " movl 20(%%ebp), %%ecx # n_2_ccomplex_blocks\n\t"
362 " shrl $4, %%ecx\n\t"
363 " andl $1, %%ecx\n\t"
365 " # The count was odd, do 2 more taps.\n\t"
366 " # Note that we've already got mm0/mm2 preloaded\n\t"
367 " # from the main loop.\n\t"
368 " movaps %%xmm0, %%xmm4\n\t"
369 " mulps %%xmm2, %%xmm0\n\t"
370 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t"
371 " addps %%xmm0, %%xmm6\n\t"
372 " mulps %%xmm4, %%xmm2\n\t"
373 " addps %%xmm2, %%xmm7\n\t"
375 " # neg inversor\n\t"
376 " movl 8(%%ebp), %%eax \n\t"
377 " xorps %%xmm1, %%xmm1\n\t"
378 " movl $0x80000000, (%%eax)\n\t"
379 " movss (%%eax), %%xmm1\n\t"
380 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t"
382 " xorps %%xmm1, %%xmm6\n\t"
383 " movaps %%xmm6, %%xmm2\n\t"
384 " unpcklps %%xmm7, %%xmm6\n\t"
385 " unpckhps %%xmm7, %%xmm2\n\t"
386 " movaps %%xmm2, %%xmm3\n\t"
387 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t"
388 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t"
389 " addps %%xmm2, %%xmm6\n\t"
390 " # xmm6 = r1 i2 r3 i4\n\t"
391 " #movl 8(%%ebp), %%eax # @result\n\t"
392 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t"
393 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t"
394 " movlps %%xmm6, (%%eax) # store low 2x32 bits (complex) to memory\n\t"
398 :
"eax",
"ecx",
"edx"
402 int getem = num_bytes % 16;
404 for(; getem > 0; getem -= 8) {
407 *result += (input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1]);
419 #include <pmmintrin.h>
421 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) {
423 const unsigned int num_bytes = num_points*8;
426 memset(&dotProduct, 0x0, 2*
sizeof(
float));
428 unsigned int number = 0;
429 const unsigned int halfPoints = num_bytes >> 4;
431 __m128 x, y, yl, yh, z, tmp1, tmp2, dotProdVal;
436 dotProdVal = _mm_setzero_ps();
438 for(;number < halfPoints; number++){
440 x = _mm_load_ps((
float*)a);
441 y = _mm_load_ps((
float*)b);
443 yl = _mm_moveldup_ps(y);
444 yh = _mm_movehdup_ps(y);
446 tmp1 = _mm_mul_ps(x,yl);
448 x = _mm_shuffle_ps(x,x,0xB1);
450 tmp2 = _mm_mul_ps(x,yh);
452 z = _mm_addsub_ps(tmp1,tmp2);
454 dotProdVal = _mm_add_ps(dotProdVal, z);
462 _mm_store_ps((
float*)dotProductVector,dotProdVal);
464 dotProduct += ( dotProductVector[0] + dotProductVector[1] );
466 if(((num_bytes >> 3) & 1) != 0) {
467 dotProduct += (*a) * (*b);
470 *result = dotProduct;
475 #ifdef LV_HAVE_SSE4_1
477 #include <smmintrin.h>
479 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) {
481 const unsigned int num_bytes = num_points*8;
483 __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, real0, real1, im0, im1;
484 float *p_input, *p_taps;
487 p_result = (__m64*)result;
488 p_input = (
float*)input;
489 p_taps = (
float*)taps;
491 static const __m128i neg = {0x000000000000000080000000};
495 int bound = (num_bytes >> 5);
496 int leftovers = (num_bytes & 24) >> 3;
498 real0 = _mm_sub_ps(real0, real0);
499 real1 = _mm_sub_ps(real1, real1);
500 im0 = _mm_sub_ps(im0, im0);
501 im1 = _mm_sub_ps(im1, im1);
503 for(; i < bound; ++i) {
506 xmm0 = _mm_load_ps(p_input);
507 xmm1 = _mm_load_ps(p_taps);
512 xmm2 = _mm_load_ps(p_input);
513 xmm3 = _mm_load_ps(p_taps);
518 xmm4 = _mm_unpackhi_ps(xmm0, xmm2);
519 xmm5 = _mm_unpackhi_ps(xmm1, xmm3);
520 xmm0 = _mm_unpacklo_ps(xmm0, xmm2);
521 xmm2 = _mm_unpacklo_ps(xmm1, xmm3);
524 xmm1 = _mm_unpackhi_ps(xmm0, xmm4);
526 xmm3 = _mm_unpacklo_ps(xmm0, xmm4);
528 xmm0 = _mm_unpackhi_ps(xmm2, xmm5);
530 xmm2 = _mm_unpacklo_ps(xmm2, xmm5);
532 xmm4 = _mm_dp_ps(xmm3, xmm2, 0xf1);
533 xmm5 = _mm_dp_ps(xmm1, xmm0, 0xf1);
535 xmm6 = _mm_dp_ps(xmm3, xmm0, 0xf2);
536 xmm7 = _mm_dp_ps(xmm1, xmm2, 0xf2);
538 real0 = _mm_add_ps(xmm4, real0);
539 real1 = _mm_add_ps(xmm5, real1);
540 im0 = _mm_add_ps(xmm6, im0);
541 im1 = _mm_add_ps(xmm7, im1);
545 real1 = _mm_xor_ps(real1,
bit128_p(&neg)->float_vec);
547 im0 = _mm_add_ps(im0, im1);
548 real0 = _mm_add_ps(real0, real1);
550 im0 = _mm_add_ps(im0, real0);
552 _mm_storel_pi(p_result, im0);
554 for(i = bound * 4; i < (bound * 4) + leftovers; ++i) {
556 *result += input[i] * taps[i];
#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