aboutsummaryrefslogtreecommitdiff
path: root/sim/testsuite
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-09-08 17:22:01 +0000
committerAndrew Cagney <cagney@redhat.com>1997-09-08 17:22:01 +0000
commit75faf9aecb2023ca625dd5cbdd667e134071cf9f (patch)
treef97aacdca4e87f4f4b0709c5db7fe84284fe1070 /sim/testsuite
parent75b3697d5f175e7121f792ca5ab9e36eeaaf5fc1 (diff)
downloadgdb-75faf9aecb2023ca625dd5cbdd667e134071cf9f.zip
gdb-75faf9aecb2023ca625dd5cbdd667e134071cf9f.tar.gz
gdb-75faf9aecb2023ca625dd5cbdd667e134071cf9f.tar.bz2
Check MS* macros from sim/common.
Diffstat (limited to 'sim/testsuite')
-rw-r--r--sim/testsuite/common/bits-gen.c259
-rw-r--r--sim/testsuite/common/bits-tst.c315
2 files changed, 574 insertions, 0 deletions
diff --git a/sim/testsuite/common/bits-gen.c b/sim/testsuite/common/bits-gen.c
new file mode 100644
index 0000000..5feb5a0
--- /dev/null
+++ b/sim/testsuite/common/bits-gen.c
@@ -0,0 +1,259 @@
+/* Miscellaneous simulator utilities.
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ Contributed by Cygnus Support.
+
+This file is part of GDB, the GNU debugger.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+
+#include <stdio.h>
+
+
+void
+gen_struct (void)
+{
+ printf ("\n");
+ printf ("typedef struct _test_tuples {\n");
+ printf (" int line;\n");
+ printf (" int row;\n");
+ printf (" int col;\n");
+ printf (" long long val;\n");
+ printf (" long long check;\n");
+ printf ("} test_tuples;\n");
+ printf ("\n");
+ printf ("typedef struct _test_spec {\n");
+ printf (" const char *file;\n");
+ printf (" const char *macro;\n");
+ printf (" int nr_rows;\n");
+ printf (" int nr_cols;\n");
+ printf (" test_tuples *tuples;\n");
+ printf ("} test_spec;\n");
+}
+
+
+void
+gen_bit (int bitsize,
+ int msb,
+ const char *macro,
+ int nr_bits)
+{
+ int i;
+
+ printf ("\n/* Test the BIT%s macro */\n", macro);
+ printf ("test_tuples bit%s_tuples[%d] = {\n", macro, nr_bits);
+ for (i = 0; i < nr_bits; i++)
+ {
+ /* compute what we think the value is */
+ long long bit = 1;
+ if (msb == 0)
+ bit <<= nr_bits - i - 1;
+ else
+ bit <<= i;
+ if (bitsize == 32)
+ bit = (long) bit;
+ /* write it out */
+ printf (" { __LINE__, ");
+ printf ("%d, %d, ", -1, i);
+ printf ("BIT%s (%2d), ", macro, i);
+ printf ("0x%08lx%08lxLL, ", (long) (bit >> 32), (long) bit);
+ printf ("},\n");
+ }
+ printf ("};\n");
+ printf ("\n");
+ printf ("test_spec bit%s_test = { __FILE__, \"BIT%s\", 1, %d, bit%s_tuples, };\n",
+ macro, macro, nr_bits, macro);
+ printf ("\n");
+}
+
+
+void
+gen_mask (int bitsize,
+ const char *msb,
+ const char *macro,
+ int nr_bits)
+{
+ int l;
+ int h;
+ printf ("\n/* Test the %sMASK%s macro */\n", msb, macro);
+ printf ("test_tuples mask%s_tuples[%d][%d] = {\n", macro, nr_bits, nr_bits);
+ for (l = 0; l < nr_bits; l++)
+ {
+ printf (" {\n");
+ for (h = 0; h < nr_bits; h++)
+ {
+ printf (" { __LINE__, ");
+ if ((strcmp (msb, "MS") == 0 && l <= h)
+ || (strcmp (msb, "MS") != 0 && l >= h)
+ || (strcmp (macro, "") == 0))
+ {
+ /* compute the mask */
+ long long mask = 0;
+ int b;
+ for (b = 0; b < nr_bits; b++)
+ {
+ long long bit = 1;
+ if (strcmp (msb, "MS") == 0)
+ {
+ if ((l <= b && b <= h)
+ || (h < l && (b <= h || b >= l)))
+ bit <<= (nr_bits - b - 1);
+ else
+ bit = 0;
+ }
+ else
+ {
+ if ((l >= b && b >= h)
+ || (h > l && (b >= h || b <= l)))
+ bit <<= b;
+ else
+ bit = 0;
+ }
+ mask |= bit;
+ }
+ if (bitsize == 32)
+ mask = (unsigned long) mask;
+ printf ("%d, %d, ", l, h);
+ printf ("%sMASK%s (%2d, %2d), ", msb, macro, l, h);
+ printf ("0x%08lx%08lxLL, ", (long) (mask >> 32), (long) mask);
+ }
+ else
+ printf ("-1, -1, ");
+ printf ("},\n");
+ }
+ printf (" },\n");
+ }
+ printf ("};\n");
+ printf ("\n");
+ printf ("test_spec mask%s_test = { __FILE__, \"%sMASK%s\", %d, %d, &mask%s_tuples[0][0], };\n",
+ macro, msb, macro, nr_bits, nr_bits, macro);
+ printf ("\n");
+}
+
+
+void
+usage (int reason)
+{
+ fprintf (stderr, "Usage:\n");
+ fprintf (stderr, " bits-gen <nr-bits> <msb>\n");
+ fprintf (stderr, "Generate a test case for the simulator bit manipulation code\n");
+ fprintf (stderr, " <nr-bits> = { 32 | 64 }\n");
+ fprintf (stderr, " <msb> = { 0 | { 31 | 63 } }\n");
+
+ switch (reason)
+ {
+ case 1: fprintf (stderr, "Wrong number of arguments\n");
+ break;
+ case 2:
+ fprintf (stderr, "Invalid <nr-bits> argument\n");
+ break;
+ case 3:
+ fprintf (stderr, "Invalid <msb> argument\n");
+ break;
+ default:
+ }
+
+ exit (1);
+}
+
+
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int bitsize;
+ int msb;
+ char *ms;
+
+ /* parse the only argument */
+ if (argc != 3)
+ usage (1);
+ if (strcmp (argv [1], "32") == 0)
+ bitsize = 32;
+ else if (strcmp (argv [1], "64") == 0)
+ bitsize = 64;
+ else
+ usage (2);
+ if (strcmp (argv [2], "0") == 0)
+ msb = 0;
+ else if (strcmp (argv [2], "31") == 0 && bitsize == 32)
+ msb = 31;
+ else if (strcmp (argv [2], "63") == 0 && bitsize == 64)
+ msb = 63;
+ else
+ usage (3);
+ if (msb == 0)
+ ms = "MS";
+ else
+ ms = "LS";
+
+ printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize);
+ printf ("#define WITH_TARGET_WORD_MSB %d\n", msb);
+ printf ("#define WITH_HOST_WORD_BITSIZE %d\n", sizeof (int) * 8);
+ printf ("\n");
+ printf ("#define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)\n");
+ printf ("\n");
+ printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n");
+ printf ("\n");
+ printf ("#include \"sim-basics.h\"\n");
+ printf ("#include \"sim-types.h\"\n");
+ printf ("#include \"sim-bits.h\"\n");
+
+ gen_struct ();
+
+
+
+ printf ("#define DO_BIT_TESTS\n");
+ gen_bit ( 4, msb, "4", 4);
+ gen_bit ( 5, msb, "5", 5);
+ gen_bit ( 8, msb, "8", 8);
+ gen_bit (10, msb, "10", 10);
+ gen_bit (16, msb, "16", 16);
+ gen_bit (32, msb, "32", 32);
+ gen_bit (64, msb, "64", 64);
+ gen_bit (bitsize, msb, "", 64);
+
+ printf ("test_spec *(bit_tests[]) = {\n");
+ printf (" &bit4_test,\n");
+ printf (" &bit5_test,\n");
+ printf (" &bit8_test,\n");
+ printf (" &bit10_test,\n");
+ printf (" &bit16_test,\n");
+ printf (" &bit32_test,\n");
+ printf (" &bit64_test,\n");
+ printf (" &bit_test,\n");
+ printf (" 0,\n");
+ printf ("};\n\n");
+
+
+
+ printf ("#define DO_MASK_TESTS\n");
+ gen_mask (16, ms, "16", 16);
+ gen_mask (32, ms, "32", 32);
+ gen_mask (64, ms, "64", 64);
+ gen_mask (bitsize, ms, "", 64);
+
+ printf ("test_spec *(mask_tests[]) = {\n");
+ printf (" &mask16_test,\n");
+ printf (" &mask32_test,\n");
+ printf (" &mask64_test,\n");
+ printf (" &mask_test,\n");
+ printf (" 0,\n");
+ printf ("};\n\n");
+
+ return 0;
+}
diff --git a/sim/testsuite/common/bits-tst.c b/sim/testsuite/common/bits-tst.c
new file mode 100644
index 0000000..576dbe4
--- /dev/null
+++ b/sim/testsuite/common/bits-tst.c
@@ -0,0 +1,315 @@
+# 2 "bits-tst.c"
+
+/* Drive the bit test routines */
+
+
+long long
+calc (const char *call,
+ long long val,
+ int row,
+ int col)
+{
+ if (strcmp (call, "MASK") == 0)
+ return MASKED (val, row, col);
+ if (strcmp (call, "MASK16") == 0)
+ return MASKED16 (val, row, col);
+ if (strcmp (call, "MASK32") == 0)
+ return MASKED32 (val, row, col);
+ if (strcmp (call, "MASK64") == 0)
+ return MASKED64 (val, row, col);
+
+ if (strcmp (call, "EXTRACT") == 0)
+ return EXTRACTED (val, row, col);
+ if (strcmp (call, "EXTRACT16") == 0)
+ return EXTRACTED16 (val, row, col);
+ if (strcmp (call, "EXTRACT32") == 0)
+ return EXTRACTED32 (val, row, col);
+ if (strcmp (call, "EXTRACT64") == 0)
+ return EXTRACTED64 (val, row, col);
+
+ if (strcmp (call, "LSEXTRACT") == 0)
+ return LSEXTRACTED (val, row, col);
+ if (strcmp (call, "LSEXTRACT16") == 0)
+ return LSEXTRACTED16 (val, row, col);
+ if (strcmp (call, "LSEXTRACT32") == 0)
+ return LSEXTRACTED32 (val, row, col);
+ if (strcmp (call, "LSEXTRACT64") == 0)
+ return LSEXTRACTED64 (val, row, col);
+
+ if (strcmp (call, "MSEXTRACT") == 0)
+ return MSEXTRACTED (val, row, col);
+ if (strcmp (call, "MSEXTRACT16") == 0)
+ return MSEXTRACTED16 (val, row, col);
+ if (strcmp (call, "MSEXTRACT32") == 0)
+ return MSEXTRACTED32 (val, row, col);
+ if (strcmp (call, "MSEXTRACT64") == 0)
+ return MSEXTRACTED64 (val, row, col);
+
+ if (strcmp (call, "INSERT") == 0)
+ return INSERTED (val, row, col);
+ if (strcmp (call, "INSERT16") == 0)
+ return INSERTED16 (val, row, col);
+ if (strcmp (call, "INSERT32") == 0)
+ return INSERTED32 (val, row, col);
+ if (strcmp (call, "INSERT64") == 0)
+ return INSERTED64 (val, row, col);
+
+ if (strcmp (call, "MSMASK") == 0)
+ return MSMASKED (val, row, col);
+ if (strcmp (call, "MSMASK16") == 0)
+ return MSMASKED16 (val, row, col);
+ if (strcmp (call, "MSMASK32") == 0)
+ return MSMASKED32 (val, row, col);
+ if (strcmp (call, "MSMASK64") == 0)
+ return MSMASKED64 (val, row, col);
+
+ if (strcmp (call, "LSMASK") == 0)
+ return LSMASKED (val, row, col);
+ if (strcmp (call, "LSMASK16") == 0)
+ return LSMASKED16 (val, row, col);
+ if (strcmp (call, "LSMASK32") == 0)
+ return LSMASKED32 (val, row, col);
+ if (strcmp (call, "LSMASK64") == 0)
+ return LSMASKED64 (val, row, col);
+
+ if (strcmp (call, "ROT16") == 0)
+ return ROT16 (val, col);
+ if (strcmp (call, "ROT32") == 0)
+ return ROT32 (val, col);
+ if (strcmp (call, "ROT64") == 0)
+ return ROT64 (val, col);
+
+ if (strcmp (call, "SEXT16") == 0)
+ return SEXT16 (val, col);
+ if (strcmp (call, "SEXT32") == 0)
+ return SEXT32 (val, col);
+ if (strcmp (call, "SEXT64") == 0)
+ return SEXT64 (val, col);
+ if (strcmp (call, "SEXT") == 0)
+ return SEXT (val, col);
+
+ else
+ {
+ fprintf (stderr, "Unknown call passed to calc (%s, 0x%08lx%08lx, %d, %d)\n",
+ call, (long)(val >> 32), (long)val, row, col);
+ abort ();
+ return val;
+ }
+}
+
+
+int
+check_sext (int nr_bits,
+ const char *sexted,
+ const char *masked,
+ const char *msmasked)
+{
+ int errors = 0;
+ int col;
+ for (col = 0; col < nr_bits; col ++)
+ {
+ long long mask = calc (masked, -1, col, col);
+ long long msmask = calc (msmasked, -1,
+ 0, (WITH_TARGET_WORD_MSB ? nr_bits - col - 1 : col));
+ long long sext = calc (sexted, mask, -1, col);
+ long long mask_1 = mask >> 1;
+ long long sext_1 = calc (sexted, mask_1, -1, col);
+ if (mask_1 != sext_1)
+ {
+ fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
+ fprintf (stderr, " %s(0x%08lx%08lx,%d) != 0x%08lx%08lx\n",
+ sexted,
+ (long)(mask_1 >> 32), (long)mask_1,
+ col,
+ (long)(sext_1 >> 32), (long)sext_1);
+ errors ++;
+ }
+ if (sext != msmask)
+ {
+ fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
+ fprintf (stderr, " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
+ sexted, (long)(mask >> 32), (long)mask, col,
+ (long)(sext >> 32), (long)sext,
+ (long)(msmask >> 32), (long)msmask);
+ errors ++;
+ }
+
+ }
+ return errors;
+}
+
+
+int
+check_rot (int nr_bits,
+ const char *roted,
+ const char *masked)
+{
+ int errors = 0;
+ int row;
+ int col;
+ for (row = 0; row < nr_bits; row++)
+ for (col = 0; col < nr_bits; col++)
+ if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
+ || (WITH_TARGET_WORD_MSB != 0 && row >= col))
+ {
+ long long mask = calc (masked, -1, row, col);
+ int shift;
+ for (shift = -nr_bits + 1; shift < nr_bits; shift ++)
+ {
+ long long rot = calc (roted, mask, -1, shift);
+ long long urot = calc (roted, rot, -1, -shift);
+ if (mask != urot
+ || (shift == 0 && rot != mask)
+ || (shift != 0 && rot == mask && abs(row - col) != (nr_bits - 1)))
+ {
+ fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
+ fprintf (stderr, " %s(%s(0x%08lx%08lx,%d) == 0x%08lx%08lx, %d) failed\n",
+ roted, roted,
+ (long)(mask >> 32), (long)mask, shift,
+ (long)(urot >> 32), (long)urot, -shift);
+ errors ++;
+ }
+ }
+ }
+ return errors;
+}
+
+
+int
+check_extract (int nr_bits,
+ const char *extracted,
+ const char *inserted,
+ const char *masked)
+{
+ int errors = 0;
+ int row;
+ int col;
+ for (row = 0; row < nr_bits; row++)
+ for (col = 0; col < nr_bits; col ++)
+ if ((WITH_TARGET_WORD_MSB == 0 && row <= col)
+ || (WITH_TARGET_WORD_MSB != 0 && row >= col))
+ {
+ long long mask = calc (masked, -1, row, col);
+ long long extr = calc (extracted, mask, row, col);
+ long long inst = calc (inserted, extr, row, col);
+ if (mask != inst)
+ {
+ fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
+ fprintf (stderr, " %s(%d,%d)=0x%08lx%08lx -> %s=0x%08lx%08lx -> %s=0x%08lx%08lx failed\n",
+ masked, row, col, (long)(mask >> 32), (long)mask,
+ extracted, (long)(extr >> 32), (long)extr,
+ inserted, (long)(inst >> 32), (long)inst);
+ errors ++;
+ }
+ }
+ return errors;
+}
+
+
+int
+check_bits (int call,
+ test_spec **tests)
+{
+ int r;
+ int c;
+ int errors = 0;
+ while (*tests != NULL)
+ {
+ int nr_rows = (*tests)->nr_rows;
+ int nr_cols = (*tests)->nr_cols;
+ test_tuples *tuples = (*tests)->tuples;
+ for (r = 0; r < nr_rows; r++)
+ for (c = 0; c < nr_cols; c++)
+ {
+ int i = r * nr_rows + c;
+ test_tuples *tuple = &tuples[i];
+ if (tuple->col >= 0)
+ {
+ long long val = (!call ? tuple->val : calc ((*tests)->macro, -1,
+ tuple->row, tuple->col));
+ long long check = tuple->check;
+ if (val != check)
+ {
+ fprintf (stderr, "%s:%d:", (*tests)->file, tuple->line);
+ fprintf (stderr, " %s", (*tests)->macro);
+ if (tuple->row >= 0)
+ fprintf (stderr, " (%d, %d)", tuple->row, tuple->col);
+ else
+ fprintf (stderr, " (%d)", tuple->col);
+ fprintf (stderr, " == 0x%08lx%08lx wrong, != 0x%08lx%08lx)\n",
+ (long) (val >> 32), (long) val,
+ (long) (check >> 32), (long) check);
+ errors ++;
+ }
+ }
+ }
+ tests ++;
+ }
+ return errors;
+}
+
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int errors = 0;
+
+
+#if defined (DO_BIT_TESTS)
+ printf ("Checking BIT*\n");
+ errors += check_bits (0, bit_tests);
+#endif
+
+
+#if defined (DO_MASK_TESTS)
+ printf ("Checking MASK*\n");
+ errors += check_bits (0, mask_tests);
+
+ printf ("Checking MASKED*\n");
+ errors += check_bits (1, mask_tests);
+#endif
+
+
+#if defined (DO_LSMASK_TESTS)
+ printf ("Checking LSMASK*\n");
+ errors += check_bits (0, lsmask_tests);
+
+ printf ("Checking LSMASKED*\n");
+ errors += check_bits (1, lsmask_tests);
+#endif
+
+
+#if defined (DO_MSMASK_TESTS)
+ printf ("Checking MSMASK*\n");
+ errors += check_bits (0, msmask_tests);
+
+ printf ("Checking MSMASKED*\n");
+ errors += check_bits (1, msmask_tests);
+#endif
+
+
+ printf ("Checking EXTRACTED*\n");
+ errors += check_extract (16, "EXTRACT16", "INSERT16", "MASK16");
+ errors += check_extract (32, "EXTRACT32", "INSERT32", "MASK32");
+ errors += check_extract (64, "EXTRACT64", "INSERT64", "MASK64");
+ errors += check_extract (64, "EXTRACT", "INSERT", "MASK");
+
+
+
+ printf ("Checking SEXT*\n");
+ errors += check_sext (16, "SEXT16", "MASK16", "MSMASK16");
+ errors += check_sext (32, "SEXT32", "MASK32", "MSMASK32");
+ errors += check_sext (64, "SEXT64", "MASK64", "MSMASK64");
+ errors += check_sext (64, "SEXT", "MASK", "MSMASK");
+
+
+ printf ("Checking ROT*\n");
+ errors += check_rot (16, "ROT16", "MASK16");
+ errors += check_rot (32, "ROT32", "MASK32");
+ errors += check_rot (64, "ROT64", "MASK64");
+
+
+ return errors != 0;
+}