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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [inst-set-test/] [inst-set-test-old.c] - Blame information for rev 107

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 107 jeremybenn
/* inst-set-test.c. Instruction set test for Or1ksim
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
/* This is a complex instruction test for OR1200 */
29
/* trap, movhi, mul, nop, rfe, sys instructions not tested*/
30
/* Currently not working. Compiles with warnings, runs with errors. */
31
 
32
#include "support.h"
33
 
34
volatile unsigned long test = 0xdeaddead;
35
 
36
#define TEST_32(c1,c2,val1,val2,op) \
37
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
38
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
39
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
40
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
41
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
42
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
43
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
44
  test ^= ((c1 (val1)) op (c2 (val2)));  test ^= ((c1 (val2)) op (c2 (val1)));\
45
 
46
#define TEST_CASTS(val1,val2,op)\
47
  TEST_32((unsigned long), (unsigned long), val1, val2, op);\
48
  TEST_32((unsigned long), (signed long), val1, val2, op);\
49
  TEST_32((unsigned long), (unsigned short), val1, val2, op);\
50
  TEST_32((unsigned long), (signed short), val1, val2, op);\
51
  TEST_32((unsigned long), (unsigned char), val1, val2, op);\
52
  TEST_32((unsigned long), (signed char), val1, val2, op);\
53
    \
54
  TEST_32((unsigned short), (unsigned long), val1, val2, op);\
55
  TEST_32((unsigned short), (signed long), val1, val2, op);\
56
  TEST_32((unsigned short), (unsigned short), val1, val2, op);\
57
  TEST_32((unsigned short), (signed short), val1, val2, op);\
58
  TEST_32((unsigned short), (unsigned char), val1, val2, op);\
59
  TEST_32((unsigned short), (signed char), val1, val2, op);\
60
    \
61
  TEST_32((unsigned char), (unsigned long), val1, val2, op);\
62
  TEST_32((unsigned char), (signed long), val1, val2, op);\
63
  TEST_32((unsigned char), (unsigned short), val1, val2, op);\
64
  TEST_32((unsigned char), (signed short), val1, val2, op)\
65
  TEST_32((unsigned char), (unsigned char), val1, val2, op);\
66
  TEST_32((unsigned char), (signed char), val1, val2, op);
67
 
68
 
69
void add_test ()
70
{
71
  int i, j;
72
  TEST_CASTS(0x12345678, 0x12345678, +);
73
  TEST_CASTS(0x12345678, 0x87654321, +);
74
  TEST_CASTS(0x87654321, 0x12345678, +);
75
  TEST_CASTS(0x87654321, 0x87654321, +);
76
 
77
  TEST_CASTS(0x1234, -0x1234, +);
78
  TEST_CASTS(0x1234, -0x1234, +);
79
  TEST_CASTS(-0x1234, 0x1234, +);
80
  TEST_CASTS(-0x1234, -0x1234, +);
81
 
82
  for (i = -1; i <= 1; i++)
83
    for (j = -1; j <= 1; j++)
84
      TEST_CASTS (i, j, +);
85
  report (test);
86
}
87
 
88
void and_test ()
89
{
90
/*  TEST_CASTS(0x12345678, 0x12345678, &);
91
  TEST_CASTS(0x12345678, 0x87654321, &);
92
  TEST_CASTS(0x87654321, 0x12345678, &);
93
  TEST_CASTS(0x87654321, 0x87654321, &);
94
 
95
  TEST_CASTS(0x12345678, 0x0, &);
96
  TEST_CASTS(0x12345678, 0xffffffff, &);
97
  TEST_CASTS(0x87654321, 0x80000000, &);
98
  TEST_CASTS(0x87654321, 0x08000000, &);
99
 
100
  TEST_CASTS(0x12345678, 0x12345678, &&);
101
  TEST_CASTS(0x12345678, 0x87654321, &&);
102
  TEST_CASTS(0x87654321, 0x12345678, &&);
103
  TEST_CASTS(0x87654321, 0x87654321, &&);
104
 
105
  TEST_CASTS(0x12345678, 0x0, &&);
106
  TEST_CASTS(0x12345678, 0xffffffff, &&);
107
  TEST_CASTS(0x87654321, 0x80000000, &&);
108
  TEST_CASTS(0x87654321, 0x08000000, &&);
109
  report (test);*/
110
}
111
 
112
void branch_test ()
113
{
114
        /* bf, bnf, j, jal, jalr, jr, sfeq, sfges, sfgeu, sfgts, sfgtu, sfles, sfleu, sflts, sfltu, sfne */
115
  report (test);
116
}
117
 
118
void load_store_test ()
119
{
120
  volatile long a;
121
  volatile short b;
122
  volatile char c;
123
  unsigned long *pa = (unsigned long *)&a;
124
  unsigned short *pb = (unsigned short *)&b;
125
  unsigned char *pc = (unsigned char *)&c;
126
 
127
  test ^= a = 0xdeadbeef;
128
  test ^= b = 0x12345678;
129
  test ^= c = 0x87654321;
130
  test ^= a = b;
131
  test ^= b = c;
132
  test ^= a;
133
  test ^= (unsigned long)a;
134
  test ^= (unsigned short)a;
135
  test ^= (unsigned char)a;
136
 
137
  test ^= (unsigned long)b;
138
  test ^= (unsigned short)b;
139
  test ^= (unsigned char)b;
140
 
141
  test ^= (unsigned long)c;
142
  test ^= (unsigned short)c;
143
  test ^= (unsigned char)c;
144
 
145
  test ^= *pa = 0xabcdef12;
146
  test ^= *pb = 0x12345678;
147
  test ^= *pc = 0xdeadbeef;
148
 
149
  test ^= (signed long)c;
150
  test ^= (signed short)c;
151
  test ^= (signed char)c;
152
 
153
  test ^= (signed long)a;
154
  test ^= (signed short)a;
155
  test ^= (signed char)a;
156
 
157
  test ^= (signed long)b;
158
  test ^= (signed short)b;
159
  test ^= (signed char)b;
160
 
161
  test ^= *pa = 0xaabbccdd;
162
  test ^= *pb = 0x56789012;
163
  test ^= *pc = 0xb055b055;
164
 
165
  test ^= (unsigned long)b;
166
  test ^= (signed long)c;
167
  test ^= (unsigned long)a;
168
  test ^= (unsigned short)c;
169
  test ^= (unsigned short)a;
170
  test ^= (unsigned char)c;
171
  test ^= (unsigned short)b;
172
  test ^= (unsigned char)b;
173
  test ^= (unsigned char)a;
174
  report (test);
175
}
176
 
177
void or_test ()
178
{
179
/*  TEST_CASTS(0x12345678, 0x12345678, |);
180
  TEST_CASTS(0x12345678, 0x87654321, |);
181
  TEST_CASTS(0x87654321, 0x12345678, |);
182
  TEST_CASTS(0x87654321, 0x87654321, |);
183
 
184
  TEST_CASTS(0x12345678, 0x0, |);
185
  TEST_CASTS(0x12345678, 0xffffffff, |);
186
  TEST_CASTS(0x87654321, 0x80000000, |);
187
  TEST_CASTS(0x87654321, 0x08000000, |);
188
 
189
  TEST_CASTS(0x12345678, 0x12345678, ||);
190
  TEST_CASTS(0x12345678, 0x87654321, ||);
191
  TEST_CASTS(0x87654321, 0x12345678, ||);
192
  TEST_CASTS(0x87654321, 0x87654321, ||);
193
 
194
  TEST_CASTS(0x12345678, 0x0, ||);
195
  TEST_CASTS(0x12345678, 0xffffffff, ||);
196
  TEST_CASTS(0x87654321, 0x80000000, ||);
197
  TEST_CASTS(0x87654321, 0x08000000, ||);*/
198
  report (test);
199
}
200
 
201
void xor_test ()
202
{
203
/*  TEST_CASTS(0x12345678, 0x12345678, ^);
204
  TEST_CASTS(0x12345678, 0x87654321, ^);
205
  TEST_CASTS(0x87654321, 0x12345678, ^);
206
  TEST_CASTS(0x87654321, 0x87654321, ^);
207
 
208
  TEST_CASTS(0x12345678, 0x0, ^);
209
  TEST_CASTS(0x12345678, 0xffffffff, ^);
210
  TEST_CASTS(0x87654321, 0x80000000, ^);
211
  TEST_CASTS(0x87654321, 0x08000000, ^);*/
212
  report (test);
213
}
214
 
215
void sll_test ()
216
{
217
  int i;
218
  for (i = -1; i < 40; i++)
219
    TEST_CASTS(0xdeaf1234, i, <<);
220
  for (i = -1; i < 33; i++)
221
    TEST_CASTS(0x12345678, i, <<);
222
  for (i = -1; i < 33; i++)
223
    TEST_CASTS(0xdea12345, i, <<);
224
 
225
  test ^= (unsigned long)0xabcd4321 << test;
226
  test ^= (signed long)0xabcd4321 << test;
227
  test ^= (unsigned long)0xabcd << test;
228
  test ^= (signed long)0xabcd << test;
229
  report (test);
230
}
231
 
232
void srl_sra_test ()
233
{
234
  int i;
235
  for (i = -1; i < 40; i++)
236
    TEST_CASTS(0xdeaf1234, i, >>);
237
  for (i = -1; i < 33; i++)
238
    TEST_CASTS(0x12345678, i, >>);
239
  for (i = -1; i < 33; i++)
240
    TEST_CASTS(0xdea12345, i, >>);
241
 
242
  test ^= (unsigned long)0xabcd4321 >> test;
243
  test ^= (signed long)0xabcd4321 >> test;
244
  test ^= (unsigned long)0xabcd >> test;
245
  test ^= (signed long)0xabcd >> test;
246
  report (test);
247
}
248
 
249
 
250
void ror_test ()
251
{
252
  unsigned long a;
253
  int i;
254
  for (i = -1; i < 40; i++) {
255
    asm ("l.ror %0, %1, %2" : "=r" (a) : "r" (0x12345678), "r" (i));
256
    test ^= a;
257
    asm ("l.ror %0, %1, %2" : "=r" (a) : "r" (0xabcdef), "r" (i));
258
    test ^= a;
259
  }
260
  asm ("l.ror %0, %1, %2" : "=r" (a) : "r" (0x12345678), "r" (0x12345678));
261
  test ^= a;
262
  report (test);
263
}
264
 
265
void sub_test ()
266
{
267
/*  int i, j;
268
  TEST_CASTS(0x12345678, 0x12345678, -);
269
  TEST_CASTS(0x12345678, 0x87654321, -);
270
  TEST_CASTS(0x87654321, 0x12345678, -);
271
  TEST_CASTS(0x87654321, 0x87654321, -);
272
 
273
  TEST_CASTS(0x1234, -0x1234, -);
274
  TEST_CASTS(0x1234, -0x1234, -);
275
  TEST_CASTS(-0x1234, 0x1234, -);
276
  TEST_CASTS(-0x1234, -0x1234, -);
277
 
278
  for (i = -1; i <= 1; i++)
279
    for (j = -1; j <= 1; j++)
280
      TEST_CASTS (i, j, -);
281
  report (test);*/
282
}
283
 
284
int main ()
285
{
286
  add_test ();
287
  and_test ();
288
  branch_test ();
289
  load_store_test ();
290
  or_test ();
291
  sll_test ();
292
  srl_sra_test ();
293
  xor_test ();
294
  sub_test ();
295
  return 0;
296
}

powered by: WebSVN 2.1.0

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