GNU Radio 3.5.3.2 C++ API
|
00001 #ifndef INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H 00002 #define INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H 00003 00004 #include <volk/volk_common.h> 00005 #include <volk/volk_complex.h> 00006 #include <stdio.h> 00007 #include <string.h> 00008 00009 00010 #ifdef LV_HAVE_GENERIC 00011 00012 00013 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_bytes) { 00014 00015 float * res = (float*) result; 00016 float * in = (float*) input; 00017 float * tp = (float*) taps; 00018 unsigned int n_2_ccomplex_blocks = num_bytes >> 4; 00019 unsigned int isodd = (num_bytes >> 3) &1; 00020 00021 00022 00023 float sum0[2] = {0,0}; 00024 float sum1[2] = {0,0}; 00025 unsigned int i = 0; 00026 00027 00028 for(i = 0; i < n_2_ccomplex_blocks; ++i) { 00029 00030 00031 sum0[0] += in[0] * tp[0] - in[1] * tp[1]; 00032 sum0[1] += in[0] * tp[1] + in[1] * tp[0]; 00033 sum1[0] += in[2] * tp[2] - in[3] * tp[3]; 00034 sum1[1] += in[2] * tp[3] + in[3] * tp[2]; 00035 00036 00037 in += 4; 00038 tp += 4; 00039 00040 } 00041 00042 00043 res[0] = sum0[0] + sum1[0]; 00044 res[1] = sum0[1] + sum1[1]; 00045 00046 00047 00048 for(i = 0; i < isodd; ++i) { 00049 00050 00051 *result += input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1]; 00052 00053 } 00054 00055 } 00056 00057 #endif /*LV_HAVE_GENERIC*/ 00058 00059 00060 #if LV_HAVE_SSE && LV_HAVE_64 00061 00062 00063 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_bytes) { 00064 00065 00066 asm 00067 ( 00068 "# ccomplex_dotprod_generic (float* result, const float *input,\n\t" 00069 "# const float *taps, unsigned num_bytes)\n\t" 00070 "# float sum0 = 0;\n\t" 00071 "# float sum1 = 0;\n\t" 00072 "# float sum2 = 0;\n\t" 00073 "# float sum3 = 0;\n\t" 00074 "# do {\n\t" 00075 "# sum0 += input[0] * taps[0] - input[1] * taps[1];\n\t" 00076 "# sum1 += input[0] * taps[1] + input[1] * taps[0];\n\t" 00077 "# sum2 += input[2] * taps[2] - input[3] * taps[3];\n\t" 00078 "# sum3 += input[2] * taps[3] + input[3] * taps[2];\n\t" 00079 "# input += 4;\n\t" 00080 "# taps += 4; \n\t" 00081 "# } while (--n_2_ccomplex_blocks != 0);\n\t" 00082 "# result[0] = sum0 + sum2;\n\t" 00083 "# result[1] = sum1 + sum3;\n\t" 00084 "# TODO: prefetch and better scheduling\n\t" 00085 " xor %%r9, %%r9\n\t" 00086 " xor %%r10, %%r10\n\t" 00087 " movq %%rcx, %%rax\n\t" 00088 " movq %%rcx, %%r8\n\t" 00089 " movq %[rsi], %%r9\n\t" 00090 " movq %[rdx], %%r10\n\t" 00091 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t" 00092 " movaps 0(%%r9), %%xmm0\n\t" 00093 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t" 00094 " movaps 0(%%r10), %%xmm2\n\t" 00095 " shr $5, %%rax # rax = n_2_ccomplex_blocks / 2\n\t" 00096 " shr $4, %%r8\n\t" 00097 " jmp .%=L1_test\n\t" 00098 " # 4 taps / loop\n\t" 00099 " # something like ?? cycles / loop\n\t" 00100 ".%=Loop1: \n\t" 00101 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t" 00102 "# movaps (%%r9), %%xmmA\n\t" 00103 "# movaps (%%r10), %%xmmB\n\t" 00104 "# movaps %%xmmA, %%xmmZ\n\t" 00105 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t" 00106 "# mulps %%xmmB, %%xmmA\n\t" 00107 "# mulps %%xmmZ, %%xmmB\n\t" 00108 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t" 00109 "# xorps %%xmmPN, %%xmmA\n\t" 00110 "# movaps %%xmmA, %%xmmZ\n\t" 00111 "# unpcklps %%xmmB, %%xmmA\n\t" 00112 "# unpckhps %%xmmB, %%xmmZ\n\t" 00113 "# movaps %%xmmZ, %%xmmY\n\t" 00114 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t" 00115 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t" 00116 "# addps %%xmmZ, %%xmmA\n\t" 00117 "# addps %%xmmA, %%xmmC\n\t" 00118 "# A=xmm0, B=xmm2, Z=xmm4\n\t" 00119 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t" 00120 " movaps 16(%%r9), %%xmm1\n\t" 00121 " movaps %%xmm0, %%xmm4\n\t" 00122 " mulps %%xmm2, %%xmm0\n\t" 00123 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00124 " movaps 16(%%r10), %%xmm3\n\t" 00125 " movaps %%xmm1, %%xmm5\n\t" 00126 " addps %%xmm0, %%xmm6\n\t" 00127 " mulps %%xmm3, %%xmm1\n\t" 00128 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t" 00129 " addps %%xmm1, %%xmm6\n\t" 00130 " mulps %%xmm4, %%xmm2\n\t" 00131 " movaps 32(%%r9), %%xmm0\n\t" 00132 " addps %%xmm2, %%xmm7\n\t" 00133 " mulps %%xmm5, %%xmm3\n\t" 00134 " add $32, %%r9\n\t" 00135 " movaps 32(%%r10), %%xmm2\n\t" 00136 " addps %%xmm3, %%xmm7\n\t" 00137 " add $32, %%r10\n\t" 00138 ".%=L1_test:\n\t" 00139 " dec %%rax\n\t" 00140 " jge .%=Loop1\n\t" 00141 " # We've handled the bulk of multiplies up to here.\n\t" 00142 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t" 00143 " # If so, we've got 2 more taps to do.\n\t" 00144 " and $1, %%r8\n\t" 00145 " je .%=Leven\n\t" 00146 " # The count was odd, do 2 more taps.\n\t" 00147 " # Note that we've already got mm0/mm2 preloaded\n\t" 00148 " # from the main loop.\n\t" 00149 " movaps %%xmm0, %%xmm4\n\t" 00150 " mulps %%xmm2, %%xmm0\n\t" 00151 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00152 " addps %%xmm0, %%xmm6\n\t" 00153 " mulps %%xmm4, %%xmm2\n\t" 00154 " addps %%xmm2, %%xmm7\n\t" 00155 ".%=Leven:\n\t" 00156 " # neg inversor\n\t" 00157 " xorps %%xmm1, %%xmm1\n\t" 00158 " mov $0x80000000, %%r9\n\t" 00159 " movd %%r9, %%xmm1\n\t" 00160 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t" 00161 " # pfpnacc\n\t" 00162 " xorps %%xmm1, %%xmm6\n\t" 00163 " movaps %%xmm6, %%xmm2\n\t" 00164 " unpcklps %%xmm7, %%xmm6\n\t" 00165 " unpckhps %%xmm7, %%xmm2\n\t" 00166 " movaps %%xmm2, %%xmm3\n\t" 00167 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t" 00168 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t" 00169 " addps %%xmm2, %%xmm6\n\t" 00170 " # xmm6 = r1 i2 r3 i4\n\t" 00171 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t" 00172 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t" 00173 " movlps %%xmm6, (%[rdi]) # store low 2x32 bits (complex) to memory\n\t" 00174 : 00175 :[rsi] "r" (input), [rdx] "r" (taps), "c" (num_bytes), [rdi] "r" (result) 00176 :"rax", "r8", "r9", "r10" 00177 ); 00178 00179 00180 int getem = num_bytes % 16; 00181 00182 00183 for(; getem > 0; getem -= 8) { 00184 00185 00186 *result += (input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1]); 00187 00188 } 00189 00190 return; 00191 00192 } 00193 00194 #endif 00195 00196 #if LV_HAVE_SSE && LV_HAVE_32 00197 00198 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_bytes) { 00199 00200 volk_32fc_x2_dot_prod_32fc_a_generic(result, input, taps, num_bytes); 00201 00202 #if 0 00203 asm volatile 00204 ( 00205 " #pushl %%ebp\n\t" 00206 " #movl %%esp, %%ebp\n\t" 00207 " movl 12(%%ebp), %%eax # input\n\t" 00208 " movl 16(%%ebp), %%edx # taps\n\t" 00209 " movl 20(%%ebp), %%ecx # n_bytes\n\t" 00210 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t" 00211 " movaps 0(%%eax), %%xmm0\n\t" 00212 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t" 00213 " movaps 0(%%edx), %%xmm2\n\t" 00214 " shrl $5, %%ecx # ecx = n_2_ccomplex_blocks / 2\n\t" 00215 " jmp .%=L1_test\n\t" 00216 " # 4 taps / loop\n\t" 00217 " # something like ?? cycles / loop\n\t" 00218 ".%=Loop1: \n\t" 00219 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t" 00220 "# movaps (%%eax), %%xmmA\n\t" 00221 "# movaps (%%edx), %%xmmB\n\t" 00222 "# movaps %%xmmA, %%xmmZ\n\t" 00223 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t" 00224 "# mulps %%xmmB, %%xmmA\n\t" 00225 "# mulps %%xmmZ, %%xmmB\n\t" 00226 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t" 00227 "# xorps %%xmmPN, %%xmmA\n\t" 00228 "# movaps %%xmmA, %%xmmZ\n\t" 00229 "# unpcklps %%xmmB, %%xmmA\n\t" 00230 "# unpckhps %%xmmB, %%xmmZ\n\t" 00231 "# movaps %%xmmZ, %%xmmY\n\t" 00232 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t" 00233 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t" 00234 "# addps %%xmmZ, %%xmmA\n\t" 00235 "# addps %%xmmA, %%xmmC\n\t" 00236 "# A=xmm0, B=xmm2, Z=xmm4\n\t" 00237 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t" 00238 " movaps 16(%%eax), %%xmm1\n\t" 00239 " movaps %%xmm0, %%xmm4\n\t" 00240 " mulps %%xmm2, %%xmm0\n\t" 00241 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00242 " movaps 16(%%edx), %%xmm3\n\t" 00243 " movaps %%xmm1, %%xmm5\n\t" 00244 " addps %%xmm0, %%xmm6\n\t" 00245 " mulps %%xmm3, %%xmm1\n\t" 00246 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t" 00247 " addps %%xmm1, %%xmm6\n\t" 00248 " mulps %%xmm4, %%xmm2\n\t" 00249 " movaps 32(%%eax), %%xmm0\n\t" 00250 " addps %%xmm2, %%xmm7\n\t" 00251 " mulps %%xmm5, %%xmm3\n\t" 00252 " addl $32, %%eax\n\t" 00253 " movaps 32(%%edx), %%xmm2\n\t" 00254 " addps %%xmm3, %%xmm7\n\t" 00255 " addl $32, %%edx\n\t" 00256 ".%=L1_test:\n\t" 00257 " decl %%ecx\n\t" 00258 " jge .%=Loop1\n\t" 00259 " # We've handled the bulk of multiplies up to here.\n\t" 00260 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t" 00261 " # If so, we've got 2 more taps to do.\n\t" 00262 " movl 20(%%ebp), %%ecx # n_2_ccomplex_blocks\n\t" 00263 " shrl $4, %%ecx\n\t" 00264 " andl $1, %%ecx\n\t" 00265 " je .%=Leven\n\t" 00266 " # The count was odd, do 2 more taps.\n\t" 00267 " # Note that we've already got mm0/mm2 preloaded\n\t" 00268 " # from the main loop.\n\t" 00269 " movaps %%xmm0, %%xmm4\n\t" 00270 " mulps %%xmm2, %%xmm0\n\t" 00271 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00272 " addps %%xmm0, %%xmm6\n\t" 00273 " mulps %%xmm4, %%xmm2\n\t" 00274 " addps %%xmm2, %%xmm7\n\t" 00275 ".%=Leven:\n\t" 00276 " # neg inversor\n\t" 00277 " movl 8(%%ebp), %%eax \n\t" 00278 " xorps %%xmm1, %%xmm1\n\t" 00279 " movl $0x80000000, (%%eax)\n\t" 00280 " movss (%%eax), %%xmm1\n\t" 00281 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t" 00282 " # pfpnacc\n\t" 00283 " xorps %%xmm1, %%xmm6\n\t" 00284 " movaps %%xmm6, %%xmm2\n\t" 00285 " unpcklps %%xmm7, %%xmm6\n\t" 00286 " unpckhps %%xmm7, %%xmm2\n\t" 00287 " movaps %%xmm2, %%xmm3\n\t" 00288 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t" 00289 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t" 00290 " addps %%xmm2, %%xmm6\n\t" 00291 " # xmm6 = r1 i2 r3 i4\n\t" 00292 " #movl 8(%%ebp), %%eax # @result\n\t" 00293 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t" 00294 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t" 00295 " movlps %%xmm6, (%%eax) # store low 2x32 bits (complex) to memory\n\t" 00296 " #popl %%ebp\n\t" 00297 : 00298 : 00299 : "eax", "ecx", "edx" 00300 ); 00301 00302 00303 int getem = num_bytes % 16; 00304 00305 for(; getem > 0; getem -= 8) { 00306 00307 00308 *result += (input[(num_bytes >> 3) - 1] * taps[(num_bytes >> 3) - 1]); 00309 00310 } 00311 00312 return; 00313 #endif 00314 } 00315 00316 #endif /*LV_HAVE_SSE*/ 00317 00318 #ifdef LV_HAVE_SSE3 00319 00320 #include <pmmintrin.h> 00321 00322 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_bytes) { 00323 00324 00325 lv_32fc_t dotProduct; 00326 memset(&dotProduct, 0x0, 2*sizeof(float)); 00327 00328 unsigned int number = 0; 00329 const unsigned int halfPoints = num_bytes >> 4; 00330 00331 __m128 x, y, yl, yh, z, tmp1, tmp2, dotProdVal; 00332 00333 const lv_32fc_t* a = input; 00334 const lv_32fc_t* b = taps; 00335 00336 dotProdVal = _mm_setzero_ps(); 00337 00338 for(;number < halfPoints; number++){ 00339 00340 x = _mm_load_ps((float*)a); // Load the ar + ai, br + bi as ar,ai,br,bi 00341 y = _mm_load_ps((float*)b); // Load the cr + ci, dr + di as cr,ci,dr,di 00342 00343 yl = _mm_moveldup_ps(y); // Load yl with cr,cr,dr,dr 00344 yh = _mm_movehdup_ps(y); // Load yh with ci,ci,di,di 00345 00346 tmp1 = _mm_mul_ps(x,yl); // tmp1 = ar*cr,ai*cr,br*dr,bi*dr 00347 00348 x = _mm_shuffle_ps(x,x,0xB1); // Re-arrange x to be ai,ar,bi,br 00349 00350 tmp2 = _mm_mul_ps(x,yh); // tmp2 = ai*ci,ar*ci,bi*di,br*di 00351 00352 z = _mm_addsub_ps(tmp1,tmp2); // ar*cr-ai*ci, ai*cr+ar*ci, br*dr-bi*di, bi*dr+br*di 00353 00354 dotProdVal = _mm_add_ps(dotProdVal, z); // Add the complex multiplication results together 00355 00356 a += 2; 00357 b += 2; 00358 } 00359 00360 __VOLK_ATTR_ALIGNED(16) lv_32fc_t dotProductVector[2]; 00361 00362 _mm_store_ps((float*)dotProductVector,dotProdVal); // Store the results back into the dot product vector 00363 00364 dotProduct += ( dotProductVector[0] + dotProductVector[1] ); 00365 00366 if((num_bytes >> 2) != 0) { 00367 dotProduct += (*a) * (*b); 00368 } 00369 00370 *result = dotProduct; 00371 } 00372 00373 #endif /*LV_HAVE_SSE3*/ 00374 00375 #ifdef LV_HAVE_SSE4_1 00376 00377 #include <smmintrin.h> 00378 00379 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_bytes) { 00380 volk_32fc_x2_dot_prod_32fc_a_sse3(result, input, taps, num_bytes); 00381 // SSE3 version runs twice as fast as the SSE4.1 version, so turning off SSE4 version for now 00382 /* 00383 __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, real0, real1, im0, im1; 00384 float *p_input, *p_taps; 00385 __m64 *p_result; 00386 00387 p_result = (__m64*)result; 00388 p_input = (float*)input; 00389 p_taps = (float*)taps; 00390 00391 static const __m128i neg = {0x000000000000000080000000}; 00392 00393 int i = 0; 00394 00395 int bound = (num_bytes >> 5); 00396 int leftovers = (num_bytes & 24) >> 3; 00397 00398 real0 = _mm_sub_ps(real0, real0); 00399 real1 = _mm_sub_ps(real1, real1); 00400 im0 = _mm_sub_ps(im0, im0); 00401 im1 = _mm_sub_ps(im1, im1); 00402 00403 for(; i < bound; ++i) { 00404 00405 00406 xmm0 = _mm_load_ps(p_input); 00407 xmm1 = _mm_load_ps(p_taps); 00408 00409 p_input += 4; 00410 p_taps += 4; 00411 00412 xmm2 = _mm_load_ps(p_input); 00413 xmm3 = _mm_load_ps(p_taps); 00414 00415 p_input += 4; 00416 p_taps += 4; 00417 00418 xmm4 = _mm_unpackhi_ps(xmm0, xmm2); 00419 xmm5 = _mm_unpackhi_ps(xmm1, xmm3); 00420 xmm0 = _mm_unpacklo_ps(xmm0, xmm2); 00421 xmm2 = _mm_unpacklo_ps(xmm1, xmm3); 00422 00423 //imaginary vector from input 00424 xmm1 = _mm_unpackhi_ps(xmm0, xmm4); 00425 //real vector from input 00426 xmm3 = _mm_unpacklo_ps(xmm0, xmm4); 00427 //imaginary vector from taps 00428 xmm0 = _mm_unpackhi_ps(xmm2, xmm5); 00429 //real vector from taps 00430 xmm2 = _mm_unpacklo_ps(xmm2, xmm5); 00431 00432 xmm4 = _mm_dp_ps(xmm3, xmm2, 0xf1); 00433 xmm5 = _mm_dp_ps(xmm1, xmm0, 0xf1); 00434 00435 xmm6 = _mm_dp_ps(xmm3, xmm0, 0xf2); 00436 xmm7 = _mm_dp_ps(xmm1, xmm2, 0xf2); 00437 00438 real0 = _mm_add_ps(xmm4, real0); 00439 real1 = _mm_add_ps(xmm5, real1); 00440 im0 = _mm_add_ps(xmm6, im0); 00441 im1 = _mm_add_ps(xmm7, im1); 00442 00443 } 00444 00445 00446 00447 00448 real1 = _mm_xor_ps(real1, (__m128)neg); 00449 00450 00451 im0 = _mm_add_ps(im0, im1); 00452 real0 = _mm_add_ps(real0, real1); 00453 00454 im0 = _mm_add_ps(im0, real0); 00455 00456 _mm_storel_pi(p_result, im0); 00457 00458 for(i = bound * 4; i < (bound * 4) + leftovers; ++i) { 00459 00460 *result += input[i] * taps[i]; 00461 } 00462 */ 00463 } 00464 00465 #endif /*LV_HAVE_SSE4_1*/ 00466 00467 #endif /*INCLUDED_volk_32fc_x2_dot_prod_32fc_a_H*/