Preliminary tests for sim-alu module.
[external/binutils.git] / sim / testsuite / common / alu-tst.c
1 #define WITH_TARGET_WORD_MSB 0
2 #define WITH_TARGET_WORD_BITSIZE 64
3 #define WITH_HOST_WORD_BITSIZE (sizeof (int) * 8)
4
5 #define ASSERT(EXPRESSION) \
6 { \
7   if (!(EXPRESSION)) { \
8     fprintf (stderr, "%s:%d: assertion failed - %s\n", \
9              __FILE__, __LINE__, #EXPRESSION); \
10     abort (); \
11   } \
12 }
13
14 #define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)
15
16 #include "sim-basics.h"
17 #include "sim-types.h"
18 #include "sim-bits.h"
19
20 #include "sim-alu.h"
21
22 #include <stdio.h>
23
24
25 typedef struct {
26   char *op;
27   unsigned64 arg;
28 } alu_op;
29
30 typedef struct {
31   unsigned64 begin;
32   alu_op ops[3];
33   unsigned64 result;
34   int carry;
35   int overflow;
36 } alu_test;
37
38 #define MAX_INT16 (32767)
39 #define MIN_INT16 (32768)
40
41 const alu_test alu16_tests[] = {
42   /* */
43   { MAX_INT16, { { "ADD", 1 }, }, MIN_INT16, 0, 1, },
44   { MIN_INT16, { { "ADD", -1 }, }, MAX_INT16, 1, 1, },
45   { MAX_INT16, { { "ADD", MIN_INT16 }, }, -1, 0, 0, },
46   { MIN_INT16, { { "ADD", MAX_INT16 }, }, -1, 0, 0, },
47   { MAX_INT16, { { "ADD", MAX_INT16 }, }, MAX_INT16 * 2, 0, 1, },
48   { MIN_INT16, { { "ADD", MIN_INT16 }, }, 0, 1, 1, },
49   /* */
50   { 0, { { "SUB", MIN_INT16 }, }, MIN_INT16, 0, 1, },
51   { MAX_INT16, { { "SUB", MAX_INT16 }, }, 0, 0, 0, },
52 };
53
54
55 static void
56 print_hex (unsigned64 val, int nr_bits)
57 {
58   switch (nr_bits)
59     {
60     case 16:
61       printf ("0x%04lx", (long) (unsigned16) (val));
62       break;
63     case 32:
64       printf ("0x%08lx", (long) (unsigned32) (val));
65       break;
66     case 64:
67       printf ("0x%08lx%08lx",
68               (long) (unsigned32) (val >> 32),
69               (long) (unsigned32) (val));
70     default:
71       abort ();
72     }
73 }
74
75
76 int errors = 0;
77
78
79 #define N 16
80 #include "alu-n-tst.h"
81 #undef N
82
83 #if 0
84 #define N 32
85 #include "alu-n-tst.h"
86 #undef N
87
88 #define N 64
89 #include "alu-n-tst.h"
90 #undef N
91 #endif
92
93 int
94 main ()
95 {
96   int i;
97   for (i = 0; i < sizeof (alu16_tests) / sizeof (*alu16_tests); i++)
98     do_op_16 (alu16_tests + i);
99   return (errors != 0);
100 }