Initial commit to Gerrit
[profile/ivi/orc.git] / testsuite / test_accsadubl.c
1
2 #include "config.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include <orc/orc.h>
8 #include <orc/orcdebug.h>
9
10
11 int error = FALSE;
12
13 void test_opcode (OrcStaticOpcode *opcode);
14
15 orc_uint8 array1[100];
16 orc_uint8 array2[100];
17
18 int orc_sad_u8 (orc_uint8 *s1, orc_uint8 *s2, int n);
19
20 int
21 main (int argc, char *argv[])
22 {
23   int i;
24   int n;
25   int sum;
26
27   orc_init();
28
29   for(n=0;n<20;n++){
30     sum = 0;
31     for(i=0;i<n;i++){
32       array1[i] = rand();
33       array2[i] = rand();
34       sum += abs(array1[i] - array2[i]);
35     }
36     if (sum != orc_sad_u8 (array1, array2, n)) {
37       for(i=0;i<n;i++){
38         printf("%d: %d %d -> %d\n", i, array1[i], array2[i],
39             abs(array1[i] - array2[i]));
40       }
41
42       printf("sum %d %d\n", sum, orc_sad_u8 (array1, array2, n));
43       error = TRUE;
44     }
45   }
46
47   if (error) return 1;
48   return 0;
49 }
50
51
52 int
53 orc_sad_u8 (orc_uint8 *s1, orc_uint8 *s2, int n)
54 {
55   static OrcProgram *p = NULL;
56   OrcExecutor *ex;
57   int sum;
58   OrcCompileResult result;
59
60   if (p == NULL) {
61     p = orc_program_new ();
62     orc_program_add_accumulator (p, 4, "a1");
63     orc_program_add_source (p, 1, "s1");
64     orc_program_add_source (p, 1, "s2");
65
66     orc_program_append_str (p, "accsadubl", "a1", "s1", "s2");
67
68     result = orc_program_compile (p);
69     if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) {
70       return 0;
71     }
72
73     //printf("%s\n", orc_program_get_asm_code (p));
74   }
75
76   ex = orc_executor_new (p);
77   orc_executor_set_n (ex, n);
78   orc_executor_set_array_str (ex, "s1", s1);
79   orc_executor_set_array_str (ex, "s2", s2);
80
81   orc_executor_run (ex);
82
83   //sum = orc_executor_get_accumulator (ex, "a1");
84   sum = ex->accumulators[0];
85
86   orc_executor_free (ex);
87
88   return sum;
89 }
90
91