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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [cbasic/] [cbasic.c] - Blame information for rev 508

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

Line No. Rev Author Line
1 90 jeremybenn
/* cbasic.c. Test of Or1ksim basic C program functionality
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
/* Test basic c functionality.  */
29
 
30
#define DEBUG 0 
31
#define DBGFINE 0
32
 
33
#include "support.h"
34
 
35
signed long test_cond(int i)
36
{
37
  switch(i) {
38
    case 1:
39
      i += 1;
40
      break;
41
    case -1:
42
      i -= 10;
43
      break;
44
    default:
45
      return i;
46
  }
47
 
48
  if (i == 2)   /* normaly i == 2 */
49
    i += 1;
50
  else
51
    i -= 10;
52
 
53
  if (i > 2)    /* normaly i == 3 */
54
    i += 1;
55
  else
56
    i -=10;
57
 
58
  if (i >= 4)   /* normaly i == 4 */
59
    i += 1;
60
  else
61
    i -= 10;
62
 
63
  if (i <= 5)   /* normaly i == 5 */
64
    i += 1;
65
  else
66
    i -= 10;
67
 
68
  if (i < 7)    /* normaly i == 6 */
69
    i += 1;
70
  else
71
    i -= 10;
72
 
73
  if (i != 666)   /* normaly i == 7 */
74
    i += 1;
75
  else
76
    i -= 10;
77
 
78
  return i;   /* with initial i == 1 return 8 */
79
}
80
 
81
signed long test_loops(int i)
82
{
83
  int j = 0;
84
 
85
  for(; i < 10; i++)
86
    j += 2;
87
 
88
  do {
89
    i -= 3;
90
  } while (j--);
91
 
92
  return i;
93
}
94
 
95
signed long test_arith(int i)
96
{
97
  int mul = 0, div = 0;
98
  int j;
99
 
100
  for(j = i; j < 40; j++) {
101
 
102
    mul += j*j*i;
103
#if 0
104
    report(mul);
105
#endif
106
    div += mul / (j+5);
107
#if 0
108
    report(div);
109
#endif
110
  }
111
 
112
  report (mul+div);
113
  return (mul + div);
114
}
115
 
116
signed long test_bitop(int i)
117
{
118
  int shl = 0, shr = 0, bit = 0;
119
  int j;
120
 
121
  for(j = i; j < 35; j++) {
122
    shl += 1 << j;
123
#if 0
124
    printf("%u. shl:%08lx", j, shl);
125
    report(shl);
126
#endif
127
    shr += 0x80000000 >> j;
128
#if 0
129
    printf("  shr:%08lx", shr);
130
    report(shr);
131
#endif
132
    bit += ((~j ^ 0x11223344) & 0x33557788) + (j | 0x11223344);
133
#if 0
134
    printf("  bit:%08lx\n", bit);
135
    report(bit);
136
#endif
137
  }
138
 
139
  return (shl + shr + bit);
140
}
141
 
142
signed long test_types(int i)
143
{
144
  unsigned char uc;
145
  signed char sc;
146
  unsigned short us;
147
  signed short ss;
148
  unsigned long ul;
149
  signed long sl;
150
 
151
  int j;
152
 
153
  i ^= 0x10203040;
154
 
155
  for(j = 0; j < 10; j++) {
156
    uc = i;
157
    sc = i;
158
    us = i;
159
    ss = i;
160
    ul = i;
161
    sl = i;
162
#if 0
163
    printf("%u. i:%08lx ", j, i);
164
    printf("uc:%08lx sc:%08lx ", uc, sc);
165
    report(uc);
166
    report(sc);
167
    printf("us:%08lx ss:%08lx ", us, ss);
168
    report(us);
169
    report(ss);
170
    printf("ul:%08lx sl:%08lx\n", ul, sl);
171
    report(ul);
172
    report(sl);
173
#endif
174
    i = uc + sc + us + ss + ul + sl;
175
  }
176
 
177
  return i;
178
}
179
 
180
signed long test_array(int i)
181
{
182
  char a1[] = "This test string MUST NOT be modified...";
183
  char a2[100];
184
 
185
  report(a1[5]);
186
  memcpy(a2, a1, 40);
187
  report(a1[5]);
188
  report(a2[5]);
189
  report(i);
190
  /* register reload test */
191
  i += a2[0] + a2[1] + a2[2] + a2[3] + a2[4] + a2[5] + a2[6] + a2[7]
192
     + a2[8] + a2[9] + a2[10] + a2[11] + a2[12] + a2[13] + a2[14] + a2[15]
193
     + a2[16] + a2[17] + a2[18] + a2[19] + a2[20] + a2[21] + a2[22] + a2[23]
194
     + a2[24] + a2[25] + a2[26] + a2[27] + a2[28] + a2[29] + a2[30] + a2[31]
195
     + a2[32] + a2[33] + a2[34] + a2[35] + a2[36] + a2[37] + a2[38] + a2[39];
196
  report(i);
197
 
198
  return i;
199
}
200
 
201
int main()
202
{
203
  signed long result1 = 0;
204
  signed long result2 = 0;
205
  signed long result3 = 0;
206
 
207
#if DEBUG
208
  printf("Start...\n");
209
#endif
210
  result1 = test_cond(1);
211
  result2 = test_cond(-1);
212
  result3 -= result1 + result2;
213
  report(result2);
214
#if DEBUG
215
  printf("After test_cond:   0x%08lx  0x%08lx\n", result1, result2);
216
#endif
217
 
218
  result1 = test_loops(1);
219
  result2 = test_loops(-1);
220
  result3 -= result1 + result2;
221
  report(result2);
222
#if DEBUG
223
  printf("After test_loops:  0x%08lx  0x%08lx\n", result1, result2);
224
#endif
225
 
226
  result1 = test_arith(1);
227
  result2 = test_arith(-1);
228
  result3 -= result1 + result2;
229
  report(result2);
230
#if DEBUG
231
  printf("After test_arith:  0x%08lx  0x%08lx\n", result1, result2);
232
#endif
233
 
234
  result1 = test_bitop(1);
235
  result2 = test_bitop(-1);
236
  result3 -= result1 + result2;
237
  report(result2);
238
#if DEBUG
239
  printf("After test_bitop:  0x%08lx  0x%08lx\n", result1, result2);
240
#endif
241
 
242
  result1 = test_types(1);
243
  result2 = test_types(-1);
244
  result3 -= result1 + result2;
245
  report(result2);
246
#if DEBUG
247
  printf("After test_types:  0x%08lx  0x%08lx\n", result1, result2);
248
#endif
249
  result1 = test_array(1);
250
  result2 = test_array(-1);
251
  result3 -= result1 + result2;
252
  report(result2);
253
#if DEBUG
254
  printf("After test_array:  0x%08lx  0x%08lx\n", result1, result2);
255
#endif
256
 
257
#ifdef XXX
258
#warning xxx
259
#endif
260
 
261
  printf("RESULT: 0x%08lx\n", result3 ^ 0x4bad2569 ^ 0xdeaddead);
262
  report(result3 ^ 0x4bad2569 ^ 0xdeaddead);
263
 
264
  exit(0);
265
}

powered by: WebSVN 2.1.0

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