#define WORD_ALIGNED(x) (_nassert(((int)(x) & 0x3) == 0))
/*输入参数加上关键字restrict,内存独立声明,xptr yptr指向的区域不重合*/
void lesson3_c(short * restrict xptr, short * restrict yptr, short *zptr,
short *w_sum, int N)
{
int i, w_vec1, w_vec2;
short w1, w2;
/*保证xptr yptr是四字节对齐的,编程者负责要保证这一点*/
WORD_ALIGNED(xptr);
WORD_ALIGNED(yptr);
w1 = zptr[0];
w2 = zptr[1];
/*最小循环20次,循环的次数是2的倍数*/
#pragma MUST_ITERATE(20, , 2);
for (i = 0; i < N; i++)
{
w_vec1 = xptr * w1;
w_vec2 = yptr * w2;
w_sum = (w_vec1 + w_vec2) >> 15;
}
} |