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.

CCS自动调用硬件乘法器运算速度慢的问题

Other Parts Discussed in Thread: MSP430FR6972

MSP430FR6972自带了硬件乘法器,之前使用的是IAR开发环境,编译器不能够自动调用硬件乘法器,但是CCS环境可以自动调用硬件乘法器,于是我特意安装了一个CCS程序,并在CCS环境上写了一个测试程序(就是想验证是否能够自动调用硬件乘法器),为了进行对比我写了一段使用寄存器调用硬件乘法器的代码。

调试这个程序时,发现同时计算一千次乘法运算使用“ * ”运算符的运行时间比使用寄存器实现的乘法慢了近一倍。所以就怀疑,CCS到底有没有使用硬件乘法器,使用了的话,怎么可能会慢这么多呢?我看编译的汇编里面调用了”CALLA   #__mspabi_mpyl_f5hw“这句代码应该就是在调用硬件乘法器呀!而且我看硬件乘法器对应的寄存器,也确实有变化,这就说明了确实使用了硬件乘法器,只是这个速度不知道为什么慢这么多。

我的测试代码:

#include "config.h"
#include "msp_uart.h"
#include "msp_tim.h"

int main(void)
{
uint32_t res, sum;
// float a,b,c;
WDTCTL = WDTPW+WDTHOLD_L;
Led_Init();
USCI_A1_Init();
PM5CTL0 &= ~LOCKLPM5;
Clock_Init();
_EINT();
while(1)
{
/* 第一部分代码 */
printf("\n Part1 \n");
TimerA1_Init();
for(uint16_t i=0; i<1000; i++)
{
res=i*i;
sum += res;
}
TimerA1_Stop();
printf("Time->%ld us\n", Tick);
printf("%ld\n", sum);
Tick=0;
sum=0;

/* 第二部分代码 */
printf("\n Part2 \n");
TimerA1_Init();
for(uint16_t i=0; i<1000; i++)
{
MPY_INT16(i, i, res);
sum += res;
}
TimerA1_Stop();
printf("Time->%ld us\n", Tick);
printf("%ld\n", sum);
Tick=0;
sum=0;

LED1_Blink();
Delay_Ms(500);


}

}

输出结果:

 Part1:

Time->3999 us

332833500

Part2:me->2332 us

332833500