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 1765

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 409 markom
  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 224 markom
 
36 409 markom
  if (i <= 5)   /* normaly i == 5 */
37
    i += 1;
38
  else
39
    i -= 10;
40 224 markom
 
41 409 markom
  if (i < 7)    /* normaly i == 6 */
42
    i += 1;
43
  else
44
    i -= 10;
45 224 markom
 
46 409 markom
  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 224 markom
}
53
 
54
signed long test_loops(int i)
55
{
56 409 markom
  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 224 markom
}
67
 
68
signed long test_arith(int i)
69
{
70 409 markom
  int mul = 0, div = 0;
71
  int j;
72
 
73
  for(j = i; j < 40; j++) {
74
 
75
    mul += j*j*i;
76 224 markom
#if 0
77 409 markom
    report(mul);
78 224 markom
#endif
79 409 markom
    div += mul / (j+5);
80 224 markom
#if 0
81 409 markom
    report(div);
82 224 markom
#endif
83 409 markom
  }
84
 
85
  report (mul+div);
86
  return (mul + div);
87 224 markom
}
88
 
89
signed long test_bitop(int i)
90
{
91 409 markom
  int shl = 0, shr = 0, bit = 0;
92
  int j;
93
 
94
  for(j = i; j < 35; j++) {
95
    shl += 1 << j;
96 224 markom
#if 0
97 1024 simons
    printf("%u. shl:%.8lx", j, shl);
98 409 markom
    report(shl);
99 224 markom
#endif
100 409 markom
    shr += 0x80000000 >> j;
101 224 markom
#if 0
102 1024 simons
    printf("  shr:%.8lx", shr);
103 409 markom
    report(shr);
104 224 markom
#endif
105 409 markom
    bit += ((~j ^ 0x11223344) & 0x33557788) + (j | 0x11223344);
106 224 markom
#if 0
107 1024 simons
    printf("  bit:%.8lx\n", bit);
108 409 markom
    report(bit);
109 224 markom
#endif
110 409 markom
  }
111
 
112
  return (shl + shr + bit);
113 224 markom
}
114
 
115
signed long test_types(int i)
116
{
117 409 markom
  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 224 markom
 
126 409 markom
  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 224 markom
#if 0
136 1024 simons
    printf("%u. i:%.8lx ", j, i);
137
    printf("uc:%.8lx sc:%.8lx ", uc, sc);
138 409 markom
    report(uc);
139
    report(sc);
140 1024 simons
    printf("us:%.8lx ss:%.8lx ", us, ss);
141 409 markom
    report(us);
142
    report(ss);
143 1024 simons
    printf("ul:%.8lx sl:%.8lx\n", ul, sl);
144 409 markom
    report(ul);
145
    report(sl);
146 224 markom
#endif
147 409 markom
    i = uc + sc + us + ss + ul + sl;
148
  }
149
 
150
  return i;
151 224 markom
}
152
 
153
signed long test_array(int i)
154
{
155 409 markom
  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 224 markom
}
173
 
174
int main()
175 409 markom
{
176
  signed long result1 = 0;
177
  signed long result2 = 0;
178
  signed long result3 = 0;
179 224 markom
 
180
#if DEBUG
181 1024 simons
  printf("Start...\n");
182 224 markom
#endif
183 409 markom
  result1 = test_cond(1);
184
  result2 = test_cond(-1);
185
  result3 -= result1 + result2;
186
  report(result2);
187 224 markom
#if DEBUG
188 1024 simons
  printf("After test_cond:   0x%.8lx  0x%.8lx\n", result1, result2);
189 224 markom
#endif
190
 
191 409 markom
  result1 = test_loops(1);
192
  result2 = test_loops(-1);
193
  result3 -= result1 + result2;
194
  report(result2);
195 224 markom
#if DEBUG
196 1024 simons
  printf("After test_loops:  0x%.8lx  0x%.8lx\n", result1, result2);
197 224 markom
#endif
198
 
199 409 markom
  result1 = test_arith(1);
200
  result2 = test_arith(-1);
201
  result3 -= result1 + result2;
202
  report(result2);
203 224 markom
#if DEBUG
204 1024 simons
  printf("After test_arith:  0x%.8lx  0x%.8lx\n", result1, result2);
205 224 markom
#endif
206
 
207 409 markom
  result1 = test_bitop(1);
208
  result2 = test_bitop(-1);
209
  result3 -= result1 + result2;
210
  report(result2);
211 224 markom
#if DEBUG
212 1024 simons
  printf("After test_bitop:  0x%.8lx  0x%.8lx\n", result1, result2);
213 224 markom
#endif
214
 
215 409 markom
  result1 = test_types(1);
216
  result2 = test_types(-1);
217
  result3 -= result1 + result2;
218
  report(result2);
219 224 markom
#if DEBUG
220 1024 simons
  printf("After test_types:  0x%.8lx  0x%.8lx\n", result1, result2);
221 224 markom
#endif
222 409 markom
  result1 = test_array(1);
223
  result2 = test_array(-1);
224
  result3 -= result1 + result2;
225
  report(result2);
226 224 markom
#if DEBUG
227 1024 simons
  printf("After test_array:  0x%.8lx  0x%.8lx\n", result1, result2);
228 224 markom
#endif
229
 
230 493 markom
#ifdef XXX
231
#warning xxx
232
#endif
233
 
234 1024 simons
  printf("RESULT: %.8lx\n", result3 ^ 0x4bad2569 ^ 0xdeaddead);
235 409 markom
  report(result3 ^ 0x4bad2569 ^ 0xdeaddead);
236 224 markom
 
237 409 markom
  exit(0);
238 224 markom
}

powered by: WebSVN 2.1.0

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