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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [inst_set_test.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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