]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/testsuite/common/alu-tst.c
sim: tests: get common tests working again
[thirdparty/binutils-gdb.git] / sim / testsuite / common / alu-tst.c
CommitLineData
c906108c
SS
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
254c3783 17#include <stdlib.h>
c906108c
SS
18#include <string.h>
19
254c3783
MF
20#define PACKAGE "sim"
21
c906108c
SS
22#include "sim-basics.h"
23
24#include "sim-alu.h"
25
26#include <stdio.h>
27
28typedef struct {
29 char *op;
30 unsigned64 arg;
31} alu_op;
32
33typedef struct {
34 unsigned64 begin;
35 alu_op ops[4];
36 unsigned64 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
53static void
54print_hex (unsigned64 val, int nr_bits)
55{
56 switch (nr_bits)
57 {
58 case 8:
59 printf ("0x%02lx", (long) (unsigned8) (val));
60 break;
61 case 16:
62 printf ("0x%04lx", (long) (unsigned16) (val));
63 break;
64 case 32:
65 printf ("0x%08lx", (long) (unsigned32) (val));
66 break;
67 case 64:
254c3783 68 printf ("0x%016llx", (long long) (unsigned64) (val));
c906108c
SS
69 break;
70 default:
71 abort ();
72 }
73}
74
75
76int 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
97int
98main ()
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}