4.8.利用 DMAC 指令

连乘和累加 (DMAC) 指令可同时对两个相邻的有符号整数(16 位)执行乘法累加运算,并可选择对乘积进行移位。乘法累加运算将两个数相乘,然后将该乘积添加到累加器中。

表 4.8 从 C 源代码生成 DMAC
C 源代码 带 DMAC 的汇编输出
longdmac(int*array1,int*array2,intM){// Assert to the compiler that both arrays are 32bit aligned_nassert((long)array1%2==0);_nassert((long)array2%2==0);// Assert to the compiler that M is even and > 0_nassert((M>0)&&(M%2==0));intj;longsum=0;for(j=0;j<M;j++)sum+=(long)array1[j]*array2[j];returnsum;}
||dmac||: ASR AL,1 MOVL XAR7,XAR5 ADDB AL,#-1 MOVZ AR5,AL MOV P,#0 MOVB ACC,#0 RPT AR5 || DMAC ACC:P,*XAR4++,*XAR7++ ADDL ACC,P LRETR

表 4.8 说明了从 C 源代码生成 DMAC 指令的方法。如需了解详情,请参阅 TMS320C28x 优化 C/C++ 编译器用户指南中的第 3.15 节“编译器对生成 DMAC 指令的支持”。