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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [cbasic/] [cbasic.c] - Blame information for rev 81

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

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

powered by: WebSVN 2.1.0

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