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.

请问这段代码怎么优化比较合适?



#include "global.h"

void detrend_const(float *pdata, float num)
{
	unsigned int i = 0;
	double sum_r=0;
	double sum_i=0;
	double mean_r=0;
	double mean_i=0;

	for(i = 0; i < num; i++)
	{
		sum_r += *(pdata + 2 * i);
		sum_i += *(pdata + 2 * i + 1);
	}
	mean_r = sum_r / num;
	mean_i = sum_i / num;

	for(i = 0; i < num; i++)
	{
		*(pdata + 2 * i) = *(pdata + 2 * i) - mean_r;
		*(pdata + 2 * i + 1) = *(pdata + 2 * i + 1) - mean_i;
	}
}

希望能占用最少的时钟周期,不考虑用汇编或线性汇编,怎么样改写最好?谢谢大神的解答!