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

Subversion Repositories forwardcom

[/] [forwardcom/] [testsuite/] [test_formats.as] - Blame information for rev 168

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

Line No. Rev Author Line
1 160 Agner
/**************************  tests_formats.as  ********************************
2
* Author:        Agner Fog
3
* date created:  2021-07-13
4
* last modified: 2021-08-04
5
* Version:       1.11
6
* Project:       ForwardCom Test suite, assembly code
7
* Description:   Test the different instruction formats
8
*
9
* This test program will test all instruction formats for general purpose
10
* registers, including formats for multi-format instructions, single-format
11
* instructions, and jump instructions.
12
*
13
* Copyright 2021 GNU General Public License v. 3 http://www.gnu.org/licenses
14
******************************************************************************/
15
 
16
// Library functions in libc_light.li
17
extern _printf:   function reguse=0xF,0          // write formatted string to stdout
18
extern _sprintf:  function reguse=0xF,0          // write formatted string to string buffer
19
 
20
const section read ip                            // read-only data section
21
 
22
// Text strings:
23
introtext:    int8 "\nForwardCom test suite\nTest all instruction formats for general purpose registers."  // intro text,
24
              int8 "\nPress Run to continue\n", 0
25
newline:      int8 "\n", 0                                                                               // newline
26
press_run:    int8 "\nPress Run to continue", 0
27
multiformat:  int8 "\nMultiformat:", 0
28
singleformat: int8 "\nSingle format:", 0
29
jumpformat:   int8 "\nJump format:", 0
30
 
31
// format strings used by print_result
32
format1:      int8 "%1X%c", 0
33
format2:      int8 "\n%10s%6c", 0
34
 
35
// arbitrary test data
36
%T = 0x7BC30956
37
T1:      int32 T, T+1, T+2, T+3, T+4, T+5, T+6, T+7
38
 
39
const end
40
 
41
 
42
code1 section execute                            // code section
43
 
44
__entry_point function public
45
_main function public
46
 
47
// print intro text and heading
48
int64  r0 = address [introtext]                  // intro text
49
call   _printf                                   // print string
50
 
51
breakpoint
52
 
53
int64  r0 = address [multiformat]
54
call   _printf                                   // print string
55
 
56
 
57
// disable error trap for unknown instructions and array bounds violation
58
int    r1 = 5
59
int    capab2 = write_capabilities(r1, 0)
60
 
61
// arbitrary test data
62
%A = 0x4956D5FE
63
%B = 0xE85B0AA1
64
 
65
// Test format 0.0 A  Multiformat RD = f2(RS, RT)
66
T00A:
67
int32  r20 = A
68
int32  r21 = B
69
int32  r1 = r20 + r21
70
int32  r0 = r1 == (A + B & 0xFFFFFFFF)
71
int    r1 = 0x00A
72
call   print_result
73
 
74
// Test format 0.1 B  Multiformat RD = f2(RS, IM1)
75
T01B:
76
int32  r1 = r20 + 0x59
77
int32  r2 = r1 ^ - 0x78
78
int32  r0 = r2 == ((A + 0x59 ^ -0x78) & 0xFFFFFFFF)
79
int    r1 = 0x01B
80
call   print_result
81
 
82
// Test format 0.8 A  Multiformat RD = f2(RD, [RS+RT*OS])
83
T08A:
84
int64  r1 = address [T1]
85
int    r2 = 2
86
int    r3 = r20
87
int32  r3 += [r1 + r2*4]
88
int32  r4 = A + T + 2
89
int32  r0 = r3 == r4
90
int    r1 = 0x08A
91
call   print_result
92
 
93
// Test format 0.9 B  Multiformat RD = f2(RD, [RS+IM1*OS])
94
T09B:
95
int64  r1 = address [T1]
96
int    r3 = r20
97
int32  r3 -= [r1 + 12]
98
int32  r4 = A - (T + 3)
99
int32  r0 = r3 == r4
100
int    r1 = 0x09B
101
call   print_result
102
 
103
// Test format 2.0.0 E  Multiformat RD = f2(RT, [RS+IM2])
104
T200E:
105
int64  r1 = address [T1 + 200]
106
int32  r3 = r20 + [r1 - 200 + 8]
107
int32  r4 = A + T + 2
108
int32  r0 = r3 == r4
109
int    r1 = 0x200E
110
call   print_result
111
 
112
// Test format 2.0.1 E  Multiformat RD = f2(RU, [RS+RT+IM2])
113
T201E:
114
int64  r1 = address [T1 - 200]
115
int    r2 = 4
116
int32  r3 = r20 + [r1 + r2 + 200]
117
int32  r4 = A + T + 1
118
int32  r0 = r3 == r4
119
int    r1 = 0x201E
120
call   print_result
121
 
122
// Test format 2.0.2 E  Multiformat RD = f2(RU, [RS+RT*OS+IM2])
123
T202E:
124
int64  r1 = address [T1 - 200]
125
int    r2 = 4
126
int32  r3 = r20 + [r1 + r2*4 + 200]
127
int32  r0 = r3 == A + T + 4
128
int    r1 = 0x202E
129
call   print_result
130
 
131
// Test format 2.0.3 E  Multiformat RD = f2(RU, [RS+RT*OS]), limit = IM2
132
T203E:
133
int64  r1 = address [T1]
134
int    r2 = 4
135
int32  r3 = r20 + [r1 + r2*4], limit = 4
136
int32  r0 = r3 == A + T + 4
137
int    r4 = read_perf(perf16, 3)                 // counter for array overflow
138
int    r0 = r4 == 0 && r0
139
int32  r3 = r20 + [r1 + r2*4], limit = 3         // exceed limit
140
int    r4 = read_perf(perf16, 3)                 // counter should show array overflow
141
int    r0 = r4 == 1 && r0
142
int    r4 = read_perf(perf16, 0)                 // reset counter
143
int    r1 = 0x203E
144
call   print_result
145
 
146
// Test format 2.0.5 E  Multiformat  RD = f3(RU, [RS+RT*OS+IM2], IM3).
147
T205E:
148
int64  r1 = address [T1]
149
int    r2 = 2
150
int32  r4 = [r1] + 0x10
151
int32  r0 = r4 == (T + 0x10 & 0xFFFFFFFF)
152
int32  r4 = [r1 + 4*r2 + 8] + 0x10
153
int32  r0 = r4 == (T + 4 + 0x10 & 0xFFFFFFFF) && r0
154
int32  r3 = B
155
int32  r4 = add_add(r3, [r1 + 4*r2 + 8], 0x25)
156
int32  r0 = r4 == (B + T + 4 + 0x25 & 0xFFFFFFFF) && r0
157
int    r1 = 0x205E
158
call   print_result
159
 
160
// Test format 2.0.6 E  Multiformat  RD = f3(RU, RS, RT)
161
T206E:
162
int32  r2 = 0x20000
163
int32  r3 = r20 + r21 - r2
164
int32  r0 = r3 == (A + B - 0x20000 & 0xFFFFFFFF)
165
int    r1 = 0x206E
166
call   print_result
167
 
168
// Test format 2.0.7 E  Multiformat  RD = f3(RS, RT, IM2 << IM3)
169
T207E:
170
int32  r3 = r20 + 0x78000000       // shifted constant
171
int32  r0 = r3 == (A + 0x78000000 & 0xFFFFFFFF)
172
int32  r3 = r20 - r21 + 0x6A00     // constant not shifted because IM3 used for options
173
int32  r4 = A - B + 0x6A00 & 0xFFFFFFFF
174
int32  r0 = r3 == r4 && r0
175
int    r1 = 0x207E
176
call   print_result
177
 
178
// Test format 2.1 A  Multiformat  RD = f3(RD, RT, [RS+IM2]).
179
T21A:
180
int64  r10 = address [T1 + 0x10000000]
181
int32  r3 = r20 - [r10 - 0x10000000]
182
int32  r0 = r3 == A - T
183
int    r1 = 0x21A
184
call   print_result
185
 
186
// Test format 2.8 A  Multiformat  RD = f3(RS, RT, IM2)
187
T28A:
188
int32  r3 = r20 - 0x12345678
189
int32  r0 = r3 == A - 0x12345678
190
int32  r3 = r20 + r21 + 0x56781234
191
int32  r4 = A + B + 0x56781234 & 0xFFFFFFFF
192
int32  r0 = r3 == r4 && r0
193
int    r1 = 0x28A
194
call   print_result
195
 
196
 
197
int64 r0 = address [press_run]
198
call _printf
199
 
200
breakpoint
201
 
202
 
203
// Test format 3.0.0 E  Multiformat  RD = f3(RU, RT, [RS+IM4])
204
T300E:
205
int32  r3 = r20 + r21 - [r10 - 0x10000000]
206
int32  r0 = r3 == A + B - T
207
int    r1 = 0x300E
208
call   print_result
209
 
210
// Test format 3.0.2 E  Multiformat  RD = f2(RU, [RS+RT*OS+IM4])
211
T302E:
212
int  r2 = 2
213
int32  r3 = r20 + [r10 + r2*4 - 0x10000000]
214
int32  r0 = r3 == A + T + 2
215
int    r1 = 0x302E
216
call   print_result
217
 
218
// Test format 3.0.3 E  Multiformat  RD = f2(RU, [RS+RT*OS]), limit = IM4
219
T303E:
220
int64  r1 = address [T1 - 0x400000]
221
int    r2 = 0x100000
222
int32  r3 = r20 + [r1 + r2*4], limit = 0x100000
223
int32  r0 = r3 == A + T
224
int    r4 = read_perf(perf16, 3)                 // counter for array overflow
225
int    r0 = r4 == 0 && r0
226
int32  r3 = r20 + [r1 + r2*4], limit = 0x0FFFFF  // exceed limit
227
int    r4 = read_perf(perf16, 3)                 // counter should show array overflow
228
int    r0 = r4 == 1 && r0
229
int    r4 = read_perf(perf16, 0)                 // reset counter
230
int    r1 = 0x303E
231
call   print_result
232
 
233
// Test format 3.0.5 E  Multiformat  RD = f3(RU, [RS+RT*OS+IM2], IM4)
234
T305E:
235
int64  r1 = address [T1]
236
int    r2 = 3
237
int32  r3 = [r1 + r2*4] - 0x77665544
238
int32  r0 = r3 == T + 3 - 0x77665544
239
int32  r3 = r20 - [r1 + r2*4 + 4] + 0x44556677
240
int32  r4 = A - (T + 4) + 0x44556677 & 0xFFFFFFFF
241
int32  r0 = r3 == r4 && r0
242
int    r1 = 0x305E
243
call   print_result
244
 
245
// Test format 3.0.7 E  Multiformat  RD = f3(RS, RT, IM4 << IM2).
246
T307E:
247
int64  r3 = r20 - 0x77665544000000
248
int64  r4 = A - 0x77665544000000
249
int64  r0 = r3 == r4
250
// this will report success on a CPU that supports only 32 bits because only the lower 32 bits of the result are compared
251
int    r1 = 0x307E
252
call   print_result
253
 
254
// Test format 3.8 A  Multiformat  RD = f3(RS, RT, IM3:IM2)
255
T38A:
256
int64  r3 = r20 + 0x123456789ABCDEF0
257
int64  r4 = A + 0x123456789ABCDEF0
258
int64  r0 = r3 == r4
259
// this will report success on a CPU that supports only 32 bits because only the lower 32 bits of the result are compared
260
int    r1 = 0x38A
261
call   print_result
262
 
263
 
264
int64 r0 = address [press_run]
265
call _printf
266
 
267
breakpoint
268
 
269
int64 r0 = address [singleformat]
270
call _printf
271
 
272
 
273
// format 1.0 A  Single format RD = f2(RS, RT). unused
274
 
275
// Test format 1.1 C  Single format RD = f2(RD, IM1-2). 32-bit instructions
276
T11C:
277
int32  r2 = -0x23AB
278
int32  r3 = 0x450000
279
int32  r2 += r3
280
int32  r0 = r2 == 0x450000 - 0x23AB
281
int32  r2 = 0XABCD
282
int32  r2 -= 0x5432
283
int32  r2 ^= 0x44000
284
int32  r0 = (r2 == (0XABCD - 0x5432 ^ 0x44000)) && r0
285
int    r1 = 0x11C
286
call   print_result
287
 
288
// Test format 1.1 C,  64-bit instructions
289
T111C:
290
int64  r2 = -0x45AB
291
int64  r2 += 0x340000000
292
int64  r4 = 0x340000000 - 0x45AB
293
int64  r0 = r2 == r4
294
int64  r2 = -0x4500000000
295
int64  r2 ^= 0x5600000000000
296
int64  r4 = - 0x4500000000 ^ 0x5600000000000
297
int64  r0 = r2 == r4 && r0
298
int    r1 = 0x111C
299
call   print_result
300
 
301
// Test format 1.8 B  Single format RD = f2(RS, IM1)
302
T18B:
303
int32  r1 = -0x1234
304
int32  r2 = abs(r1, 1)
305
int32  r0 = r2 == 0x1234
306
int32  r3 = roundp2(r2,1)
307
int32  r0 = r3 == 0x2000 && r0
308
int    r1 = 0x18B
309
call   print_result
310
 
311
// Test format 2.0.6 E
312
T206E_s:
313
int32  r2 = T
314
int32  r3 = truth_tab3(r20, r21, r2, 0x78)
315
int32  r0 = r3 == (A & B ^ T)
316
int    r1 = 0x206E
317
call   print_result
318
 
319
// Test format 2.0.7 E
320
T207E_s:
321
int32  r1 = 7
322
int32  r2 = 0x12345678
323
int32  r3 = move_bits(r1, r2, 20, 0, 8)
324
int32  r0 = r3 == 0x23
325
int    r1 = 0x207E
326
call   print_result
327
 
328
// Test format 2.9 A
329
T29A:
330
int64  r2 = insert_hi(r20, 0xABBA)
331
int64  r3 = r2 + (0xCDDEF << 36)
332
int64  r4 = (A | 0xABBA << 32) + (0xCDDEF << 36)
333
int32  r0 = r3 == r4
334
int    r1 = 0x29A
335
call   print_result
336
 
337
 
338
int64 r0 = address [jumpformat]
339
call _printf
340
 
341
 
342
// Test format 1.6 B
343
T16B:
344
int    r1 = 1
345
int    r2 = 2
346
if (int32 r1 < r2) {int r3 = 5}
347
if (int32 r1 == r2) {int r3 = 6}
348
int32  r0 = r3 == 5
349
int    r1 = 0x16B
350
call   print_result
351
 
352
// Test format 1.7 C
353
T17C:
354
if (int32 r1 == 9) {int r3 = 7}
355
else {int r3 = 8}
356
int32  r0 = r3 == 8
357
int    r1 = 0x17C
358
call   print_result
359
 
360
// Test format 2.5.0 A
361
T250A:
362
int32  r3 = r20 + r21, jump_nzero T250A_2
363
int    r3 = 0
364
T250A_2:
365
int32  r0 = r3 == (A + B & 0xFFFFFFFF)
366
int    r1 = 0x250A
367
call   print_result
368
 
369
// Test format 2.5.1 B
370
T251B:
371
int32  r3 = r20 + 0x1000, jump_nzero T251B_2
372
int    r3 = 0
373
T251B_2:
374
int32  r0 = r3 == A + 0x1000
375
int    r1 = 0x251B
376
call   print_result
377
 
378
// Test format 2.5.2 B
379
options codesize = 1 << 16
380
T252B:
381
int    r3 = 0x200
382
int32  r3 += [T1], jump_nzero T252B_2
383
int    r3 = 0
384
T252B_2:
385
int32  r0 = r3 == T + 0x200
386
int    r1 = 0x252B
387
call   print_result
388
 
389
// Test format 2.5.4 C
390
options codesize = 1 << 30
391
T254C:
392
int64  r10 = address [T254C_2]
393
if (int32 r20 != 1) {jump TARGET1}
394
int    r3 = 0
395
T254C_2:
396
int32  r0 = r3 == 0x55
397
int    r1 = 0x254C
398
options codesize = 0
399
call   print_result
400
 
401
// Test format 2.5.5 C
402
T255C:
403
int32  r3 = r21
404
if (int32 r20 > A-1) {jump T255C_2}
405
int32  r3 = 0
406
T255C_2:
407
int32  r0 = r3 == r21
408
int    r1 = 0x255C
409
call   print_result
410
 
411
// Test format 2.5.7 C
412
// system call not implemented yet
413
 
414
// Test format 3.1.0 A
415
T310A:
416
int64  r10 = address [T310A_2]
417
int32  r1 = [T1]
418
if (int32 r1 == [T1]) {jump TARGET1}
419
int    r10 = 0
420
T310A_2:
421
int32  r0 = r10 != 0
422
int    r1 = 0x310A
423
call   print_result
424
 
425
// Test format 3.1.1 A
426
T311A:
427
int64  r10 = address [T311A_2]
428
if (int32 r20 == A) {jump TARGET1}
429
int    r10 = 0
430
T311A_2:
431
int32  r0 = r10 != 0
432
int    r1 = 0x311A
433
call   print_result
434
 
435
 
436
int64 r0 = address [newline]
437
call _printf
438
 
439
breakpoint
440
 
441
int r0 = 0                                       // program return value
442
return                                           // return from main
443
 
444
_main end
445
 
446
 
447
print_result function
448
// Print the result of a single test. Parameters:
449
// r0:  1 if success
450
// r1:  format as hexadecimal digits. e.g. 0x204E means format 2.0.4 E
451
 
452
// allocate space for temporary string and parameter list
453
int64 sp -= 64               // allocate space on stack
454
int    r7 = r1
455
int    r6 = 'N'
456
int    r6 = 'Y', mask = r0, fallback = r6
457
 
458
// find length of format name
459
int    r5 = 8
460
int    r3 = r1 >= 0x1000
461
int    r5 += 4, mask = r3
462
int64  r4 = sp + 16           // string buffer
463
 
464
// loop through characters in format name
465
for (int ; r5 >= 0; r5 -= 4) {
466
  // set up parameter list for sprintf
467
  uint32 r0 = r7 >> r5         // character
468
  int    r0 &= 0x0F
469
  int64  [sp] = r0             // part of format name
470
  int    r1 = ' '
471
  int    r3 = r5 > 4
472
  int    r1 = r3 ? '.' : r1    // dot or space after character
473
  int64  [sp+8] = r1           // character
474
  int64  r0 = r4               // string buffer
475
  int64  r1 = address [format1]// format string
476
  int64  r2 = sp               // parameter list
477
  call   _sprintf              // put part of format name in string buffer
478
  int64  r4 += 2               // advance string buffer pointer
479
}
480
 
481
// set up parameter list for printf
482
int64  r4 = sp + 16          // string buffer
483
int64  [sp] = r4             // format name
484
int64  [sp+8] = r6           // 'Y' if success
485
int64  r0 = address [format2]// format string
486
int64  r1 = sp               // parameter list
487
call   _printf               // write to stdout
488
 
489
int64 sp += 64               // free stack space
490
return
491
 
492
print_result end
493
 
494
code1  end
495
 
496
 
497
// second code section for long distance jumps
498
code2 section execute
499
 
500
TARGET1:
501
int    r3 = 0x55
502
int64  jump r10
503
 
504
code2  end

powered by: WebSVN 2.1.0

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