Added statev to sql transform script
[libfirm] / ir / be / test / fehler68.c
1 /************************************************************************
2  * Program:  scalar_product.c
3  * Function: Calculates the scalar product of vector lying in memory
4  *           Used as a test for the simd optimization.
5  * Author:   Andreas Schoesser
6  * Date:     2007-06-13
7  ************************************************************************/
8
9 #include <stdio.h>
10 #include <malloc.h>
11 #include <stdlib.h>
12 #include <time.h>
13
14 float scalar_product(float *a, float *b, unsigned int max_elements);
15
16 main()
17 {
18         float res;
19         int i, max_elements = 100;
20         double  d_zeitdauer;
21
22         // Allocate memory and make sure pointers are aligned to 16 byte addresses
23         char *a = malloc(16 + max_elements * sizeof(float));
24         char *b = malloc(16 + max_elements * sizeof(float));
25         float c;
26         char *ca = &a[0] + 16 - (unsigned int) ((unsigned int) &a[0] % 16);
27         char *cb = &b[0] + 16 - (unsigned int) ((unsigned int) &b[0] % 16);
28
29         float *aa = (float *) ca;
30         float *ab = (float *) cb;
31
32         printf("Scalar product\n==============\n\n");
33
34         //printf("Array Position: %u, %u, %u, %u\n", a, b, aa, ba/*(unsigned int) &aa[0] % 16, (unsigned int) &ba[0] % 16*/);
35
36         // Fill both arrays with random values
37         for(i = 0; i < max_elements; i++)
38         {
39                 aa[i] = (float) (rand() % 10);
40                 ab[i] = (float) (rand() % 10);
41
42                 //printf("(%g * %g)  +  ", a[i], b[i]);
43         }
44
45         //for(i = 0; i < max_elements - 4; i += 4)
46         res = scalar_product(aa, ab, max_elements);
47
48         printf("\nResult: %g\n", res);
49 }
50
51
52 float scalar_product(float * a, float * b, unsigned int max_elements)
53 {
54         float res;
55         int   i;
56
57         /*for(i = 0; i < 4; i++)
58         {
59                 a[i] = (float) (rand() % 10);
60                 b[i] = (float) (rand() % 10);
61
62                 printf("(%g * %g)  +  ", a[i], b[i]);
63         }*/
64
65         for(i = 0; i < max_elements; i += 4)
66                 res += a[i] * b[i] + a[i + 1] * b[i + 1] + a[i + 2] * b[i + 2] + a[i + 3] * b[i + 3];
67
68         return(res);
69 }