1 /************************************************************************
2 * Program: vadd_store.c
3 * Function: Add 2 vectors (lying in memory) and store the result in
4 * a another vector in memory.
5 * Used as a test for the simd optimization.
6 * Author: Andreas Schoesser
8 ************************************************************************/
16 //void array_test(int *a[]);
23 printf("1. vload -> vadd -> vstore\n===================\n\n");
26 printf("2. vload -> vadd -> vstore, multi dimensional array, in loop\n==========================================\n\n");
35 /*Also possible: Local pointers instead of function parameters: */
36 //int *a = (int *) alloca(8), *b = (int *) alloca(8), *c = (int *) alloca(8);
40 for(i = 0; i < 2; i++)
47 /* Also possible: Local arrays, but may be optimized so that no pattern is found
48 int a[2], b[2], c[2]; */
51 /* Version 1: Directly adding. */
58 /* Version 2: Adding of local variables
60 int a0, a1, b0, b1, c0, c1;
75 /* Version 3: Mixed adding of locals and pointers
87 for(i = 0; i < 2; i++)
88 printf("%d + %d = %d\n", a[i], b[i], c[i]);
98 /* Version 4: Manually unrolled loop */
101 int d[5][5], e[5][5], f[5][5];
103 for(j = 0; j < 4; j++)
104 for(i = 0; i < 2; i++)
106 e[j][i] = rand() % 10;
107 f[j][i] = rand() % 10;
110 for(j = 0; j < 4; j++)
111 //for(i = 0; i < 2; i ++ )
113 d[j][0] = e[j][0] + f[j][0];
114 d[j][1] = e[j][1] + f[j][1];
117 for(j = 0; j < 4; j++)
119 for(i = 0; i < 2; i++)
120 printf("%d + %d = %d\n", e[j][i], f[j][i], d[j][i]);
127 void array_test(int a[][5])
129 printf("\n a[1][1]: %d\n", a[1][1]);