xref: /netbsd-src/external/gpl3/gdb/dist/sim/testsuite/common/alu-tst.c (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
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 <stdlib.h>
18 #include <string.h>
19 
20 #define PACKAGE "sim"
21 
22 #include "sim-basics.h"
23 
24 #include "sim-alu.h"
25 
26 #include <stdio.h>
27 
28 typedef struct {
29   char *op;
30   uint64_t arg;
31 } alu_op;
32 
33 typedef struct {
34   uint64_t begin;
35   alu_op ops[4];
36   uint64_t result;
37   int carry_borrow;
38   int overflow;
39 } alu_test;
40 
41 #define MAX_INT8 UNSIGNED64 (127)
42 #define MIN_INT8 UNSIGNED64 (128)
43 
44 #define MAX_INT16 UNSIGNED64 (32767)
45 #define MIN_INT16 UNSIGNED64 (32768)
46 
47 #define MAX_INT32 UNSIGNED64 (0x7fffffff)
48 #define MIN_INT32 UNSIGNED64 (0x80000000)
49 
50 #define MAX_INT64 UNSIGNED64 (0x7fffffffffffffff)
51 #define MIN_INT64 UNSIGNED64 (0x8000000000000000)
52 
53 static void
print_hex(uint64_t val,int nr_bits)54 print_hex (uint64_t val, int nr_bits)
55 {
56   switch (nr_bits)
57     {
58     case 8:
59       printf ("0x%02lx", (long) (uint8_t) (val));
60       break;
61     case 16:
62       printf ("0x%04lx", (long) (uint16_t) (val));
63       break;
64     case 32:
65       printf ("0x%08lx", (long) (uint32_t) (val));
66       break;
67     case 64:
68       printf ("0x%016llx", (long long) (uint64_t) (val));
69       break;
70     default:
71       abort ();
72     }
73 }
74 
75 
76 int errors = 0;
77 
78 
79 #define N 8
80 #include "alu-n-tst.h"
81 #undef N
82 
83 #define N 16
84 #include "alu-n-tst.h"
85 #undef N
86 
87 #define N 32
88 #include "alu-n-tst.h"
89 #undef N
90 
91 #define N 64
92 #include "alu-n-tst.h"
93 #undef N
94 
95 
96 
97 int
main()98 main ()
99 {
100   do_alu_8_tests ();
101   do_alu_16_tests ();
102   do_alu_32_tests ();
103   do_alu_64_tests ();
104   return (errors != 0);
105 }
106