I need to implement the following loop in Neon.
int jump=4,c[8],i; //c[8] may be declared here
int *src,sum=0; //**EDIT:** src points to a 256 element array
for (i = 0; i < 4; i++)
{
sum = src[ i + 0 * jump] * c[0];//1
sum += src[ i + 1 * jump] * c[1];//2
sum += src[ i + 2 * jump] * c[2];//3
sum += src[ i + 3 * jump] * c[3];//4
sum += src[ i + 4 * jump] * c[4];//5
sum += src[ i + 5 * jump] * c[5];//6
sum += src[ i + 6 * jump] * c[6];//7
sum += src[ i + 7 * jump] * c[7];//8
src += 2; //9
}
**EDIT:**
The code can be shortened as-
int jump=4,c[8],i,j; //initialize array c
int *src,sum,a[256];//initialize array a
src=a;
for (i = 0; i < 4; i++)
{
sum=0;
for (j = 0; j < 8; j++)
{
int *p=src+ i + (j * jump);
sum += (*p)* c[j]; //sum += src[ i + j* jump] * c[j]
}
printf("Sum:%d\n",sum);
src += 2;
}
Just need to know a way to implement something like [%0]=[%0]+4 rather than [%0]!
The main optimization will come by running the instructions numbered 1-8 in parallel using VMLA instruction in NEON.
- We may do that by loading array c[8] into registers q0 and q1 and loading array src[256] into registers q2 and q3.After this we use VMLA,VADD,VPADD to get the result in the variable sum.
- The problem being faced is how to load the elements of array src (as src[0],src[4],src[8] and so on)since the only way i know how to load an array is by [%1]! which only loads an array sequentially(as src[0],src[1],src[2] and so on).
Also how may the pointer src be incremented by 2 in instruction 9?