尽可能避免通用的相同表达式,尤其对于__x128_t类型
对于TMS320C66x编译器而言,那些结果是__x128_t类型的表达式并不会归为相同的表达式,因而可能会重复计算。所以在使用__x128_t数据类型的intrinsic时,尽量吧相同的部分提取出来。如下所示。这种改变不会改变循环的功能功能,但是却能改变性能
void dprod_vcse(double *restrict inputPtr,double *restrict coefsPtr,int
nCoefs,double *restrict sumPtr, int nlength) {
int i, j;
double sumTemp = 0, sumTemp1 = 0, sumTemp2 = 0, sumTemp3 = 0;
for(i = 0; i<nlength/4; i++)
{
for (j = 0; j < nCoefs; j++)
{
sumTemp = _daddsp(sumTemp,_daddsp(_hid128(_cmpysp(inputPtr<span style="font-style: normal;">,coefsPtr</span><span style="font-style: normal;">)),_lod128(_cmpysp(inputPtr</span><span style="font-style: normal;">,coefsPtr</span><span style="font-style: normal;">))));
sumTemp1 = _daddsp(sumTemp1,_daddsp(_hid128(_cmpysp(inputPtr[i+1],coefsPtr</span><span style="font-style: normal;">)),_lod128(_cmpysp(inputPtr[i+1],coefsPtr</span><span style="font-style: normal;">))));
sumTemp2 = _daddsp(sumTemp2,_daddsp(_hid128(_cmpysp(inputPtr[i+2],coefsPtr</span><span style="font-style: normal;">)),_lod128(_cmpysp(inputPtr[i+2],coefsPtr</span><span style="font-style: normal;">))));
sumTemp3 = _daddsp(sumTemp3,_daddsp(_hid128(_cmpysp(inputPtr[i+3],coefsPtr</span><span style="font-style: normal;">)),_lod128(_cmpysp(inputPtr[i+3],coefsPtr</span><span style="font-style: normal;">))));
}
sumPtr</span><span style="font-style: normal;"> = sumTemp;
sumPtr[i+1] = sumTemp1;
sumPtr[i+2] = sumTemp2;
sumPtr[i+3] = sumTemp3;
}
}</span>
修改为
<span style="font-style: normal;">void dprod_novcse(double *restrict inputPtr,double *restrict coefsPtr,int
nCoefs,double *restrict sumPtr, int nlength) {
int i, j;
double sumTemp = 0, sumTemp1 = 0, sumTemp2 = 0, sumTemp3 = 0;
__x128_t cmpysp_temp, cmpysp_temp1, cmpysp_temp2, cmpysp_temp3;
for(i = 0; i<nlength/4; i++)
{
for (j = 0; j < nCoefs; j++)
{
cmpysp_temp = _cmpysp(inputPtr</span><span style="font-style: normal;">,coefsPtr</span><span style="font-style: normal;">);
sumTemp = _daddsp(sumTemp, _daddsp(_hid128(cmpysp_temp),
_lod128(cmpysp_temp)));
cmpysp_temp1 = _cmpysp(inputPtr[i+1],coefsPtr</span><span style="font-style: normal;">);
sumTemp1 = _daddsp(sumTemp1, _daddsp(_hid128(cmpysp_temp1),
_lod128(cmpysp_temp1)));
cmpysp_temp2 = _cmpysp(inputPtr[i+2],coefsPtr</span><span style="font-style: normal;">);
sumTemp2 = _daddsp(sumTemp2, _daddsp(_hid128(cmpysp_temp2),
_lod128(cmpysp_temp2)));
cmpysp_temp3 = _cmpysp(inputPtr[i+3],coefsPtr</span><span style="font-style: normal;">);
sumTemp3 = _daddsp(sumTemp3, _daddsp(_hid128(cmpysp_temp3),
_lod128(cmpysp_temp3)));
}
sumPtr</span><span style="font-style: normal;"> = sumTemp;
sumPtr[i+1] = sumTemp1;
sumPtr[i+2] = sumTemp2;</span>
sumPtr[i+3] = sumTemp3;
}
} |