Update tizen 2.0 beta source
[profile/ivi/liboil.git] / testsuite / test1.c
1 /*
2  * LIBOIL - Library of Optimized Inner Loops
3  * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27
28
29 #include <stdio.h>
30 #include <liboil/liboil.h>
31 #include <ctype.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <math.h>
35
36 #include <liboil/liboilprototype.h>
37 #include <liboil/liboiltest.h>
38 #include <liboil/liboilcpu.h>
39
40 void hist(OilTest *Test);
41
42 int main (int argc, char *argv[])
43 {
44   OilFunctionClass *klass;
45   OilFunctionImpl *impl;
46   OilTest *test;
47   int i;
48   int n;
49   //int j;
50   int ret;
51   unsigned int cpu_flags;
52
53   oil_init ();
54
55   cpu_flags = oil_cpu_get_flags ();
56   n = oil_class_get_n_classes ();
57   for (i=0;i<n; i++ ){
58     klass = oil_class_get_by_index(i);
59
60     printf("%s\n", klass->name);
61
62     test = oil_test_new (klass);
63     if (test == NULL) {
64       printf("  bad prototype\n");
65       continue;
66     }
67
68     for (impl = klass->first_impl; impl; impl = impl->next) {
69       printf("  %s\n", impl->name);
70       if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags) {
71         printf("    not supported\n");
72       } else {
73
74         test->n = 1600;
75
76         ret = oil_test_check_impl (test, impl);
77         if (ret) {
78 #if 0
79           printf("    %lu %g\n",test->prof.min,
80               (double)test->prof.total/test->prof.n);
81           for(j=0;j<test->prof.hist_n;j++){
82             printf("    %lu %d\n",test->prof.hist_time[j],test->prof.hist_count[j]);
83           }
84 #endif
85           printf("    ave=%g std=%g\n", impl->profile_ave, impl->profile_std);
86           //hist(test);
87         } else {
88           printf("  not tested\n");
89           break;
90         }
91       }
92     }
93
94     oil_test_free (test);
95   }
96
97   return 0;
98 }
99
100
101 void
102 hist(OilTest *test)
103 {
104   double ave;
105   double std;
106   int max_i;
107   double off;
108   double s;
109   double s2;
110   int i;
111   int n;
112   double x;
113
114   do {
115     s = s2 = 0;
116     n = 0;
117     max_i = -1;
118     for(i=0;i<10;i++){
119       x = test->prof.hist_time[i];
120       s2 += x * x * test->prof.hist_count[i];
121       s += x * test->prof.hist_count[i];
122       n += test->prof.hist_count[i];
123       if (test->prof.hist_count[i] > 0) {
124         if (max_i == -1 || test->prof.hist_time[i] > test->prof.hist_time[max_i]) {
125           max_i = i;
126         }
127       }
128     }
129
130     ave = s / n;
131     std = sqrt (s2 - s * s / n + n*n) / (n-1);
132     off = (test->prof.hist_time[max_i] - ave)/std;
133
134     printf("    ave=%g std=%g max=%ld off=%g %s\n",
135         ave, std, test->prof.hist_time[max_i], off, (off>4.0)?"yes":"no");
136
137     if (off > 4.0) {
138       test->prof.hist_count[max_i] = 0;
139     }
140   } while (off > 4.0);
141   printf("    ave=%g std=%g\n", ave, std);
142 }
143
144