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.

F28335指令周期问题,如何最高效



int32数组300个求和,如何最快执行?实测执行1次加法运算平均要4个指令周期,是否有问题

int32 a[300],b;

方法1测试:

b=a[0];

b+=a[1];

b+=a[2];

...

b+=a[299];

不用循环语句,直接加,加载在RAM中测试,运行耗时8us左右;

方法2测试:

i=300;b=0;

while(i--)

    b+=a[i];

加载在RAM中运行测试,耗时为30us左右;

另外使用浮点加法也测试了下,同样的while循环耗时大致为38us左右。

测试的时间是采用在程序前后加GPIO翻转操作,使用示波器看电平时间测试得到。

问题是如何优化类似数组的求和计算,按理说流水线结构第一种方式测试耗时应该是2us左右,为什么感觉慢了4倍!