OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [sim/] [testsuite/] [common/] [bits-tst.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
# 2 "bits-tst.c"
2
 
3
/* Drive the bit test routines */
4
 
5
 
6
long long
7
calc (const char *call,
8
      long long val,
9
      int row,
10
      int col)
11
{
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);
22
 
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);
33
 
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);
44
 
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);
55
 
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);
66
 
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);
77
 
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);
88
 
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);
99
 
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);
110
 
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);
119
 
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);
130
 
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);
141
 
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);
152
 
153
  else
154
    {
155
      fprintf (stderr,
156
               "Unknown call passed to calc (%s, 0x%08lx%08lx, %d, %d)\n",
157
               call, (long)(val >> 32), (long)val, row, col);
158
      abort ();
159
      return val;
160
    }
161
}
162
 
163
 
164
int
165
check_sext (int nr_bits,
166
            int msb_nr,
167
            const char *sexted,
168
            const char *masked,
169
            const char *msmasked)
170
{
171
  int errors = 0;
172
  int col;
173
  for (col = 0; col < nr_bits; col ++)
174
    {
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)
184
        {
185
          fprintf (stderr,
186
                   "%s:%d: ", __FILE__, __LINE__);
187
          fprintf (stderr,
188
                   " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
189
                   sexted, (long)(mask_0 >> 32), (long)mask_0, col,
190
                   (long)(sext_0 >> 32), (long)sext_0,
191
                   (long)(mask_1 >> 32), (long)mask_1);
192
          errors ++;
193
        }
194
      if (sext_1 != mask_1)
195
        {
196
          fprintf (stderr,
197
                   "%s:%d: ", __FILE__, __LINE__);
198
          fprintf (stderr,
199
                   " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
200
                   sexted, (long)(mask_1 >> 32), (long)mask_1, col,
201
                   (long)(sext_1 >> 32), (long)sext_1,
202
                   (long)(mask_1 >> 32), (long)mask_1);
203
          errors ++;
204
        }
205
      if (sext != msmask)
206
        {
207
          fprintf (stderr,
208
                   "%s:%d: ", __FILE__, __LINE__);
209
          fprintf (stderr,
210
                   " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx (%s(%d,%d))\n",
211
                   sexted, (long)(mask >> 32), (long)mask, col,
212
                   (long)(sext >> 32), (long)sext,
213
                   (long)(msmask >> 32), (long)msmask,
214
                   msmasked, 0, (msb_nr ? nr_bits - col - 1 : col));
215
          errors ++;
216
        }
217
 
218
    }
219
  return errors;
220
}
221
 
222
 
223
int
224
check_rot (int nr_bits,
225
           const char *roted,
226
           const char *masked)
227
{
228
  int errors = 0;
229
  int row;
230
  int col;
231
  for (row = 0; row < nr_bits; row++)
232
    for (col = 0; col < nr_bits; col++)
233
      if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
234
          || (WITH_TARGET_WORD_MSB != 0 && row >= col))
235
        {
236
          long long mask = calc (masked, -1, row, col);
237
          int shift;
238
          for (shift = -nr_bits + 1; shift < nr_bits; shift ++)
239
            {
240
              long long rot = calc (roted, mask, -1, shift);
241
              long long urot = calc (roted, rot, -1, -shift);
242
              if (mask != urot
243
                  || (shift == 0 && rot != mask)
244
                  || (shift != 0 && rot == mask && abs(row - col) != (nr_bits - 1)))
245
                {
246
                  fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
247
                  fprintf (stderr, " %s(%s(0x%08lx%08lx,%d) == 0x%08lx%08lx, %d) failed\n",
248
                           roted, roted,
249
                           (long)(mask >> 32), (long)mask, shift,
250
                           (long)(urot >> 32), (long)urot, -shift);
251
                  errors ++;
252
                }
253
            }
254
        }
255
  return errors;
256
}
257
 
258
 
259
int
260
check_extract (int nr_bits,
261
               const char *extracted,
262
               const char *inserted,
263
               const char *masked)
264
{
265
  int errors = 0;
266
  int row;
267
  int col;
268
  for (row = 0; row < nr_bits; row++)
269
    for (col = 0; col < nr_bits; col ++)
270
      if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
271
          || (WITH_TARGET_WORD_MSB != 0 && row >= col))
272
        {
273
          long long mask = calc (masked, -1, row, col);
274
          long long extr = calc (extracted, mask, row, col);
275
          long long inst = calc (inserted, extr, row, col);
276
          if (mask != inst)
277
            {
278
              fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
279
              fprintf (stderr, " %s(%d,%d)=0x%08lx%08lx -> %s=0x%08lx%08lx -> %s=0x%08lx%08lx failed\n",
280
                       masked, row, col, (long)(mask >> 32), (long)mask,
281
                       extracted, (long)(extr >> 32), (long)extr,
282
                       inserted, (long)(inst >> 32), (long)inst);
283
              errors ++;
284
            }
285
        }
286
  return errors;
287
}
288
 
289
 
290
int
291
check_bits (int call,
292
            test_spec **tests)
293
{
294
  int r;
295
  int c;
296
  int errors = 0;
297
  while (*tests != NULL)
298
    {
299
      int nr_rows = (*tests)->nr_rows;
300
      int nr_cols = (*tests)->nr_cols;
301
      test_tuples *tuples = (*tests)->tuples;
302
      for (r = 0; r < nr_rows; r++)
303
        for (c = 0; c < nr_cols; c++)
304
          {
305
            int i = r * nr_rows + c;
306
            test_tuples *tuple = &tuples[i];
307
            if (tuple->col >= 0)
308
              {
309
                long long val = (!call ? tuple->val : calc ((*tests)->macro, -1,
310
                                                            tuple->row, tuple->col));
311
                long long check = tuple->check;
312
                if (val != check)
313
                  {
314
                    fprintf (stderr, "%s:%d:", (*tests)->file, tuple->line);
315
                    fprintf (stderr, " %s", (*tests)->macro);
316
                    if (tuple->row >= 0)
317
                      fprintf (stderr, " (%d, %d)", tuple->row, tuple->col);
318
                    else
319
                      fprintf (stderr, " (%d)", tuple->col);
320
                    fprintf (stderr, " == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
321
                             (long) (val >> 32), (long) val,
322
                             (long) (check >> 32), (long) check);
323
                    errors ++;
324
                  }
325
              }
326
          }
327
      tests ++;
328
    }
329
  return errors;
330
}
331
 
332
 
333
int
334
main (argc, argv)
335
     int argc;
336
     char **argv;
337
{
338
  int errors = 0;
339
 
340
 
341
#if defined (DO_BIT_TESTS)
342
  printf ("Checking BIT*\n");
343
  errors += check_bits (0, bit_tests);
344
#endif
345
 
346
 
347
#if defined (DO_MASK_TESTS)
348
  printf ("Checking MASK*\n");
349
  errors += check_bits (0, mask_tests);
350
 
351
  printf ("Checking MASKED*\n");
352
  errors += check_bits (1, mask_tests);
353
#endif
354
 
355
 
356
#if defined (DO_LSMASK_TESTS)
357
  printf ("Checking LSMASK*\n");
358
  errors += check_bits (0, lsmask_tests);
359
 
360
  printf ("Checking LSMASKED*\n");
361
  errors += check_bits (1, lsmask_tests);
362
#endif
363
 
364
 
365
#if defined (DO_MSMASK_TESTS)
366
  printf ("Checking MSMASK*\n");
367
  errors += check_bits (0, msmask_tests);
368
 
369
  printf ("Checking MSMASKED*\n");
370
  errors += check_bits (1, msmask_tests);
371
#endif
372
 
373
 
374
  printf ("Checking EXTRACTED*\n");
375
  errors += check_extract ( 8, "EXTRACT8",  "INSERT8",  "MASK8");
376
  errors += check_extract (16, "EXTRACT16", "INSERT16", "MASK16");
377
  errors += check_extract (32, "EXTRACT32", "INSERT32", "MASK32");
378
  errors += check_extract (64, "EXTRACT64", "INSERT64", "MASK64");
379
  errors += check_extract (64, "EXTRACT",   "INSERT",   "MASK");
380
 
381
  printf ("Checking SEXT*\n");
382
  errors += check_sext ( 8, WITH_TARGET_WORD_MSB, "SEXT8",  "MASK8",  "MSMASK8");
383
  errors += check_sext (16, WITH_TARGET_WORD_MSB, "SEXT16", "MASK16", "MSMASK16");
384
  errors += check_sext (32, WITH_TARGET_WORD_MSB, "SEXT32", "MASK32", "MSMASK32");
385
  errors += check_sext (64, WITH_TARGET_WORD_MSB, "SEXT64", "MASK64", "MSMASK64");
386
  errors += check_sext (64, WITH_TARGET_WORD_MSB, "SEXT",   "MASK",   "MSMASK");
387
 
388
  printf ("Checking LSSEXT*\n");
389
  errors += check_sext ( 8,  8 - 1, "LSSEXT8",  "LSMASK8",  "MSMASK8");
390
  errors += check_sext (16, 16 - 1, "LSSEXT16", "LSMASK16", "MSMASK16");
391
  errors += check_sext (32, 32 - 1, "LSSEXT32", "LSMASK32", "MSMASK32");
392
  errors += check_sext (64, 64 - 1, "LSSEXT64", "LSMASK64", "MSMASK64");
393
  errors += check_sext (64, WITH_TARGET_WORD_BITSIZE - 1, "LSSEXT",   "LSMASK",   "MSMASK");
394
 
395
  printf ("Checking MSSEXT*\n");
396
  errors += check_sext (8,   0, "MSSEXT8",  "MSMASK8",  "MSMASK8");
397
  errors += check_sext (16,  0, "MSSEXT16", "MSMASK16", "MSMASK16");
398
  errors += check_sext (32,  0, "MSSEXT32", "MSMASK32", "MSMASK32");
399
  errors += check_sext (64,  0, "MSSEXT64", "MSMASK64", "MSMASK64");
400
  errors += check_sext (64,  0, "MSSEXT",   "MSMASK",   "MSMASK");
401
 
402
  printf ("Checking ROT*\n");
403
  errors += check_rot (16, "ROT16", "MASK16");
404
  errors += check_rot (32, "ROT32", "MASK32");
405
  errors += check_rot (64, "ROT64", "MASK64");
406
 
407
  return errors != 0;
408
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.