GNU Radio 3.6.5 C++ API
|
00001 #ifndef INCLUDED_volk_32fc_x2_conjugate_dot_prod_32fc_a_H 00002 #define INCLUDED_volk_32fc_x2_conjugate_dot_prod_32fc_a_H 00003 00004 #include <volk/volk_common.h> 00005 #include<volk/volk_complex.h> 00006 #include<stdio.h> 00007 00008 00009 #ifdef LV_HAVE_GENERIC 00010 00011 00012 static inline void volk_32fc_x2_conjugate_dot_prod_32fc_a_generic(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_bytes) { 00013 00014 float * res = (float*) result; 00015 float * in = (float*) input; 00016 float * tp = (float*) taps; 00017 unsigned int n_2_ccomplex_blocks = num_bytes >> 4; 00018 unsigned int isodd = (num_bytes >> 3) &1; 00019 00020 00021 00022 float sum0[2] = {0,0}; 00023 float sum1[2] = {0,0}; 00024 unsigned int i = 0; 00025 00026 00027 for(i = 0; i < n_2_ccomplex_blocks; ++i) { 00028 00029 00030 sum0[0] += in[0] * tp[0] + in[1] * tp[1]; 00031 sum0[1] += (-in[0] * tp[1]) + in[1] * tp[0]; 00032 sum1[0] += in[2] * tp[2] + in[3] * tp[3]; 00033 sum1[1] += (-in[2] * tp[3]) + in[3] * tp[2]; 00034 00035 00036 in += 4; 00037 tp += 4; 00038 00039 } 00040 00041 00042 res[0] = sum0[0] + sum1[0]; 00043 res[1] = sum0[1] + sum1[1]; 00044 00045 00046 00047 for(i = 0; i < isodd; ++i) { 00048 00049 00050 *result += input[(num_bytes >> 3) - 1] * lv_conj(taps[(num_bytes >> 3) - 1]); 00051 00052 } 00053 /* 00054 for(i = 0; i < num_bytes >> 3; ++i) { 00055 *result += input[i] * conjf(taps[i]); 00056 } 00057 */ 00058 } 00059 00060 #endif /*LV_HAVE_GENERIC*/ 00061 00062 00063 #if LV_HAVE_SSE && LV_HAVE_64 00064 00065 00066 static inline void volk_32fc_x2_conjugate_dot_prod_32fc_a_sse(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_bytes) { 00067 00068 __VOLK_ATTR_ALIGNED(16) static const uint32_t conjugator[4]= {0x00000000, 0x80000000, 0x00000000, 0x80000000}; 00069 00070 00071 00072 00073 asm volatile 00074 ( 00075 "# ccomplex_conjugate_dotprod_generic (float* result, const float *input,\n\t" 00076 "# const float *taps, unsigned num_bytes)\n\t" 00077 "# float sum0 = 0;\n\t" 00078 "# float sum1 = 0;\n\t" 00079 "# float sum2 = 0;\n\t" 00080 "# float sum3 = 0;\n\t" 00081 "# do {\n\t" 00082 "# sum0 += input[0] * taps[0] - input[1] * taps[1];\n\t" 00083 "# sum1 += input[0] * taps[1] + input[1] * taps[0];\n\t" 00084 "# sum2 += input[2] * taps[2] - input[3] * taps[3];\n\t" 00085 "# sum3 += input[2] * taps[3] + input[3] * taps[2];\n\t" 00086 "# input += 4;\n\t" 00087 "# taps += 4; \n\t" 00088 "# } while (--n_2_ccomplex_blocks != 0);\n\t" 00089 "# result[0] = sum0 + sum2;\n\t" 00090 "# result[1] = sum1 + sum3;\n\t" 00091 "# TODO: prefetch and better scheduling\n\t" 00092 " xor %%r9, %%r9\n\t" 00093 " xor %%r10, %%r10\n\t" 00094 " movq %[conjugator], %%r9\n\t" 00095 " movq %%rcx, %%rax\n\t" 00096 " movaps 0(%%r9), %%xmm8\n\t" 00097 " movq %%rcx, %%r8\n\t" 00098 " movq %[rsi], %%r9\n\t" 00099 " movq %[rdx], %%r10\n\t" 00100 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t" 00101 " movaps 0(%%r9), %%xmm0\n\t" 00102 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t" 00103 " movups 0(%%r10), %%xmm2\n\t" 00104 " shr $5, %%rax # rax = n_2_ccomplex_blocks / 2\n\t" 00105 " shr $4, %%r8\n\t" 00106 " xorps %%xmm8, %%xmm2\n\t" 00107 " jmp .%=L1_test\n\t" 00108 " # 4 taps / loop\n\t" 00109 " # something like ?? cycles / loop\n\t" 00110 ".%=Loop1: \n\t" 00111 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t" 00112 "# movaps (%%r9), %%xmmA\n\t" 00113 "# movaps (%%r10), %%xmmB\n\t" 00114 "# movaps %%xmmA, %%xmmZ\n\t" 00115 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t" 00116 "# mulps %%xmmB, %%xmmA\n\t" 00117 "# mulps %%xmmZ, %%xmmB\n\t" 00118 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t" 00119 "# xorps %%xmmPN, %%xmmA\n\t" 00120 "# movaps %%xmmA, %%xmmZ\n\t" 00121 "# unpcklps %%xmmB, %%xmmA\n\t" 00122 "# unpckhps %%xmmB, %%xmmZ\n\t" 00123 "# movaps %%xmmZ, %%xmmY\n\t" 00124 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t" 00125 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t" 00126 "# addps %%xmmZ, %%xmmA\n\t" 00127 "# addps %%xmmA, %%xmmC\n\t" 00128 "# A=xmm0, B=xmm2, Z=xmm4\n\t" 00129 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t" 00130 " movaps 16(%%r9), %%xmm1\n\t" 00131 " movaps %%xmm0, %%xmm4\n\t" 00132 " mulps %%xmm2, %%xmm0\n\t" 00133 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00134 " movaps 16(%%r10), %%xmm3\n\t" 00135 " movaps %%xmm1, %%xmm5\n\t" 00136 " xorps %%xmm8, %%xmm3\n\t" 00137 " addps %%xmm0, %%xmm6\n\t" 00138 " mulps %%xmm3, %%xmm1\n\t" 00139 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t" 00140 " addps %%xmm1, %%xmm6\n\t" 00141 " mulps %%xmm4, %%xmm2\n\t" 00142 " movaps 32(%%r9), %%xmm0\n\t" 00143 " addps %%xmm2, %%xmm7\n\t" 00144 " mulps %%xmm5, %%xmm3\n\t" 00145 " add $32, %%r9\n\t" 00146 " movaps 32(%%r10), %%xmm2\n\t" 00147 " addps %%xmm3, %%xmm7\n\t" 00148 " add $32, %%r10\n\t" 00149 " xorps %%xmm8, %%xmm2\n\t" 00150 ".%=L1_test:\n\t" 00151 " dec %%rax\n\t" 00152 " jge .%=Loop1\n\t" 00153 " # We've handled the bulk of multiplies up to here.\n\t" 00154 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t" 00155 " # If so, we've got 2 more taps to do.\n\t" 00156 " and $1, %%r8\n\t" 00157 " je .%=Leven\n\t" 00158 " # The count was odd, do 2 more taps.\n\t" 00159 " # Note that we've already got mm0/mm2 preloaded\n\t" 00160 " # from the main loop.\n\t" 00161 " movaps %%xmm0, %%xmm4\n\t" 00162 " mulps %%xmm2, %%xmm0\n\t" 00163 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00164 " addps %%xmm0, %%xmm6\n\t" 00165 " mulps %%xmm4, %%xmm2\n\t" 00166 " addps %%xmm2, %%xmm7\n\t" 00167 ".%=Leven:\n\t" 00168 " # neg inversor\n\t" 00169 " xorps %%xmm1, %%xmm1\n\t" 00170 " mov $0x80000000, %%r9\n\t" 00171 " movd %%r9, %%xmm1\n\t" 00172 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t" 00173 " # pfpnacc\n\t" 00174 " xorps %%xmm1, %%xmm6\n\t" 00175 " movaps %%xmm6, %%xmm2\n\t" 00176 " unpcklps %%xmm7, %%xmm6\n\t" 00177 " unpckhps %%xmm7, %%xmm2\n\t" 00178 " movaps %%xmm2, %%xmm3\n\t" 00179 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t" 00180 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t" 00181 " addps %%xmm2, %%xmm6\n\t" 00182 " # xmm6 = r1 i2 r3 i4\n\t" 00183 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t" 00184 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t" 00185 " movlps %%xmm6, (%[rdi]) # store low 2x32 bits (complex) to memory\n\t" 00186 : 00187 :[rsi] "r" (input), [rdx] "r" (taps), "c" (num_bytes), [rdi] "r" (result), [conjugator] "r" (conjugator) 00188 :"rax", "r8", "r9", "r10" 00189 ); 00190 00191 00192 int getem = num_bytes % 16; 00193 00194 00195 for(; getem > 0; getem -= 8) { 00196 00197 00198 *result += (input[(num_bytes >> 3) - 1] * lv_conj(taps[(num_bytes >> 3) - 1])); 00199 00200 } 00201 00202 return; 00203 } 00204 #endif 00205 00206 #if LV_HAVE_SSE && LV_HAVE_32 00207 static inline void volk_32fc_x2_conjugate_dot_prod_32fc_a_sse_32(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_bytes) { 00208 00209 __VOLK_ATTR_ALIGNED(16) static const uint32_t conjugator[4]= {0x00000000, 0x80000000, 0x00000000, 0x80000000}; 00210 00211 int bound = num_bytes >> 4; 00212 int leftovers = num_bytes % 16; 00213 00214 00215 asm volatile 00216 ( 00217 " #pushl %%ebp\n\t" 00218 " #movl %%esp, %%ebp\n\t" 00219 " #movl 12(%%ebp), %%eax # input\n\t" 00220 " #movl 16(%%ebp), %%edx # taps\n\t" 00221 " #movl 20(%%ebp), %%ecx # n_bytes\n\t" 00222 " movaps 0(%[conjugator]), %%xmm1\n\t" 00223 " xorps %%xmm6, %%xmm6 # zero accumulators\n\t" 00224 " movaps 0(%[eax]), %%xmm0\n\t" 00225 " xorps %%xmm7, %%xmm7 # zero accumulators\n\t" 00226 " movaps 0(%[edx]), %%xmm2\n\t" 00227 " movl %[ecx], (%[out])\n\t" 00228 " shrl $5, %[ecx] # ecx = n_2_ccomplex_blocks / 2\n\t" 00229 00230 " xorps %%xmm1, %%xmm2\n\t" 00231 " jmp .%=L1_test\n\t" 00232 " # 4 taps / loop\n\t" 00233 " # something like ?? cycles / loop\n\t" 00234 ".%=Loop1: \n\t" 00235 "# complex prod: C += A * B, w/ temp Z & Y (or B), xmmPN=$0x8000000080000000\n\t" 00236 "# movaps (%[eax]), %%xmmA\n\t" 00237 "# movaps (%[edx]), %%xmmB\n\t" 00238 "# movaps %%xmmA, %%xmmZ\n\t" 00239 "# shufps $0xb1, %%xmmZ, %%xmmZ # swap internals\n\t" 00240 "# mulps %%xmmB, %%xmmA\n\t" 00241 "# mulps %%xmmZ, %%xmmB\n\t" 00242 "# # SSE replacement for: pfpnacc %%xmmB, %%xmmA\n\t" 00243 "# xorps %%xmmPN, %%xmmA\n\t" 00244 "# movaps %%xmmA, %%xmmZ\n\t" 00245 "# unpcklps %%xmmB, %%xmmA\n\t" 00246 "# unpckhps %%xmmB, %%xmmZ\n\t" 00247 "# movaps %%xmmZ, %%xmmY\n\t" 00248 "# shufps $0x44, %%xmmA, %%xmmZ # b01000100\n\t" 00249 "# shufps $0xee, %%xmmY, %%xmmA # b11101110\n\t" 00250 "# addps %%xmmZ, %%xmmA\n\t" 00251 "# addps %%xmmA, %%xmmC\n\t" 00252 "# A=xmm0, B=xmm2, Z=xmm4\n\t" 00253 "# A'=xmm1, B'=xmm3, Z'=xmm5\n\t" 00254 " movaps 16(%[edx]), %%xmm3\n\t" 00255 " movaps %%xmm0, %%xmm4\n\t" 00256 " xorps %%xmm1, %%xmm3\n\t" 00257 " mulps %%xmm2, %%xmm0\n\t" 00258 " movaps 16(%[eax]), %%xmm1\n\t" 00259 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00260 " movaps %%xmm1, %%xmm5\n\t" 00261 " addps %%xmm0, %%xmm6\n\t" 00262 " mulps %%xmm3, %%xmm1\n\t" 00263 " shufps $0xb1, %%xmm5, %%xmm5 # swap internals\n\t" 00264 " addps %%xmm1, %%xmm6\n\t" 00265 " movaps 0(%[conjugator]), %%xmm1\n\t" 00266 " mulps %%xmm4, %%xmm2\n\t" 00267 " movaps 32(%[eax]), %%xmm0\n\t" 00268 " addps %%xmm2, %%xmm7\n\t" 00269 " mulps %%xmm5, %%xmm3\n\t" 00270 " addl $32, %[eax]\n\t" 00271 " movaps 32(%[edx]), %%xmm2\n\t" 00272 " addps %%xmm3, %%xmm7\n\t" 00273 " xorps %%xmm1, %%xmm2\n\t" 00274 " addl $32, %[edx]\n\t" 00275 ".%=L1_test:\n\t" 00276 " decl %[ecx]\n\t" 00277 " jge .%=Loop1\n\t" 00278 " # We've handled the bulk of multiplies up to here.\n\t" 00279 " # Let's sse if original n_2_ccomplex_blocks was odd.\n\t" 00280 " # If so, we've got 2 more taps to do.\n\t" 00281 " movl 0(%[out]), %[ecx] # n_2_ccomplex_blocks\n\t" 00282 " shrl $4, %[ecx]\n\t" 00283 " andl $1, %[ecx]\n\t" 00284 " je .%=Leven\n\t" 00285 " # The count was odd, do 2 more taps.\n\t" 00286 " # Note that we've already got mm0/mm2 preloaded\n\t" 00287 " # from the main loop.\n\t" 00288 " movaps %%xmm0, %%xmm4\n\t" 00289 " mulps %%xmm2, %%xmm0\n\t" 00290 " shufps $0xb1, %%xmm4, %%xmm4 # swap internals\n\t" 00291 " addps %%xmm0, %%xmm6\n\t" 00292 " mulps %%xmm4, %%xmm2\n\t" 00293 " addps %%xmm2, %%xmm7\n\t" 00294 ".%=Leven:\n\t" 00295 " # neg inversor\n\t" 00296 " #movl 8(%%ebp), %[eax] \n\t" 00297 " xorps %%xmm1, %%xmm1\n\t" 00298 " movl $0x80000000, (%[out])\n\t" 00299 " movss (%[out]), %%xmm1\n\t" 00300 " shufps $0x11, %%xmm1, %%xmm1 # b00010001 # 0 -0 0 -0\n\t" 00301 " # pfpnacc\n\t" 00302 " xorps %%xmm1, %%xmm6\n\t" 00303 " movaps %%xmm6, %%xmm2\n\t" 00304 " unpcklps %%xmm7, %%xmm6\n\t" 00305 " unpckhps %%xmm7, %%xmm2\n\t" 00306 " movaps %%xmm2, %%xmm3\n\t" 00307 " shufps $0x44, %%xmm6, %%xmm2 # b01000100\n\t" 00308 " shufps $0xee, %%xmm3, %%xmm6 # b11101110\n\t" 00309 " addps %%xmm2, %%xmm6\n\t" 00310 " # xmm6 = r1 i2 r3 i4\n\t" 00311 " #movl 8(%%ebp), %[eax] # @result\n\t" 00312 " movhlps %%xmm6, %%xmm4 # xmm4 = r3 i4 ?? ??\n\t" 00313 " addps %%xmm4, %%xmm6 # xmm6 = r1+r3 i2+i4 ?? ??\n\t" 00314 " movlps %%xmm6, (%[out]) # store low 2x32 bits (complex) to memory\n\t" 00315 " #popl %%ebp\n\t" 00316 : 00317 : [eax] "r" (input), [edx] "r" (taps), [ecx] "r" (num_bytes), [out] "r" (result), [conjugator] "r" (conjugator) 00318 ); 00319 00320 00321 00322 00323 printf("%d, %d\n", leftovers, bound); 00324 00325 for(; leftovers > 0; leftovers -= 8) { 00326 00327 00328 *result += (input[(bound << 1)] * lv_conj(taps[(bound << 1)])); 00329 00330 } 00331 00332 return; 00333 00334 00335 00336 00337 00338 00339 } 00340 00341 #endif /*LV_HAVE_SSE*/ 00342 00343 00344 00345 #endif /*INCLUDED_volk_32fc_x2_conjugate_dot_prod_32fc_a_H*/