lltest.c
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <rmon.h>
#include "corefunc.h"
static long long fll ( long long );
static long fi ( long);
static long long f2 (long long, long long *, long long);
static long long fll ( long long a)
{
if (a > 3)
return a;
else if (a == 0)
return 1;
else
return a*a;
}
static long fi ( long a)
{
return a+1;
}
static long long f2 (long long a, long long *p, long long b)
{
return a+b+ *p;
}
lltest()
{
int numFailures = 0;
long long a, b;
unsigned long long c, d;
int i, j;
long long arr[4];
long long arri[2] = {0x100001000LL, 3};
struct rec {
int one;
long long two;
} vrec;
/* lladdsub */
a = 0x10000000aLL;
b = a;
b++;
d = b - 1;
numFailures += check_equal(a, d);
c = a + b;
numFailures += check_equal(c, 0x200000015LLU);
a--; /* 0x100000009 */
d = c - a;
b = -a;
numFailures += check_equal(d, 0x10000000cLL);
numFailures += check_equal(b, 0xfffffffefffffff7LL);
/* llcmp */
a = 2;
b = 5LL;
c = a > -2;
numFailures += check_equal(c, 1);
i = a > 0x100000002LL;
numFailures += check_equal(i, 0);
i = (a > -2 ? 2 : 3);
numFailures += check_equal(i, 2);
i = (a > 0x100000002LL ? 2 : 3);
numFailures += check_equal(i, 3);
/* llmisc */
numFailures += check_equal(sizeof(long long), 8);
numFailures += check_equal(__builtin_alignof(long long), 8);
c = 4;
arr[0] = arri[1];
arr[3] = arr[0];
a = arr[3];
numFailures += check_equal(a, 3);
arr[a] >>= 1;
numFailures += check_equal(arr[a], 1);
vrec.one = 1;
a--;
vrec.two = a;
numFailures += check_equal(vrec.two, 2LL);
c ^= 1;
/* c == 5 */
c = ~c & (c | 2);
numFailures += check_equal(c, 2);
c = (long long) 3.0;
numFailures += check_equal(c, 3);
switch (c) {
case 0:
osSyncPrintf("switch fail\n");
numFailures++;
break;
case 3LL:
break;
default:
osSyncPrintf("switch fail\n");
numFailures++;
break;
}
/* llmuldiv */
a = 2;
b = 5LL;
b *= a;
numFailures += check_equal(b, 10);
c = b / 3;
numFailures += check_equal(c, 3);
c = 1 << (long long)((a < 3 ? 1 : 3)*4%3+1);
numFailures += check_equal(c, 4LLU);
b = a*4%3+1;
numFailures += check_equal(b, 3);
b >>= 1;
numFailures += check_equal(b, 1);
/* llpars() */
i = 1;
a = 0;
a = i;
a = fll(a);
numFailures += check_equal(a, 1);
i = a;
i = fll(i);
a = fll(a+i);
numFailures += check_equal(a, 4);
a = fll(0);
numFailures += check_equal(a, 1);
a = fll(4);
numFailures += check_equal(a, 4);
a = fi(a);
numFailures += check_equal(a, 5);
a = f2(-1, &a, 2);
numFailures += check_equal(a, 6);
return(numFailures);
}