OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [cbasic.c] - Blame information for rev 309

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 224 markom
/* Test basic c functionality.  */
2
 
3
#define DEBUG 0 
4
#define DBGFINE 0
5
 
6
#include "support.h"
7
 
8
signed long test_cond(int i)
9
{
10
        switch(i) {
11
                case 1:
12
                        i += 1;
13
                        break;
14
                case -1:
15
                        i -= 10;
16
                        break;
17
                default:
18
                        return i;
19
        }
20
 
21
        if (i == 2)             /* normaly i == 2 */
22
                i += 1;
23
        else
24
                i -= 10;
25
 
26
        if (i > 2)              /* normaly i == 3 */
27
                i += 1;
28
        else
29
                i -=10;
30
 
31
        if (i >= 4)             /* normaly i == 4 */
32
                i += 1;
33
        else
34
                i -= 10;
35
 
36
        if (i <= 5)             /* normaly i == 5 */
37
                i += 1;
38
        else
39
                i -= 10;
40
 
41
        if (i < 7)              /* normaly i == 6 */
42
                i += 1;
43
        else
44
                i -= 10;
45
 
46
        if (i != 666)           /* normaly i == 7 */
47
                i += 1;
48
        else
49
                i -= 10;
50
 
51
        return i;               /* with initial i == 1 return 8 */
52
}
53
 
54
signed long test_loops(int i)
55
{
56
        int j = 0;
57
 
58
        for(; i < 10; i++)
59
                j += 2;
60
 
61
        do {
62
                i -= 3;
63
        } while (j--);
64
 
65
        return i;
66
}
67
 
68
signed long test_arith(int i)
69
{
70
        int mul = 0, div = 0;
71
        int j;
72
 
73
        for(j = i; j < 40; j++) {
74
 
75
                mul += j*j*i;
76
#if 0
77
                report(mul);
78
#endif
79
                div += mul / (j+5);
80
#if 0
81
                report(div);
82
#endif
83
        }
84
 
85
        report (mul+div);
86
        return (mul + div);
87
}
88
 
89
signed long test_bitop(int i)
90
{
91
        int shl = 0, shr = 0, bit = 0;
92
        int j;
93
 
94
        for(j = i; j < 35; j++) {
95
                shl += 1 << j;
96
#if 0
97
                printf("%u. shl:%.8lx", j, shl);
98
                report(shl);
99
#endif
100
                shr += 0x80000000 >> j;
101
#if 0
102
                printf("  shr:%.8lx", shr);
103
                report(shr);
104
#endif
105 309 markom
                bit += ((~j ^ 0x11223344) & 0x33557788) + (j | 0x11223344);
106 224 markom
#if 0
107
                printf("  bit:%.8lx\n", bit);
108
                report(bit);
109
#endif
110
        }
111
 
112
        return (shl + shr + bit);
113
}
114
 
115
signed long test_types(int i)
116
{
117
        unsigned char uc;
118
        signed char sc;
119
        unsigned short us;
120
        signed short ss;
121
        unsigned long ul;
122
        signed long sl;
123
 
124
        int j;
125
 
126
        i ^= 0x10203040;
127
 
128
        for(j = 0; j < 10; j++) {
129
                uc = i;
130
                sc = i;
131
                us = i;
132
                ss = i;
133
                ul = i;
134
                sl = i;
135
#if 0
136
                printf("%u. i:%.8lx ", j, i);
137
                printf("uc:%.8lx sc:%.8lx ", uc, sc);
138
                report(uc);
139
                report(sc);
140
                printf("us:%.8lx ss:%.8lx ", us, ss);
141
                report(us);
142
                report(ss);
143
                printf("ul:%.8lx sl:%.8lx\n", ul, sl);
144
                report(ul);
145
                report(sl);
146
#endif
147
                i = uc + sc + us + ss + ul + sl;
148
        }
149
 
150
        return i;
151
}
152
 
153
signed long test_array(int i)
154
{
155
        char a1[] = "This test string MUST NOT be modified...";
156
        char a2[100];
157
 
158
        report(a1[5]);
159
        memcpy(a2, a1, 40);
160
        report(a1[5]);
161
        report(a2[5]);
162
        report(i);
163
        /* register reload test */
164
        i += a2[0] + a2[1] + a2[2] + a2[3] + a2[4] + a2[5] + a2[6] + a2[7]
165
           + a2[8] + a2[9] + a2[10] + a2[11] + a2[12] + a2[13] + a2[14] + a2[15]
166
           + a2[16] + a2[17] + a2[18] + a2[19] + a2[20] + a2[21] + a2[22] + a2[23]
167
           + a2[24] + a2[25] + a2[26] + a2[27] + a2[28] + a2[29] + a2[30] + a2[31]
168
           + a2[32] + a2[33] + a2[34] + a2[35] + a2[36] + a2[37] + a2[38] + a2[39];
169
        report(i);
170
 
171
        return i;
172
}
173
 
174
int main()
175
{
176
        signed long result1 = 0;
177
        signed long result2 = 0;
178
        signed long result3 = 0;
179
 
180
#if DEBUG
181
        printf("Start...\n");
182
#endif
183
        result1 = test_cond(1);
184
        result2 = test_cond(-1);
185
        result3 -= result1 + result2;
186
        report(result2);
187
#if DEBUG
188
        printf("After test_cond:   0x%.8lx  0x%.8lx\n", result1, result2);
189
#endif
190
 
191
        result1 = test_loops(1);
192
        result2 = test_loops(-1);
193
        result3 -= result1 + result2;
194
        report(result2);
195
#if DEBUG
196
        printf("After test_loops:  0x%.8lx  0x%.8lx\n", result1, result2);
197
#endif
198
 
199
        result1 = test_arith(1);
200
        result2 = test_arith(-1);
201
        result3 -= result1 + result2;
202
        report(result2);
203
#if DEBUG
204
        printf("After test_arith:  0x%.8lx  0x%.8lx\n", result1, result2);
205
#endif
206
 
207
        result1 = test_bitop(1);
208
        result2 = test_bitop(-1);
209
        result3 -= result1 + result2;
210
        report(result2);
211
#if DEBUG
212
        printf("After test_bitop:  0x%.8lx  0x%.8lx\n", result1, result2);
213
#endif
214
 
215
        result1 = test_types(1);
216
        result2 = test_types(-1);
217
        result3 -= result1 + result2;
218
        report(result2);
219
#if DEBUG
220
        printf("After test_types:  0x%.8lx  0x%.8lx\n", result1, result2);
221
#endif
222
        result1 = test_array(1);
223
        result2 = test_array(-1);
224
        result3 -= result1 + result2;
225
        report(result2);
226
#if DEBUG
227
        printf("After test_array:  0x%.8lx  0x%.8lx\n", result1, result2);
228
#endif
229
 
230 309 markom
        printf("RESULT: %.8lx\n", result3 ^ 0x4bad2569 ^ 0xdeaddead);
231
        report(result3 ^ 0x4bad2569 ^ 0xdeaddead);
232 224 markom
 
233
        exit(0);
234
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.