Initial commit to Gerrit
[profile/ivi/orc.git] / testsuite / exec_opcodes_sys.c
1
2 #include "config.h"
3
4 #include <stdio.h>
5
6 #include <orc/orc.h>
7 #include <orc-test/orctest.h>
8
9
10 int error = FALSE;
11 int verbose = FALSE;
12
13 void test_opcode_src (OrcStaticOpcode *opcode);
14 void test_opcode_const (OrcStaticOpcode *opcode);
15 void test_opcode_param (OrcStaticOpcode *opcode);
16 void test_opcode_inplace (OrcStaticOpcode *opcode);
17 void test_opcode_src_2d (OrcStaticOpcode *opcode);
18 void test_opcode_src_const_n (OrcStaticOpcode *opcode);
19 void test_opcode_src_const_n_2d (OrcStaticOpcode *opcode);
20
21 int
22 main (int argc, char *argv[])
23 {
24   int i;
25   OrcOpcodeSet *opcode_set;
26
27   orc_test_init();
28   orc_init();
29
30   opcode_set = orc_opcode_set_get ("sys");
31
32   for(i=0;i<opcode_set->n_opcodes;i++){
33     if (verbose) printf("%s src %d,%d,%d,%d\n",
34         opcode_set->opcodes[i].name,
35         opcode_set->opcodes[i].dest_size[0],
36         opcode_set->opcodes[i].dest_size[1],
37         opcode_set->opcodes[i].src_size[0],
38         opcode_set->opcodes[i].src_size[1]);
39     test_opcode_src (opcode_set->opcodes + i);
40   }
41   for(i=0;i<opcode_set->n_opcodes;i++){
42     if (verbose) printf("%s const %d,%d,%d\n",
43         opcode_set->opcodes[i].name,
44         opcode_set->opcodes[i].dest_size[0],
45         opcode_set->opcodes[i].src_size[0],
46         opcode_set->opcodes[i].src_size[1]);
47     test_opcode_const (opcode_set->opcodes + i);
48   }
49   for(i=0;i<opcode_set->n_opcodes;i++){
50     if (verbose) printf("%s param %d,%d,%d\n",
51         opcode_set->opcodes[i].name,
52         opcode_set->opcodes[i].dest_size[0],
53         opcode_set->opcodes[i].src_size[0],
54         opcode_set->opcodes[i].src_size[1]);
55     test_opcode_param (opcode_set->opcodes + i);
56   }
57   for(i=0;i<opcode_set->n_opcodes;i++){
58     if (verbose) printf("%s inplace %d,%d,%d\n",
59         opcode_set->opcodes[i].name,
60         opcode_set->opcodes[i].dest_size[0],
61         opcode_set->opcodes[i].src_size[0],
62         opcode_set->opcodes[i].src_size[1]);
63     test_opcode_inplace (opcode_set->opcodes + i);
64   }
65   for(i=0;i<opcode_set->n_opcodes;i++){
66     if (verbose) printf("%s src 2d %d,%d,%d\n",
67         opcode_set->opcodes[i].name,
68         opcode_set->opcodes[i].dest_size[0],
69         opcode_set->opcodes[i].src_size[0],
70         opcode_set->opcodes[i].src_size[1]);
71     test_opcode_src_2d (opcode_set->opcodes + i);
72   }
73   for(i=0;i<opcode_set->n_opcodes;i++){
74     if (verbose) printf("%s src const n %d,%d,%d\n",
75         opcode_set->opcodes[i].name,
76         opcode_set->opcodes[i].dest_size[0],
77         opcode_set->opcodes[i].src_size[0],
78         opcode_set->opcodes[i].src_size[1]);
79     test_opcode_src_const_n (opcode_set->opcodes + i);
80   }
81   for(i=0;i<opcode_set->n_opcodes;i++){
82     if (verbose) printf("%s src const n 2d %d,%d,%d\n",
83         opcode_set->opcodes[i].name,
84         opcode_set->opcodes[i].dest_size[0],
85         opcode_set->opcodes[i].src_size[0],
86         opcode_set->opcodes[i].src_size[1]);
87     test_opcode_src_const_n_2d (opcode_set->opcodes + i);
88   }
89
90   if (error) return 1;
91   return 0;
92 }
93
94 void
95 test_opcode_src (OrcStaticOpcode *opcode)
96 {
97   OrcProgram *p;
98   char s[40];
99   int ret;
100   int flags = 0;
101
102   if (opcode->flags & ORC_STATIC_OPCODE_SCALAR) {
103     return;
104   }
105
106   p = orc_program_new ();
107   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
108     orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
109   } else {
110     orc_program_add_destination (p, opcode->dest_size[0], "d1");
111   }
112   if (opcode->dest_size[1] != 0) {
113     orc_program_add_destination (p, opcode->dest_size[1], "d2");
114   }
115   orc_program_add_source (p, opcode->src_size[0], "s1");
116   if (opcode->src_size[1] != 0) {
117     orc_program_add_source (p, opcode->src_size[1], "s2");
118   }
119
120   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
121       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
122     flags = ORC_TEST_FLAGS_FLOAT;
123   }
124
125   sprintf(s, "test_s_%s", opcode->name);
126   orc_program_set_name (p, s);
127
128   if (opcode->dest_size[1] != 0) {
129     orc_program_append_dds_str (p, opcode->name, "d1", "d2", "s1");
130   } else {
131     orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
132   }
133
134   ret = orc_test_compare_output_full (p, flags);
135   if (!ret) {
136     printf("test failed\n");
137     error = TRUE;
138   }
139
140   orc_program_free (p);
141 }
142
143 void
144 test_opcode_const (OrcStaticOpcode *opcode)
145 {
146   OrcProgram *p;
147   char s[40];
148   int ret;
149   int flags = 0;
150   int args[4] = { -1, -1, -1, -1 };
151   int n_args = 0;
152
153   if (opcode->src_size[1] == 0) {
154     return;
155   }
156   p = orc_program_new ();
157   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
158     args[n_args++] =
159       orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
160   } else {
161     args[n_args++] =
162       orc_program_add_destination (p, opcode->dest_size[0], "d1");
163   }
164   if (opcode->dest_size[1] != 0) {
165     args[n_args++] =
166       orc_program_add_destination (p, opcode->dest_size[1], "d2");
167   }
168   args[n_args++] =
169     orc_program_add_source (p, opcode->src_size[0], "s1");
170   args[n_args++] =
171     orc_program_add_constant (p, opcode->src_size[1], 1, "c1");
172   if (opcode->src_size[2]) {
173     args[n_args++] =
174       orc_program_add_constant (p, opcode->src_size[2], 1, "c2");
175   }
176
177   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
178       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
179     flags = ORC_TEST_FLAGS_FLOAT;
180   }
181
182   sprintf(s, "test_const_%s", opcode->name);
183   orc_program_set_name (p, s);
184
185   orc_program_append_2 (p, opcode->name, 0, args[0], args[1],
186       args[2], args[3]);
187
188   ret = orc_test_compare_output_full (p, flags);
189   if (!ret) {
190     printf("test failed\n");
191     error = TRUE;
192   }
193
194   orc_program_free (p);
195 }
196
197 void
198 test_opcode_param (OrcStaticOpcode *opcode)
199 {
200   OrcProgram *p;
201   char s[40];
202   int ret;
203   int flags = 0;
204   int args[4] = { -1, -1, -1, -1 };
205   int n_args = 0;
206
207   if (opcode->src_size[1] == 0) {
208     return;
209   }
210   p = orc_program_new ();
211   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
212     args[n_args++] =
213       orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
214   } else {
215     args[n_args++] =
216       orc_program_add_destination (p, opcode->dest_size[0], "d1");
217   }
218   if (opcode->dest_size[1] != 0) {
219     args[n_args++] =
220       orc_program_add_destination (p, opcode->dest_size[1], "d2");
221   }
222   args[n_args++] =
223     orc_program_add_source (p, opcode->src_size[0], "s1");
224   args[n_args++] =
225     orc_program_add_parameter (p, opcode->src_size[1], "p1");
226   if (opcode->src_size[2]) {
227     args[n_args++] =
228       orc_program_add_parameter (p, opcode->src_size[2], "p2");
229   }
230
231   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
232       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
233     flags = ORC_TEST_FLAGS_FLOAT;
234   }
235
236   sprintf(s, "test_p_%s", opcode->name);
237   orc_program_set_name (p, s);
238
239   orc_program_append_2 (p, opcode->name, 0, args[0], args[1],
240       args[2], args[3]);
241
242   ret = orc_test_compare_output_full (p, flags);
243   if (!ret) {
244     printf("test failed\n");
245     error = TRUE;
246   }
247
248   orc_program_free (p);
249 }
250
251 void
252 test_opcode_inplace (OrcStaticOpcode *opcode)
253 {
254   OrcProgram *p;
255   char s[40];
256   int ret;
257   int flags = 0;
258
259   if (opcode->dest_size[0] != opcode->src_size[0]) return;
260
261   if (opcode->flags & ORC_STATIC_OPCODE_SCALAR ||
262       opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
263     return;
264   }
265
266   p = orc_program_new ();
267   orc_program_add_destination (p, opcode->dest_size[0], "d1");
268   if (opcode->dest_size[1] != 0) {
269     orc_program_add_destination (p, opcode->dest_size[1], "d2");
270   }
271   if (opcode->src_size[1] != 0) {
272     orc_program_add_source (p, opcode->src_size[0], "s2");
273   }
274
275   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
276       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
277     flags = ORC_TEST_FLAGS_FLOAT;
278   }
279
280   sprintf(s, "test_inplace_%s", opcode->name);
281   orc_program_set_name (p, s);
282
283   orc_program_append_str (p, opcode->name, "d1", "d1", "s2");
284
285   ret = orc_test_compare_output_full (p, flags);
286   if (!ret) {
287     printf("test failed\n");
288     error = TRUE;
289   }
290
291   orc_program_free (p);
292 }
293
294 void
295 test_opcode_src_2d (OrcStaticOpcode *opcode)
296 {
297   OrcProgram *p;
298   char s[40];
299   int ret;
300   int flags = 0;
301
302   if (opcode->flags & ORC_STATIC_OPCODE_SCALAR) {
303     return;
304   }
305
306   p = orc_program_new ();
307   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
308     orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
309   } else {
310     orc_program_add_destination (p, opcode->dest_size[0], "d1");
311   }
312   if (opcode->dest_size[1] != 0) {
313     orc_program_add_destination (p, opcode->dest_size[1], "d2");
314   }
315   orc_program_add_source (p, opcode->src_size[0], "s1");
316   if (opcode->src_size[1] != 0) {
317     orc_program_add_source (p, opcode->src_size[1], "s2");
318   }
319
320   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
321       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
322     flags = ORC_TEST_FLAGS_FLOAT;
323   }
324
325   sprintf(s, "test_s_%s", opcode->name);
326   orc_program_set_name (p, s);
327   orc_program_set_2d (p);
328
329   if (opcode->dest_size[1] != 0) {
330     orc_program_append_dds_str (p, opcode->name, "d1", "d2", "s1");
331   } else {
332     orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
333   }
334
335   ret = orc_test_compare_output_full (p, flags);
336   if (!ret) {
337     printf("test failed\n");
338     error = TRUE;
339   }
340
341   orc_program_free (p);
342 }
343
344 void
345 test_opcode_src_const_n (OrcStaticOpcode *opcode)
346 {
347   OrcProgram *p;
348   char s[40];
349   int ret;
350   int flags = 0;
351
352   if (opcode->flags & ORC_STATIC_OPCODE_SCALAR) {
353     return;
354   }
355
356   p = orc_program_new ();
357   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
358     orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
359   } else {
360     orc_program_add_destination (p, opcode->dest_size[0], "d1");
361   }
362   if (opcode->dest_size[1] != 0) {
363     orc_program_add_destination (p, opcode->dest_size[1], "d2");
364   }
365   orc_program_add_source (p, opcode->src_size[0], "s1");
366   if (opcode->src_size[1] != 0) {
367     orc_program_add_source (p, opcode->src_size[1], "s2");
368   }
369
370   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
371       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
372     flags = ORC_TEST_FLAGS_FLOAT;
373   }
374
375   sprintf(s, "test_s_%s", opcode->name);
376   orc_program_set_name (p, s);
377   orc_program_set_constant_n (p, 8);
378
379   if (opcode->dest_size[1] != 0) {
380     orc_program_append_dds_str (p, opcode->name, "d1", "d2", "s1");
381   } else {
382     orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
383   }
384
385   ret = orc_test_compare_output_full (p, flags);
386   if (!ret) {
387     printf("test failed\n");
388     error = TRUE;
389   }
390
391   orc_program_free (p);
392 }
393
394 void
395 test_opcode_src_const_n_2d (OrcStaticOpcode *opcode)
396 {
397   OrcProgram *p;
398   char s[40];
399   int ret;
400   int flags = 0;
401
402   if (opcode->flags & ORC_STATIC_OPCODE_SCALAR) {
403     return;
404   }
405
406   p = orc_program_new ();
407   if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
408     orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
409   } else {
410     orc_program_add_destination (p, opcode->dest_size[0], "d1");
411   }
412   if (opcode->dest_size[1] != 0) {
413     orc_program_add_destination (p, opcode->dest_size[1], "d2");
414   }
415   orc_program_add_source (p, opcode->src_size[0], "s1");
416   if (opcode->src_size[1] != 0) {
417     orc_program_add_source (p, opcode->src_size[1], "s2");
418   }
419
420   if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
421       (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
422     flags = ORC_TEST_FLAGS_FLOAT;
423   }
424
425   sprintf(s, "test_s_%s", opcode->name);
426   orc_program_set_name (p, s);
427   orc_program_set_2d (p);
428   orc_program_set_constant_n (p, 8);
429
430   if (opcode->dest_size[1] != 0) {
431     orc_program_append_dds_str (p, opcode->name, "d1", "d2", "s1");
432   } else {
433     orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
434   }
435
436   ret = orc_test_compare_output_full (p, flags);
437   if (!ret) {
438     printf("test failed\n");
439     error = TRUE;
440   }
441
442   orc_program_free (p);
443 }
444