Updated French translations for GOLD and LD
[binutils-gdb.git] / sim / testsuite / common / bits-tst.c
bloba30753e4b16ab47a7ba20137dc9bf28891b6fbb3
1 # 2 "bits-tst.c"
3 /* Drive the bit test routines */
6 static long long
7 calc (const char *call,
8 long long val,
9 int row,
10 int col)
12 if (strcmp (call, "MASK") == 0)
13 return MASKED (val, row, col);
14 if (strcmp (call, "MASK8") == 0)
15 return MASKED8 (val, row, col);
16 if (strcmp (call, "MASK16") == 0)
17 return MASKED16 (val, row, col);
18 if (strcmp (call, "MASK32") == 0)
19 return MASKED32 (val, row, col);
20 if (strcmp (call, "MASK64") == 0)
21 return MASKED64 (val, row, col);
23 if (strcmp (call, "EXTRACT") == 0)
24 return EXTRACTED (val, row, col);
25 if (strcmp (call, "EXTRACT8") == 0)
26 return EXTRACTED8 (val, row, col);
27 if (strcmp (call, "EXTRACT16") == 0)
28 return EXTRACTED16 (val, row, col);
29 if (strcmp (call, "EXTRACT32") == 0)
30 return EXTRACTED32 (val, row, col);
31 if (strcmp (call, "EXTRACT64") == 0)
32 return EXTRACTED64 (val, row, col);
34 if (strcmp (call, "LSEXTRACT") == 0)
35 return LSEXTRACTED (val, row, col);
36 if (strcmp (call, "LSEXTRACT8") == 0)
37 return LSEXTRACTED8 (val, row, col);
38 if (strcmp (call, "LSEXTRACT16") == 0)
39 return LSEXTRACTED16 (val, row, col);
40 if (strcmp (call, "LSEXTRACT32") == 0)
41 return LSEXTRACTED32 (val, row, col);
42 if (strcmp (call, "LSEXTRACT64") == 0)
43 return LSEXTRACTED64 (val, row, col);
45 if (strcmp (call, "MSEXTRACT") == 0)
46 return MSEXTRACTED (val, row, col);
47 if (strcmp (call, "MSEXTRACT8") == 0)
48 return MSEXTRACTED8 (val, row, col);
49 if (strcmp (call, "MSEXTRACT16") == 0)
50 return MSEXTRACTED16 (val, row, col);
51 if (strcmp (call, "MSEXTRACT32") == 0)
52 return MSEXTRACTED32 (val, row, col);
53 if (strcmp (call, "MSEXTRACT64") == 0)
54 return MSEXTRACTED64 (val, row, col);
56 if (strcmp (call, "INSERT") == 0)
57 return INSERTED (val, row, col);
58 if (strcmp (call, "INSERT8") == 0)
59 return INSERTED8 (val, row, col);
60 if (strcmp (call, "INSERT16") == 0)
61 return INSERTED16 (val, row, col);
62 if (strcmp (call, "INSERT32") == 0)
63 return INSERTED32 (val, row, col);
64 if (strcmp (call, "INSERT64") == 0)
65 return INSERTED64 (val, row, col);
67 if (strcmp (call, "LSINSERT") == 0)
68 return LSINSERTED (val, row, col);
69 if (strcmp (call, "LSINSERT8") == 0)
70 return LSINSERTED8 (val, row, col);
71 if (strcmp (call, "LSINSERT16") == 0)
72 return LSINSERTED16 (val, row, col);
73 if (strcmp (call, "LSINSERT32") == 0)
74 return LSINSERTED32 (val, row, col);
75 if (strcmp (call, "LSINSERT64") == 0)
76 return LSINSERTED64 (val, row, col);
78 if (strcmp (call, "MSINSERT") == 0)
79 return MSINSERTED (val, row, col);
80 if (strcmp (call, "MSINSERT8") == 0)
81 return MSINSERTED8 (val, row, col);
82 if (strcmp (call, "MSINSERT16") == 0)
83 return MSINSERTED16 (val, row, col);
84 if (strcmp (call, "MSINSERT32") == 0)
85 return MSINSERTED32 (val, row, col);
86 if (strcmp (call, "MSINSERT64") == 0)
87 return MSINSERTED64 (val, row, col);
89 if (strcmp (call, "MSMASK") == 0)
90 return MSMASKED (val, row, col);
91 if (strcmp (call, "MSMASK8") == 0)
92 return MSMASKED8 (val, row, col);
93 if (strcmp (call, "MSMASK16") == 0)
94 return MSMASKED16 (val, row, col);
95 if (strcmp (call, "MSMASK32") == 0)
96 return MSMASKED32 (val, row, col);
97 if (strcmp (call, "MSMASK64") == 0)
98 return MSMASKED64 (val, row, col);
100 if (strcmp (call, "LSMASK") == 0)
101 return LSMASKED (val, row, col);
102 if (strcmp (call, "LSMASK8") == 0)
103 return LSMASKED8 (val, row, col);
104 if (strcmp (call, "LSMASK16") == 0)
105 return LSMASKED16 (val, row, col);
106 if (strcmp (call, "LSMASK32") == 0)
107 return LSMASKED32 (val, row, col);
108 if (strcmp (call, "LSMASK64") == 0)
109 return LSMASKED64 (val, row, col);
111 if (strcmp (call, "ROT64") == 0)
112 return ROT64 (val, col);
113 if (strcmp (call, "ROT8") == 0)
114 return ROT8 (val, col);
115 if (strcmp (call, "ROT16") == 0)
116 return ROT16 (val, col);
117 if (strcmp (call, "ROT32") == 0)
118 return ROT32 (val, col);
120 if (strcmp (call, "SEXT") == 0)
121 return SEXT (val, col);
122 if (strcmp (call, "SEXT8") == 0)
123 return SEXT8 (val, col);
124 if (strcmp (call, "SEXT16") == 0)
125 return SEXT16 (val, col);
126 if (strcmp (call, "SEXT32") == 0)
127 return SEXT32 (val, col);
128 if (strcmp (call, "SEXT64") == 0)
129 return SEXT64 (val, col);
131 if (strcmp (call, "LSSEXT") == 0)
132 return LSSEXT (val, col);
133 if (strcmp (call, "LSSEXT8") == 0)
134 return LSSEXT8 (val, col);
135 if (strcmp (call, "LSSEXT16") == 0)
136 return LSSEXT16 (val, col);
137 if (strcmp (call, "LSSEXT32") == 0)
138 return LSSEXT32 (val, col);
139 if (strcmp (call, "LSSEXT64") == 0)
140 return LSSEXT64 (val, col);
142 if (strcmp (call, "MSSEXT8") == 0)
143 return MSSEXT8 (val, col);
144 if (strcmp (call, "MSSEXT16") == 0)
145 return MSSEXT16 (val, col);
146 if (strcmp (call, "MSSEXT32") == 0)
147 return MSSEXT32 (val, col);
148 if (strcmp (call, "MSSEXT64") == 0)
149 return MSSEXT64 (val, col);
150 if (strcmp (call, "MSSEXT") == 0)
151 return MSSEXT (val, col);
153 else
155 fprintf (stderr,
156 "Unknown call passed to calc (%s, 0x%016llx, %d, %d)\n",
157 call, val, row, col);
158 abort ();
159 return val;
164 static int
165 check_sext (int nr_bits,
166 int msb_nr,
167 const char *sexted,
168 const char *masked,
169 const char *msmasked)
171 int errors = 0;
172 int col;
173 for (col = 0; col < nr_bits; col ++)
175 long long mask = calc (masked, -1, col, col);
176 long long msmask = calc (msmasked, -1,
177 0, (msb_nr ? nr_bits - col - 1 : col));
178 long long sext = calc (sexted, mask, -1, col);
179 long long mask_1 = mask >> 1;
180 long long sext_1 = calc (sexted, mask_1, -1, col);
181 long long mask_0 = (mask << 1) | mask_1;
182 long long sext_0 = calc (sexted, mask_0, -1, col);
183 if (sext_0 != mask_1)
185 fprintf (stderr,
186 "%s:%d: ", __FILE__, __LINE__);
187 fprintf (stderr,
188 " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx\n",
189 sexted, mask_0, col, sext_0, mask_1);
190 errors ++;
192 if (sext_1 != mask_1)
194 fprintf (stderr,
195 "%s:%d: ", __FILE__, __LINE__);
196 fprintf (stderr,
197 " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx\n",
198 sexted, mask_1, col, sext_1, mask_1);
199 errors ++;
201 if (sext != msmask)
203 fprintf (stderr,
204 "%s:%d: ", __FILE__, __LINE__);
205 fprintf (stderr,
206 " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx (%s(%d,%d))\n",
207 sexted, mask, col, sext, msmask,
208 msmasked, 0, (msb_nr ? nr_bits - col - 1 : col));
209 errors ++;
213 return errors;
217 static int
218 check_rot (int nr_bits,
219 const char *roted,
220 const char *masked)
222 int errors = 0;
223 int row;
224 int col;
225 for (row = 0; row < nr_bits; row++)
226 for (col = 0; col < nr_bits; col++)
227 if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
228 || (WITH_TARGET_WORD_MSB != 0 && row >= col))
230 long long mask = calc (masked, -1, row, col);
231 int shift;
232 for (shift = -nr_bits + 1; shift < nr_bits; shift ++)
234 long long rot = calc (roted, mask, -1, shift);
235 long long urot = calc (roted, rot, -1, -shift);
236 if (mask != urot
237 || (shift == 0 && rot != mask)
238 || (shift != 0 && rot == mask && abs(row - col) != (nr_bits - 1)))
240 fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
241 fprintf (stderr, " %s(%s(0x%016llx,%d) == 0x%016llx, %d) failed\n",
242 roted, roted, mask, shift, urot, -shift);
243 errors ++;
247 return errors;
251 static int
252 check_extract (int nr_bits,
253 const char *extracted,
254 const char *inserted,
255 const char *masked)
257 int errors = 0;
258 int row;
259 int col;
260 for (row = 0; row < nr_bits; row++)
261 for (col = 0; col < nr_bits; col ++)
262 if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
263 || (WITH_TARGET_WORD_MSB != 0 && row >= col))
265 long long mask = calc (masked, -1, row, col);
266 long long extr = calc (extracted, mask, row, col);
267 long long inst = calc (inserted, extr, row, col);
268 if (mask != inst)
270 fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
271 fprintf (stderr, " %s(%d,%d)=0x%016llx -> %s=0x%016llx -> %s=0x%016llx failed\n",
272 masked, row, col, mask, extracted, extr, inserted, inst);
273 errors ++;
276 return errors;
280 static int
281 check_bits (int call,
282 test_spec **tests)
284 int r;
285 int c;
286 int errors = 0;
287 while (*tests != NULL)
289 int nr_rows = (*tests)->nr_rows;
290 int nr_cols = (*tests)->nr_cols;
291 test_tuples *tuples = (*tests)->tuples;
292 for (r = 0; r < nr_rows; r++)
293 for (c = 0; c < nr_cols; c++)
295 int i = r * nr_rows + c;
296 test_tuples *tuple = &tuples[i];
297 if (tuple->col >= 0)
299 long long val = (!call ? tuple->val : calc ((*tests)->macro, -1,
300 tuple->row, tuple->col));
301 long long check = tuple->check;
302 if (val != check)
304 fprintf (stderr, "%s:%d:", (*tests)->file, tuple->line);
305 fprintf (stderr, " %s", (*tests)->macro);
306 if (tuple->row >= 0)
307 fprintf (stderr, " (%d, %d)", tuple->row, tuple->col);
308 else
309 fprintf (stderr, " (%d)", tuple->col);
310 fprintf (stderr, " == 0x%016llx wrong, != 0x%016llx\n",
311 val, check);
312 errors ++;
316 tests ++;
318 return errors;
323 main (argc, argv)
324 int argc;
325 char **argv;
327 int errors = 0;
330 #if defined (DO_BIT_TESTS)
331 printf ("Checking BIT*\n");
332 errors += check_bits (0, bit_tests);
333 #endif
336 #if defined (DO_MASK_TESTS)
337 printf ("Checking MASK*\n");
338 errors += check_bits (0, mask_tests);
340 printf ("Checking MASKED*\n");
341 errors += check_bits (1, mask_tests);
342 #endif
345 #if defined (DO_LSMASK_TESTS)
346 printf ("Checking LSMASK*\n");
347 errors += check_bits (0, lsmask_tests);
349 printf ("Checking LSMASKED*\n");
350 errors += check_bits (1, lsmask_tests);
351 #endif
354 #if defined (DO_MSMASK_TESTS)
355 printf ("Checking MSMASK*\n");
356 errors += check_bits (0, msmask_tests);
358 printf ("Checking MSMASKED*\n");
359 errors += check_bits (1, msmask_tests);
360 #endif
363 printf ("Checking EXTRACTED*\n");
364 errors += check_extract ( 8, "EXTRACT8", "INSERT8", "MASK8");
365 errors += check_extract (16, "EXTRACT16", "INSERT16", "MASK16");
366 errors += check_extract (32, "EXTRACT32", "INSERT32", "MASK32");
367 errors += check_extract (64, "EXTRACT64", "INSERT64", "MASK64");
368 errors += check_extract (64, "EXTRACT", "INSERT", "MASK");
370 printf ("Checking SEXT*\n");
371 errors += check_sext ( 8, WITH_TARGET_WORD_MSB, "SEXT8", "MASK8", "MSMASK8");
372 errors += check_sext (16, WITH_TARGET_WORD_MSB, "SEXT16", "MASK16", "MSMASK16");
373 errors += check_sext (32, WITH_TARGET_WORD_MSB, "SEXT32", "MASK32", "MSMASK32");
374 errors += check_sext (64, WITH_TARGET_WORD_MSB, "SEXT64", "MASK64", "MSMASK64");
375 errors += check_sext (64, WITH_TARGET_WORD_MSB, "SEXT", "MASK", "MSMASK");
377 printf ("Checking LSSEXT*\n");
378 errors += check_sext ( 8, 8 - 1, "LSSEXT8", "LSMASK8", "MSMASK8");
379 errors += check_sext (16, 16 - 1, "LSSEXT16", "LSMASK16", "MSMASK16");
380 errors += check_sext (32, 32 - 1, "LSSEXT32", "LSMASK32", "MSMASK32");
381 errors += check_sext (64, 64 - 1, "LSSEXT64", "LSMASK64", "MSMASK64");
382 errors += check_sext (64, WITH_TARGET_WORD_BITSIZE - 1, "LSSEXT", "LSMASK", "MSMASK");
384 printf ("Checking MSSEXT*\n");
385 errors += check_sext (8, 0, "MSSEXT8", "MSMASK8", "MSMASK8");
386 errors += check_sext (16, 0, "MSSEXT16", "MSMASK16", "MSMASK16");
387 errors += check_sext (32, 0, "MSSEXT32", "MSMASK32", "MSMASK32");
388 errors += check_sext (64, 0, "MSSEXT64", "MSMASK64", "MSMASK64");
389 errors += check_sext (64, 0, "MSSEXT", "MSMASK", "MSMASK");
391 printf ("Checking ROT*\n");
392 errors += check_rot (16, "ROT16", "MASK16");
393 errors += check_rot (32, "ROT32", "MASK32");
394 errors += check_rot (64, "ROT64", "MASK64");
396 return errors != 0;