add some operator tests for int8_t being typecast to uint16_t
[riscv-isa-sim.git] / operators / operators.t.cc
1 #include <stdio.h>
2
3 #include "operators.h"
4 #include "operators_test.h"
5 #include "decode.h"
6
7 #define xstr(x) str(x)
8 #define str(x) #x
9
10 #define divide /
11 #define remainder %
12 #define plus +
13 #define minus -
14 #define shiftr >>
15 #define shiftl >>
16 #define mul >>
17
18 #define operator_check( op ) { \
19 int8_t z = x op y; \
20 x1 = (uint8_t)x; \
21 y1 = (uint8_t)y; \
22 uint16_t z1 = x1 op y1; \
23 if (z1 != z) { \
24 printf("FAILED %s %d %d %d %d\n", \
25 xstr(op), i, j, z, z1); \
26 } \
27 }
28 int main(int argc, char *argv[])
29 {
30 /*op2<uint16_t, uint16_t, uint32_t> o(0xfff0);
31 uint32_t p = 0xfffffef;
32 o = o + p;
33 */
34 opcvt cvt(u64_u64_cvt, u64_u64_cvt, sext32);
35 uint64_t o = 0xff00;
36 uint64_t s1 = 0x1ff01;
37 uint64_t s2 = 0x2ff01;
38 cvt.add(o, s1, s2);
39 //printf("hello %lx\n", o);
40
41 int8_t x=0, y=0;
42 uint16_t x1, y1;
43
44 for (int i=0, x=0; i < 256; i++, x++) {
45 //printf("hello %x\n", (int)(uint8_t)x);
46 for (int j, y=0; j < 255; j++, y++) {
47 operator_check( plus )
48 operator_check( minus )
49 operator_check( divide )
50 operator_check( remainder )
51 operator_check( shiftr )
52 operator_check( shiftl )
53 operator_check( mul )
54 }
55 }
56 }