// ***************** prog.c ****************************************** // Dsp program sample calculates a*x+y // // (c) multicore.ru // // ******************************************************************* typedef __attribute__((__vector_size__(4 *sizeof(float)))) float _v4f32; float x[200]; float y[200]; float z0[200]; float z1[200]; // // @description: initialize input vectors with some values // void SetupVectors(float *in1, float* in2, int length) { int i, j; for (i = 0; i < length; i++) { in1[i]= i * 2.3 + 1; } for (j = length; j >= 0; j--) { in2[j]= (length-j) * 1.6; } } // // @description: calculate const*vector1+vector2 // void Func0(float *in1, float* in2, float k, float* out, int length) { for (int i = 0; i < length; i++) { out[i]= k * in1[i] + in2[i]; } } // // @description: calculate const*vector1+vector2 by using elcore builtin // functions // void Func1(float *in1, float* in2, float k, float* out, int length) { _v4f32 *x1 = (_v4f32*)in1; _v4f32 *y1 = (_v4f32*)in2; _v4f32 *z1 = (_v4f32*)out; for (int i = 0; i < length/4; i++) { _v4f32 mul =__builtin_cv4f32_mul(k, x1[i]); z1[i] =__builtin_v4f32_add(mul, y1[i]); } } int main() { SetupVectors(x, y, 200); Func0(x, y, 4.0f, z0, 200); Func1(x, y, 4.0f, z1, 200); return 100; }