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

Subversion Repositories scarts

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
/* Miscellaneous simulator utilities.
2
   Copyright (C) 1997, 2007, 2008 Free Software Foundation, Inc.
3
   Contributed by Cygnus Support.
4
 
5
This file is part of GDB, the GNU debugger.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 3 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
 
20
 
21
#include <stdio.h>
22
 
23
 
24
void
25
gen_struct (void)
26
{
27
  printf ("\n");
28
  printf ("typedef struct _test_tuples {\n");
29
  printf ("  int line;\n");
30
  printf ("  int row;\n");
31
  printf ("  int col;\n");
32
  printf ("  long long val;\n");
33
  printf ("  long long check;\n");
34
  printf ("} test_tuples;\n");
35
  printf ("\n");
36
  printf ("typedef struct _test_spec {\n");
37
  printf ("  const char *file;\n");
38
  printf ("  const char *macro;\n");
39
  printf ("  int nr_rows;\n");
40
  printf ("  int nr_cols;\n");
41
  printf ("  test_tuples *tuples;\n");
42
  printf ("} test_spec;\n");
43
}
44
 
45
 
46
void
47
gen_bit (int bitsize,
48
         int msb,
49
         const char *macro,
50
         int nr_bits)
51
{
52
  int i;
53
 
54
  printf ("\n/* Test the %s macro */\n", macro);
55
  printf ("test_tuples %s_tuples[%d] = {\n", macro, nr_bits);
56
  for (i = 0; i < nr_bits; i++)
57
    {
58
      /* compute what we think the value is */
59
      unsigned long long bit = 1;
60
      if (msb == 0)
61
        bit <<= nr_bits - i - 1;
62
      else
63
        bit <<= i;
64
      if (bitsize == 32)
65
        bit = (unsigned) bit; /* truncate it! */
66
      /* write it out */
67
      printf ("  { __LINE__, ");
68
      printf ("%d, %2d, ", -1, i);
69
      printf ("%s (%2d), ", macro, i);
70
      printf ("UNSIGNED64 (0x%08lx%08lx), ",
71
              (long) (bit >> 32), (long) bit);
72
      printf ("},\n");
73
    }
74
  printf ("};\n");
75
  printf ("\n");
76
  printf ("test_spec %s_test = { __FILE__, \"%s\", 1, %d, %s_tuples, };\n",
77
          macro, macro, nr_bits, macro);
78
  printf ("\n");
79
}
80
 
81
 
82
void
83
gen_enum (const char *macro,
84
          int nr_bits)
85
{
86
  int i;
87
 
88
  printf ("\n/* Test the %s macro in an enum */\n", macro);
89
  printf ("enum enum_%s {\n", macro);
90
  for (i = 0; i < nr_bits; i++)
91
    {
92
      printf ("  elem_%s_%d = %s (%d),\n", macro, i, macro, i);
93
    }
94
  printf ("};\n");
95
  printf ("\n");
96
}
97
 
98
 
99
void
100
gen_mask (int bitsize,
101
          const char *msb,
102
          const char *macro,
103
          int nr_bits)
104
{
105
  int l;
106
  int h;
107
  printf ("\n/* Test the %s%s macro */\n", msb, macro);
108
  printf ("test_tuples %s_tuples[%d][%d] = {\n", macro, nr_bits, nr_bits);
109
  for (l = 0; l < nr_bits; l++)
110
    {
111
      printf ("  {\n");
112
      for (h = 0; h < nr_bits; h++)
113
        {
114
          printf ("    { __LINE__, ");
115
          if ((strcmp (msb, "MS") == 0 && l <= h)
116
              || (strcmp (msb, "MS") != 0 && l >= h)
117
              || (strcmp (macro, "") == 0))
118
            {
119
              /* compute the mask */
120
              unsigned long long mask = 0;
121
              int b;
122
              for (b = 0; b < nr_bits; b++)
123
                {
124
                  unsigned long long bit = 1;
125
                  if (strcmp (msb, "MS") == 0)
126
                    {
127
                      if ((l <= b && b <= h)
128
                          || (h < l && (b <= h || b >= l)))
129
                        bit <<= (nr_bits - b - 1);
130
                      else
131
                        bit = 0;
132
                    }
133
                  else
134
                    {
135
                      if ((l >= b && b >= h)
136
                          || (h > l && (b >= h || b <= l)))
137
                        bit <<= b;
138
                      else
139
                        bit = 0;
140
                    }
141
                  mask |= bit;
142
                }
143
              if (bitsize == 32)
144
                mask = (unsigned long) mask;
145
              printf ("%d, %d, ", l, h);
146
              printf ("%s%s (%2d, %2d), ", msb, macro, l, h);
147
              printf ("UNSIGNED64 (0x%08lx%08lx), ",
148
                      (long) (mask >> 32), (long) mask);
149
            }
150
          else
151
            printf ("-1, -1, ");
152
          printf ("},\n");
153
        }
154
      printf ("  },\n");
155
    }
156
  printf ("};\n");
157
  printf ("\n");
158
  printf ("test_spec %s_test = { __FILE__, \"%s%s\", %d, %d, &%s_tuples[0][0], };\n",
159
          macro, msb, macro, nr_bits, nr_bits, macro);
160
  printf ("\n");
161
}
162
 
163
 
164
void
165
usage (int reason)
166
{
167
  fprintf (stderr, "Usage:\n");
168
  fprintf (stderr, "  bits-gen <nr-bits> <msb> <byte-order>\n");
169
  fprintf (stderr, "Generate a test case for the simulator bit manipulation code\n");
170
  fprintf (stderr, "  <nr-bits> = { 32 | 64 }\n");
171
  fprintf (stderr, "  <msb> = { 0 | { 31 | 63 } }\n");
172
  fprintf (stderr, "  <byte-order> = { big | little }\n");
173
 
174
  switch (reason)
175
    {
176
    case 1: fprintf (stderr, "Wrong number of arguments\n");
177
      break;
178
    case 2:
179
      fprintf (stderr, "Invalid <nr-bits> argument\n");
180
      break;
181
    case 3:
182
      fprintf (stderr, "Invalid <msb> argument\n");
183
      break;
184
    case 4:
185
      fprintf (stderr, "Invalid <byte-order> argument\n");
186
      break;
187
    default:
188
    }
189
 
190
  exit (1);
191
}
192
 
193
 
194
 
195
int
196
main (argc, argv)
197
     int argc;
198
     char **argv;
199
{
200
  int bitsize;
201
  int msb;
202
  char *ms;
203
  int big_endian;
204
 
205
  if (argc != 4)
206
    usage (1);
207
 
208
  if (strcmp (argv [1], "32") == 0)
209
    bitsize = 32;
210
  else if (strcmp (argv [1], "64") == 0)
211
    bitsize = 64;
212
  else
213
    usage (2);
214
 
215
  if (strcmp (argv [2], "0") == 0)
216
    msb = 0;
217
  else if (strcmp (argv [2], "31") == 0 && bitsize == 32)
218
    msb = 31;
219
  else if (strcmp (argv [2], "63") == 0 && bitsize == 64)
220
    msb = 63;
221
  else
222
    usage (3);
223
  if (msb == 0)
224
    ms = "MS";
225
  else
226
    ms = "LS";
227
 
228
  if (strcmp (argv [3], "big") == 0)
229
    big_endian = 1;
230
  else if (strcmp (argv [3], "little") == 0)
231
    big_endian = 0;
232
  else
233
    usage (4);
234
 
235
  printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize);
236
  printf ("#define WITH_TARGET_WORD_MSB %d\n", msb);
237
  printf ("#define WITH_HOST_WORD_BITSIZE %d\n", sizeof (int) * 8);
238
  printf ("#define WITH_TARGET_BYTE_ORDER %s\n", big_endian ? "BIG_ENDIAN" : "LITTLE_ENDIAN");
239
  printf ("\n");
240
  printf ("#define SIM_BITS_INLINE (ALL_H_INLINE)\n");
241
  printf ("\n");
242
  printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n");
243
  printf ("\n");
244
  printf ("#include \"sim-basics.h\"\n");
245
 
246
  gen_struct ();
247
 
248
 
249
 
250
  printf ("#define DO_BIT_TESTS\n");
251
  gen_bit ( 4, msb, "BIT4",  4);
252
  gen_bit ( 5, msb, "BIT5",  5);
253
  gen_bit ( 8, msb, "BIT8",  8);
254
  gen_bit (10, msb, "BIT10", 10);
255
  gen_bit (16, msb, "BIT16", 16);
256
  gen_bit (32, msb, "BIT32", 32);
257
  gen_bit (64, msb, "BIT64", 64);
258
  gen_bit (bitsize, msb, "BIT", 64);
259
 
260
  gen_bit ( 8,  8 - 1, "LSBIT8",   8);
261
  gen_bit (16, 16 - 1, "LSBIT16", 16);
262
  gen_bit (32, 32 - 1, "LSBIT32", 32);
263
  gen_bit (64, 64 - 1, "LSBIT64", 64);
264
  gen_bit (bitsize, bitsize - 1, "LSBIT",   64);
265
 
266
  gen_bit ( 8,  0, "MSBIT8",   8);
267
  gen_bit (16,  0, "MSBIT16", 16);
268
  gen_bit (32,  0, "MSBIT32", 32);
269
  gen_bit (64,  0, "MSBIT64", 64);
270
  gen_bit (bitsize,  0, "MSBIT",   64);
271
 
272
  printf ("test_spec *(bit_tests[]) = {\n");
273
  printf ("  &BIT4_test,\n");
274
  printf ("  &BIT5_test,\n");
275
  printf ("  &BIT8_test,\n");
276
  printf ("  &BIT10_test,\n");
277
  printf ("  &BIT16_test,\n");
278
  printf ("  &BIT32_test,\n");
279
  printf ("  &BIT64_test,\n");
280
  printf ("  &BIT_test,\n");
281
  printf ("  &LSBIT8_test,\n");
282
  printf ("  &LSBIT16_test,\n");
283
  printf ("  &LSBIT32_test,\n");
284
  printf ("  &LSBIT64_test,\n");
285
  printf ("  &LSBIT_test,\n");
286
  printf ("  &MSBIT8_test,\n");
287
  printf ("  &MSBIT16_test,\n");
288
  printf ("  &MSBIT32_test,\n");
289
  printf ("  &MSBIT64_test,\n");
290
  printf ("  &MSBIT_test,\n");
291
  printf ("  0,\n");
292
  printf ("};\n\n");
293
 
294
  gen_enum ("BIT",   64);
295
  gen_enum ("LSBIT", 64);
296
  gen_enum ("MSBIT", 64);
297
  gen_enum ("BIT32",   32);
298
  gen_enum ("LSBIT32", 32);
299
  gen_enum ("MSBIT32", 32);
300
 
301
  printf ("#define DO_MASK_TESTS\n");
302
  gen_mask ( 8, ms, "MASK8",  8);
303
  gen_mask (16, ms, "MASK16", 16);
304
  gen_mask (32, ms, "MASK32", 32);
305
  gen_mask (64, ms, "MASK64", 64);
306
  gen_mask (bitsize, ms, "MASK", 64);
307
 
308
  printf ("test_spec *(mask_tests[]) = {\n");
309
  printf ("  &MASK8_test,\n");
310
  printf ("  &MASK16_test,\n");
311
  printf ("  &MASK32_test,\n");
312
  printf ("  &MASK64_test,\n");
313
  printf ("  &MASK_test,\n");
314
  printf ("  0,\n");
315
  printf ("};\n\n");
316
 
317
  return 0;
318
}

powered by: WebSVN 2.1.0

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