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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mp3/] [sw/] [cbasic/] [cbasic.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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