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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-cbasic.c] - Blame information for rev 393

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

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

powered by: WebSVN 2.1.0

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