Initial commit to Gerrit
[profile/ivi/orc.git] / testsuite / generate_xml_table2.c
1
2 #include "config.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include <orc/orc.h>
9 #include <orc-test/orctest.h>
10
11
12 int error = FALSE;
13
14 char * get_desc (OrcStaticOpcode *opcode);
15 char * get_code (OrcStaticOpcode *opcode);
16
17 int
18 main (int argc, char *argv[])
19 {
20   int i;
21   OrcOpcodeSet *opcode_set;
22   OrcTarget *targets[10];
23   unsigned int target_flags[10];
24   int n_targets;
25
26   orc_init();
27   orc_test_init();
28
29   targets[0] = orc_target_get_by_name("sse");
30   target_flags[0] = orc_target_get_default_flags(targets[0]);
31
32   targets[1] = orc_target_get_by_name("mmx");
33   target_flags[1] = orc_target_get_default_flags(targets[1]);
34
35   targets[2] = orc_target_get_by_name("altivec");
36   target_flags[2] = orc_target_get_default_flags(targets[2]);
37
38   targets[3] = orc_target_get_by_name("arm");
39   target_flags[3] = orc_target_get_default_flags(targets[3]);
40
41   targets[4] = orc_target_get_by_name("c64x-c");
42   target_flags[4] = orc_target_get_default_flags(targets[4]);
43
44   n_targets=5;
45   
46   printf(
47 "<table frame=\"all\" id=\"table-basictypes\" xreflabel=\"Table of Opcodes\">\n"
48 "<title>Table of Opcodes</title>\n"
49 "<tgroup cols=\"3\" align=\"left\" colsep=\"1\" rowsep=\"1\">\n"
50 "<thead>\n"
51 "<row>\n"
52 "<entry>opcode</entry>\n"
53 "<entry>destination size</entry>\n"
54 "<entry>source 1 size</entry>\n"
55 "<entry>source 2 size</entry>\n"
56 "<entry>description</entry>\n"
57 "<entry>pseudo code</entry>\n"
58 "</row>\n"
59 "</thead>\n"
60 "<tbody valign=\"top\">\n");
61
62   opcode_set = orc_opcode_set_get ("sys");
63
64   for(i=0;i<opcode_set->n_opcodes;i++){
65     printf("<row>\n");
66     printf("<entry>%s</entry>\n", opcode_set->opcodes[i].name);
67     printf("<entry>%d</entry>\n", opcode_set->opcodes[i].dest_size[0]);
68     printf("<entry>%d</entry>\n", opcode_set->opcodes[i].src_size[0]);
69     if (opcode_set->opcodes[i].src_size[1]) {
70       printf("<entry>%d%s</entry>\n", opcode_set->opcodes[i].src_size[1],
71           (opcode_set->opcodes[i].flags & ORC_STATIC_OPCODE_SCALAR) ? "S" : "");
72     } else {
73       printf("<entry></entry>\n");
74     }
75     printf("<entry>%s</entry>\n", get_desc(&opcode_set->opcodes[i]));
76     printf("<entry>%s</entry>\n", get_code(&opcode_set->opcodes[i]));
77     printf("</row>\n");
78   }
79   printf(
80 "</tbody>\n"
81 "</tgroup>\n"
82 "</table>\n");
83
84   return 0;
85 }
86
87 struct a {
88   char *name;
89   char *code;
90   char *desc;
91 };
92
93 struct a ops[] = {
94   { "absb", "(a &lt; 0) ? -a : a", "absolute value" },
95   { "addb", "a + b", "add" },
96   { "addssb", "clamp(a + b)", "add with signed saturate" },
97   { "addusb", "clamp(a + b)", "add with unsigned saturate" },
98   { "andb", "a &amp; b", "bitwise AND" },
99   { "andnb", "a &amp; (~b)", "bitwise AND NOT" },
100   { "avgsb", "(a + b + 1)&gt;&gt;1", "signed average" },
101   { "avgub", "(a + b + 1)&gt;&gt;1", "unsigned average" },
102   { "cmpeqb", "(a == b) ? (~0) : 0", "compare equal" },
103   { "cmpgtsb", "(a &gt; b) ? (~0) : 0", "compare greater than" },
104   { "copyb", "a", "copy" },
105   { "maxsb", "(a &gt; b) ? a : b", "signed maximum" },
106   { "maxub", "(a &gt; b) ? a : b", "unsigned maximum" },
107   { "minsb", "(a &lt; b) ? a : b", "signed minimum" },
108   { "minub", "(a &lt; b) ? a : b", "unsigned minimum" },
109   { "mullb", "a * b", "low bits of multiply" },
110   { "mulhsb", "(a * b) &gt;&gt; 8", "high bits of signed multiply" },
111   { "mulhub", "(a * b) &gt;&gt; 8", "high bits of unsigned multiply" },
112   { "orb", "a | b", "bitwise or" },
113   { "shlb", "a &lt;&lt; b", "shift left" },
114   { "shrsb", "a &gt;&gt; b", "signed shift right" },
115   { "shrub", "a &gt;&gt; b", "unsigned shift right" },
116   { "signb", "sign(a)", "sign" },
117   { "subb", "a - b", "subtract" },
118   { "subssb", "clamp(a - b)", "subtract with signed saturate" },
119   { "subusb", "clamp(a - b)", "subtract with unsigned saturate" },
120   { "xorb", "a ^ b", "bitwise XOR" },
121
122   { "absw", "(a &lt; 0) ? -a : a", "absolute value" },
123   { "addw", "a + b", "add" },
124   { "addssw", "clamp(a + b)", "add with signed saturate" },
125   { "addusw", "clamp(a + b)", "add with unsigned saturate" },
126   { "andw", "a &amp; b", "bitwise AND" },
127   { "andnw", "a &amp; (~b)", "bitwise AND NOT" },
128   { "avgsw", "(a + b + 1)&gt;&gt;1", "signed average" },
129   { "avguw", "(a + b + 1)&gt;&gt;1", "unsigned average" },
130   { "cmpeqw", "(a == b) ? (~0) : 0", "compare equal" },
131   { "cmpgtsw", "(a &gt; b) ? (~0) : 0", "compare greater than" },
132   { "copyw", "a", "copy" },
133   { "maxsw", "(a &gt; b) ? a : b", "signed maximum" },
134   { "maxuw", "(a &gt; b) ? a : b", "unsigned maximum" },
135   { "minsw", "(a &lt; b) ? a : b", "signed minimum" },
136   { "minuw", "(a &lt; b) ? a : b", "unsigned minimum" },
137   { "mullw", "a * b", "low bits of multiply" },
138   { "mulhsw", "(a * b) &gt;&gt; 8", "high bits of signed multiply" },
139   { "mulhuw", "(a * b) &gt;&gt; 8", "high bits of unsigned multiply" },
140   { "orw", "a | b", "bitwise or" },
141   { "shlw", "a &lt;&lt; b", "shift left" },
142   { "shrsw", "a &gt;&gt; b", "signed shift right" },
143   { "shruw", "a &gt;&gt; b", "unsigned shift right" },
144   { "signw", "sign(a)", "sign" },
145   { "subw", "a - b", "subtract" },
146   { "subssw", "clamp(a - b)", "subtract with signed saturate" },
147   { "subusw", "clamp(a - b)", "subtract with unsigned saturate" },
148   { "xorw", "a ^ b", "bitwise XOR" },
149
150   { "absl", "(a &lt; 0) ? -a : a", "absolute value" },
151   { "addl", "a + b", "add" },
152   { "addssl", "clamp(a + b)", "add with signed saturate" },
153   { "addusl", "clamp(a + b)", "add with unsigned saturate" },
154   { "andl", "a &amp; b", "bitwise AND" },
155   { "andnl", "a &amp; (~b)", "bitwise AND NOT" },
156   { "avgsl", "(a + b + 1)&gt;&gt;1", "signed average" },
157   { "avgul", "(a + b + 1)&gt;&gt;1", "unsigned average" },
158   { "cmpeql", "(a == b) ? (~0) : 0", "compare equal" },
159   { "cmpgtsl", "(a &gt; b) ? (~0) : 0", "compare greater than" },
160   { "copyl", "a", "copy" },
161   { "maxsl", "(a &gt; b) ? a : b", "signed maximum" },
162   { "maxul", "(a &gt; b) ? a : b", "unsigned maximum" },
163   { "minsl", "(a &lt; b) ? a : b", "signed minimum" },
164   { "minul", "(a &lt; b) ? a : b", "unsigned minimum" },
165   { "mulll", "a * b", "low bits of multiply" },
166   { "mulhsl", "(a * b) &gt;&gt; 16", "high bits of signed multiply" },
167   { "mulhul", "(a * b) &gt;&gt; 16", "high bits of unsigned multiply" },
168   { "orl", "a | b", "bitwise or" },
169   { "shll", "a &lt;&lt; b", "shift left" },
170   { "shrsl", "a &gt;&gt; b", "signed shift right" },
171   { "shrul", "a &gt;&gt; b", "unsigned shift right" },
172   { "signl", "sign(a)", "sign" },
173   { "subl", "a - b", "subtract" },
174   { "subssl", "clamp(a - b)", "subtract with signed saturate" },
175   { "subusl", "clamp(a - b)", "subtract with unsigned saturate" },
176   { "xorl", "a ^ b", "bitwise XOR" },
177
178   { "convsbw", "a", "convert signed" },
179   { "convubw", "a", "convert unsigned" },
180   { "convswl", "a", "convert signed" },
181   { "convuwl", "a", "convert unsigned" },
182   { "convwb", "a", "convert" },
183   { "convssswb", "clamp(a)", "convert signed to signed with saturation" },
184   { "convsuswb", "clamp(a)", "convert signed to unsigned with saturation" },
185   { "convusswb", "clamp(a)", "convert unsigned to signed with saturation" },
186   { "convuuswb", "clamp(a)", "convert unsigned to unsigned with saturation" },
187   { "convlw", "a", "convert" },
188   { "convssslw", "clamp(a)", "convert signed to signed with saturation" },
189   { "convsuslw", "clamp(a)", "convert signed to unsigned with saturation" },
190   { "convusslw", "clamp(a)", "convert unsigned to signed with saturation" },
191   { "convuuslw", "clamp(a)", "convert unsigned to unsigned with saturation" },
192   { "mulsbw", "a * b", "multiply signed" },
193   { "mulubw", "a * b", "multiply unsigned" },
194   { "mulswl", "a * b", "multiply signed" },
195   { "muluwl", "a * b", "multiply unsigned" },
196   { "mergewl", "special", "merge halves" },
197   { "mergebw", "special", "merge halves" },
198   { "select0wb", "special", "select first half" },
199   { "select1wb", "special", "select second half" },
200   { "select0lw", "special", "select first half" },
201   { "select1lw", "special", "select second half" },
202   { "swapw", "special", "endianness swap" },
203   { "swapl", "special", "endianness swap" },
204
205   { "accw", "+= a", "accumulate" },
206   { "accl", "+= a", "accumulate" },
207   { "accsadubl", "+= abs(a - b)", "accumulate absolute difference" },
208
209   { "splitlw" , "special", "split first/second words" },
210   { "splitwb" , "special", "split first/second bytes" },
211   { "addf", "a + b", "add" },
212   { "subf", "a - b", "subtract" },
213   { "mulf", "a * b", "multiply" },
214   { "divf", "a / b", "divide" },
215   { "sqrtf", "sqrt(a)", "square root" },
216   { "maxf", "max(a,b)", "maximum" },
217   { "minf", "min(a,b)", "minimum" },
218   { "cmpeqf", "(a == b) ? (~0) : 0", "compare equal" },
219   { "cmpltf", "(a == b) ? (~0) : 0", "compare less than" },
220   { "cmplef", "(a == b) ? (~0) : 0", "compare less than or equal" },
221   { "convfl", "a", "convert float point to integer" },
222   { "convlf", "a", "convert integer to floating point" },
223
224   { "loadb", "array[i]", "load from memory" },
225   { "loadw", "array[i]", "load from memory" },
226   { "loadl", "array[i]", "load from memory" },
227   { "loadq", "array[i]", "load from memory" },
228   { "storeb", "special", "store to memory" },
229   { "storew", "special", "store to memory" },
230   { "storel", "special", "store to memory" },
231   { "storeq", "special", "store to memory" },
232   { "loadoffb", "array[i+offset]", "load from memory with offset" },
233   { "loadoffw", "array[i+offset]", "load from memory with offset" },
234   { "loadoffl", "array[i+offset]", "load from memory with offset" },
235   { "loadoffq", "array[i+offset]", "load from memory with offset" },
236   { "loadpb", "scalar", "load parameter or constant" },
237   { "loadpw", "scalar", "load parameter or constant" },
238   { "loadpl", "scalar", "load parameter or constant" },
239   { "loadpq", "scalar", "load parameter or constant" },
240   { "loadupdb", "array[i>>1]", "load upsampled duplicate" },
241   { "loadupib", "(array[i>>1] + array[(i+1)>>1] + 1)>>1",
242     "load upsampled interpolate" },
243   { "ldresnearb", "array[(b+c*i)>>8]", "load, nearest neighbor resampled" },
244   { "ldreslinb", "special", "load, bilinear resampled" },
245   { "ldresnearl", "array[(b+c*i)>>8]", "load, nearest neighbor resampled" },
246   { "ldreslinl", "special", "load, bilinear resampled" },
247   { "div255w", "a/255", "divide by 255" },
248   { "divluw", "clamp(a/(b &amp; 255),0,255)", "saturated unsigned divide 16-bit by 8-bit" },
249   { "splatw3q", "special", "duplicates high 16-bits to lower 48 bits" },
250   { "splatbw", "special", "duplicates 8 bits to both halfs of 16 bits" },
251   { "splatbl", "special", "duplicates 8 bits to all parts of 32 bits" },
252   { "convql", "a", "convert" },
253   { "convslq", "a", "signed convert" },
254   { "convulq", "a", "unsigned convert" },
255   { "convhwb", "a>>8", "shift and convert" },
256   { "convhlw", "a>>16", "shift and convert" },
257   { "convsssql", "clamp(a)", "convert signed to signed with saturation" },
258   { "convsusql", "clamp(a)", "convert signed to unsigned with saturation" },
259   { "convussql", "clamp(a)", "convert unsigned to signed with saturation" },
260   { "convuusql", "clamp(a)", "convert unsigned to unsigned with saturation" },
261
262 };
263
264
265 char *
266 get_desc (OrcStaticOpcode *opcode)
267 {
268   int i;
269   for(i=0;i<sizeof(ops)/sizeof(ops[0]);i++){
270     if (strcmp (opcode->name, ops[i].name) == 0) {
271       return ops[i].desc;
272     }
273   }
274   return "";
275 }
276
277 char *
278 get_code (OrcStaticOpcode *opcode)
279 {
280   int i;
281   for(i=0;i<sizeof(ops)/sizeof(ops[0]);i++){
282     if (strcmp (opcode->name, ops[i].name) == 0) {
283       return ops[i].code;
284     }
285   }
286   return "";
287 }
288