aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-10-17 03:57:53 +0000
committerAndrew Cagney <cagney@redhat.com>1997-10-17 03:57:53 +0000
commitafb1dbe851c1395fd46213bb663b349d5768b35d (patch)
tree0d6a021377e96124a6ed11987a594c2ee1472d33
parent9d59cbb13c35d1aa0901428efabc05c2b5fae38a (diff)
downloadgdb-afb1dbe851c1395fd46213bb663b349d5768b35d.zip
gdb-afb1dbe851c1395fd46213bb663b349d5768b35d.tar.gz
gdb-afb1dbe851c1395fd46213bb663b349d5768b35d.tar.bz2
Preliminary tests for sim-alu module.
-rw-r--r--sim/testsuite/common/.Sanitize2
-rw-r--r--sim/testsuite/common/alu-n-tst.h87
-rw-r--r--sim/testsuite/common/alu-tst.c100
3 files changed, 189 insertions, 0 deletions
diff --git a/sim/testsuite/common/.Sanitize b/sim/testsuite/common/.Sanitize
index e5562e5..ba27ecd 100644
--- a/sim/testsuite/common/.Sanitize
+++ b/sim/testsuite/common/.Sanitize
@@ -27,6 +27,8 @@ Make-common.in
Makefile.in
bits-gen.c
bits-tst.c
+fpu-tst.c
+alu-tst.c
Things-to-lose:
diff --git a/sim/testsuite/common/alu-n-tst.h b/sim/testsuite/common/alu-n-tst.h
new file mode 100644
index 0000000..bf2635f
--- /dev/null
+++ b/sim/testsuite/common/alu-n-tst.h
@@ -0,0 +1,87 @@
+#ifndef N
+#error "N must be #defined"
+#endif
+
+#include "sim-xcat.h"
+
+/* NOTE: see end of file for #undef of these macros */
+#define unsignedN XCONCAT2(unsigned,N)
+#define OP_BEGIN XCONCAT3(ALU,N,_BEGIN)
+#define OP_ADD XCONCAT3(ALU,N,_ADD)
+#define OP_SUB XCONCAT3(ALU,N,_SUB)
+#define HAD_OVERFLOW (XCONCAT3(ALU,N,_HAD_OVERFLOW) != 0)
+#define HAD_CARRY (XCONCAT3(ALU,N,_HAD_CARRY) != 0)
+#define RESULT XCONCAT3(ALU,N,_RESULT)
+#define OVERFLOW_RESULT XCONCAT3(ALU,N,_OVERFLOW_RESULT)
+#define CARRY_RESULT XCONCAT3(ALU,N,_CARRY_RESULT)
+#define do_op_N XCONCAT2(do_op_,N)
+
+void
+do_op_N (const alu_test *tst)
+{
+ const alu_op *op;
+ /* without type cast */
+ {
+ OP_BEGIN (tst->begin);
+ print_hex (tst->begin, N);
+ for (op = tst->ops; op->op != NULL; op++)
+ {
+ printf (" %s ", op->op);
+ print_hex (op->arg, N);
+ if (strcmp (op->op, "add") == 0
+ || strcmp (op->op, "ADD") == 0)
+ OP_ADD (op->arg);
+ else if (strcmp (op->op, "sub") == 0
+ || strcmp (op->op, "SUB") == 0)
+ OP_SUB (op->arg);
+ else
+ {
+ printf (" -- operator unknown\n");
+ abort ();
+ }
+ }
+ printf (" = ");
+ print_hex (tst->result, N);
+ printf (" C%d V%d", tst->carry, tst->overflow);
+ if (tst->carry != HAD_CARRY)
+ {
+ printf (" -- carry wrong %d", HAD_CARRY);
+ errors ++;
+ }
+ if (tst->overflow != HAD_OVERFLOW)
+ {
+ printf (" -- overflow wrong %d", HAD_OVERFLOW);
+ errors ++;
+ }
+ if ((unsignedN) CARRY_RESULT != (unsignedN) tst->result)
+ {
+ printf (" -- carry result wrong ");
+ print_hex (CARRY_RESULT, N);
+ errors ++;
+ }
+ if ((unsignedN) OVERFLOW_RESULT != (unsignedN) tst->result)
+ {
+ printf (" -- overflow result wrong ");
+ print_hex (OVERFLOW_RESULT, N);
+ errors ++;
+ }
+ if ((unsignedN) RESULT != (unsignedN) tst->result)
+ {
+ printf (" -- result wrong ");
+ print_hex (RESULT, N);
+ errors ++;
+ }
+ printf ("\n");
+ }
+}
+
+#undef OP_BEGIN
+#undef OP_ADD
+#undef OP_SUB
+#undef HAD_OVERFLOW
+#undef HAD_CARRY
+#undef OVERFLOW_RESULT
+#undef CARRY_RESULT
+#undef RESULT
+#undef do_op_N
+#undef unsignedN
diff --git a/sim/testsuite/common/alu-tst.c b/sim/testsuite/common/alu-tst.c
new file mode 100644
index 0000000..f03ebd5
--- /dev/null
+++ b/sim/testsuite/common/alu-tst.c
@@ -0,0 +1,100 @@
+#define WITH_TARGET_WORD_MSB 0
+#define WITH_TARGET_WORD_BITSIZE 64
+#define WITH_HOST_WORD_BITSIZE (sizeof (int) * 8)
+
+#define ASSERT(EXPRESSION) \
+{ \
+ if (!(EXPRESSION)) { \
+ fprintf (stderr, "%s:%d: assertion failed - %s\n", \
+ __FILE__, __LINE__, #EXPRESSION); \
+ abort (); \
+ } \
+}
+
+#define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)
+
+#include "sim-basics.h"
+#include "sim-types.h"
+#include "sim-bits.h"
+
+#include "sim-alu.h"
+
+#include <stdio.h>
+
+
+typedef struct {
+ char *op;
+ unsigned64 arg;
+} alu_op;
+
+typedef struct {
+ unsigned64 begin;
+ alu_op ops[3];
+ unsigned64 result;
+ int carry;
+ int overflow;
+} alu_test;
+
+#define MAX_INT16 (32767)
+#define MIN_INT16 (32768)
+
+const alu_test alu16_tests[] = {
+ /* */
+ { MAX_INT16, { { "ADD", 1 }, }, MIN_INT16, 0, 1, },
+ { MIN_INT16, { { "ADD", -1 }, }, MAX_INT16, 1, 1, },
+ { MAX_INT16, { { "ADD", MIN_INT16 }, }, -1, 0, 0, },
+ { MIN_INT16, { { "ADD", MAX_INT16 }, }, -1, 0, 0, },
+ { MAX_INT16, { { "ADD", MAX_INT16 }, }, MAX_INT16 * 2, 0, 1, },
+ { MIN_INT16, { { "ADD", MIN_INT16 }, }, 0, 1, 1, },
+ /* */
+ { 0, { { "SUB", MIN_INT16 }, }, MIN_INT16, 0, 1, },
+ { MAX_INT16, { { "SUB", MAX_INT16 }, }, 0, 0, 0, },
+};
+
+
+static void
+print_hex (unsigned64 val, int nr_bits)
+{
+ switch (nr_bits)
+ {
+ case 16:
+ printf ("0x%04lx", (long) (unsigned16) (val));
+ break;
+ case 32:
+ printf ("0x%08lx", (long) (unsigned32) (val));
+ break;
+ case 64:
+ printf ("0x%08lx%08lx",
+ (long) (unsigned32) (val >> 32),
+ (long) (unsigned32) (val));
+ default:
+ abort ();
+ }
+}
+
+
+int errors = 0;
+
+
+#define N 16
+#include "alu-n-tst.h"
+#undef N
+
+#if 0
+#define N 32
+#include "alu-n-tst.h"
+#undef N
+
+#define N 64
+#include "alu-n-tst.h"
+#undef N
+#endif
+
+int
+main ()
+{
+ int i;
+ for (i = 0; i < sizeof (alu16_tests) / sizeof (*alu16_tests); i++)
+ do_op_16 (alu16_tests + i);
+ return (errors != 0);
+}