1 #define WITH_TARGET_WORD_MSB 0
2 #define WITH_TARGET_WORD_BITSIZE 64
3 #define WITH_HOST_WORD_BITSIZE (sizeof (int) * 8)
4 #define WITH_TARGET_BYTE_ORDER BIG_ENDIAN /* does not matter */
5 
6 #define ASSERT(EXPRESSION) \
7 { \
8   if (!(EXPRESSION)) { \
9     fprintf (stderr, "%s:%d: assertion failed - %s\n", \
10              __FILE__, __LINE__, #EXPRESSION); \
11     abort (); \
12   } \
13 }
14 
15 #define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)
16 
17 #include <string.h>
18 
19 #include "sim-basics.h"
20 
21 #include "sim-alu.h"
22 
23 #include <stdio.h>
24 
25 typedef struct {
26   char *op;
27   unsigned64 arg;
28 } alu_op;
29 
30 typedef struct {
31   unsigned64 begin;
32   alu_op ops[4];
33   unsigned64 result;
34   int carry_borrow;
35   int overflow;
36 } alu_test;
37 
38 #define MAX_INT8 UNSIGNED64 (127)
39 #define MIN_INT8 UNSIGNED64 (128)
40 
41 #define MAX_INT16 UNSIGNED64 (32767)
42 #define MIN_INT16 UNSIGNED64 (32768)
43 
44 #define MAX_INT32 UNSIGNED64 (0x7fffffff)
45 #define MIN_INT32 UNSIGNED64 (0x80000000)
46 
47 #define MAX_INT64 UNSIGNED64 (0x7fffffffffffffff)
48 #define MIN_INT64 UNSIGNED64 (0x8000000000000000)
49 
50 static void
print_hex(unsigned64 val,int nr_bits)51 print_hex (unsigned64 val, int nr_bits)
52 {
53   switch (nr_bits)
54     {
55     case 8:
56       printf ("0x%02lx", (long) (unsigned8) (val));
57       break;
58     case 16:
59       printf ("0x%04lx", (long) (unsigned16) (val));
60       break;
61     case 32:
62       printf ("0x%08lx", (long) (unsigned32) (val));
63       break;
64     case 64:
65       printf ("0x%08lx%08lx",
66 	      (long) (unsigned32) (val >> 32),
67 	      (long) (unsigned32) (val));
68       break;
69     default:
70       abort ();
71     }
72 }
73 
74 
75 int errors = 0;
76 
77 
78 #define N 8
79 #include "alu-n-tst.h"
80 #undef N
81 
82 #define N 16
83 #include "alu-n-tst.h"
84 #undef N
85 
86 #define N 32
87 #include "alu-n-tst.h"
88 #undef N
89 
90 #define N 64
91 #include "alu-n-tst.h"
92 #undef N
93 
94 
95 
96 int
main()97 main ()
98 {
99   do_alu_8_tests ();
100   do_alu_16_tests ();
101   do_alu_32_tests ();
102   do_alu_64_tests ();
103   return (errors != 0);
104 }
105