This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

代码优化,memcpy,for循环,内存移动



使用DSP进行FFT运算,发现FFT利用库函数很快,主要是其他操作拖慢了时间,主要在这几个地方

在代码声明了4个全局变量

float fft_data[1024];
float ff_out[2048];
float fft_out_img[1024]
float fft_out_real[1024];

1. 使用的数据放在存放在DDR上,利用memcpy把数据移动到fft_data,比较慢

float *p = (float*)(data_ddr_base + offset)
memcpy(fft_data, p, 4*range_gate);

然后做了一个fft运算,结果存到fft_out里面,这里很快

2. 需要对结果的每个复数做如下计算, abs = sqrt(real * real + img * img),把fft_out中每个复数的实部和虚部分开,这里也比较慢

for(i=0;i<FFT_DATA_NUMBERS;i+=2) {
    fft_out_real[i/2] = fft_out[i];
    fft_out_img[i/2] = fft_out[i+1];
}

3. 最后要把结果做累加,存储在DDR里面,这里也比较慢

float *p = (float*) result_addr
DSPF_sp_vecadd(p, fft_out, p, FFT_RESULT_NUMBERS);

请问这几个地方该如何优化啊?