The sample program vmx_sample illustrates the ease with which vector instructions can be incorporated into a PPE program.
#include <stdio.h>
// Define a type we can look at either as an array of ints or as a vector.
typedef union {
int iVals[4];
vector signed int myVec;
} vecVar;
int main()
{
vecVar v1, v2, vConst; // define variables
// load the literal value 2 into the 4 positions in vConst,
vConst.myVec = (vector signed int){2, 2, 2, 2};
// load 4 values into the 4 element of vector v1
v1.myVec = (vector signed int){10, 20, 30, 40};
// call vector add function
v2.myVec = vec_add( v1.myVec, vConst.myVec );
// see what we got!
printf("\nResults:\nv2[0] = %d, v2[1] = %d, v2[2] = %d, v2[3] = %d\n\n",
v2.iVals[0], v2.iVals[1], v2.iVals[2], v2.iVals[3]);
return 0;
}
See Developing code for the Cell Broadband Engine for more information on how to run the example on the simulator.