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

Subversion Repositories forwardcom

[/] [forwardcom/] [testsuite/] [tests_branch.as] - Blame information for rev 166

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

Line No. Rev Author Line
1 162 Agner
/**************************  tests_branch.as  *******************************
2
* Author:        Agner Fog
3
* date created:  2021-07-07
4
* last modified: 2021-07-20
5
* Version:       1.11
6
* Project:       ForwardCom Test suite, assembly code
7
* Description:   Test jump, call, and branch instructions with general
8
*                purpose registers
9
*
10
* This test program will test jump, call, and branch instructions and
11
* output a list of which instructions are working for int8, int16, int32,
12
* and int64 operands.
13
*
14
* Copyright 2021 GNU General Public License v.3 http://www.gnu.org/licenses
15
******************************************************************************/
16
 
17
// Library functions in libc_light.li
18
extern _puts:     function reguse=3,0            // write string + linefeed to stdout
19
extern _printf:   function reguse=0xF,0          // write formatted string to stdout
20
 
21
const section read ip                            // read-only data section
22
// Text strings:
23
 
24
text1: int8 "\nForwardCom test suite\nTest jump, call, and branch instructions"  // intro text,
25
       int8 "\nPress Run to continue"
26
       int8 "\n                          int8   int16  int32  int64", 0          // and heading
27
newline: int8 "\n", 0                                                            // newline
28
press_run: int8 "\nPress Run to continue", 0
29
 
30
format1: int8 "\n%-26s%3c%7c%7c%7c", 0           // format string for printing results
31
 
32
// text strings for each instruction:
33
text_sub_jz:              int8 "sub/jump_zero", 0
34
text_sub_jneg:            int8 "sub/jump_neg", 0
35
text_sub_jpos:            int8 "sub/jump_pos", 0
36
text_sub_joverfl:         int8 "sub/jump_overfl", 0
37
text_sub_jborrow:         int8 "sub/jump_borrow", 0
38
 
39
text_add_jz:              int8 "add/jump_zero", 0
40
text_add_jneg:            int8 "add/jump_neg", 0
41
text_add_jpos:            int8 "add/jump_pos", 0
42
text_add_joverfl:         int8 "add/jump_overfl", 0
43
text_add_jcarry:          int8 "add/jump_carry", 0
44
 
45
text_and_jz:              int8 "and/jump_zero", 0
46
text_or_jz:               int8 "or /jump_zero", 0
47
text_xor_jz:              int8 "xor/jump_zero", 0
48
 
49
text_test_bit_jtrue:      int8 "test_bit/jump_true", 0
50
text_test_bits_and_jtrue: int8 "test_bits_and/jump_true", 0
51
text_test_bits_or_jtrue:  int8 "test_bits_or/jump_true", 0
52
 
53
text_compare_jequal:      int8 "compare/jump_equal", 0
54
text_compare_jsbelow:     int8 "compare/jump_sbelow", 0
55
text_compare_jsabove:     int8 "compare/jump_sabove", 0
56
text_compare_jubelow:     int8 "compare/jump_ubelow", 0
57
text_compare_juabove:     int8 "compare/jump_uabove", 0
58
 
59
text_inc_compare_jbelow:  int8 "increment_compare/j_below", 0
60
text_inc_compare_jabove:  int8 "increment_compare/j_above", 0
61
text_sub_maxlen_jpos:     int8 "sub_maxlen/jump_pos", 0
62
 
63
text_jump_relative:       int8 "jump_relative pointer", 0
64
text_call_relative:       int8 "call_relative pointer", 0
65
text_jump_relative_table: int8 "jump_relative table", 0
66
text_call_relative_table: int8 "call_relative table", 0
67
 
68
text_jump_absolute:       int8 "jump absolute pointer", 0
69
text_call_absolute:       int8 "call absolute pointer", 0
70
text_jump_register:       int8 "jump to register", 0
71
text_call_register:       int8 "call to register", 0
72
text_jump_32:             int8 "jump 32 bit offset", 0
73
text_call_32:             int8 "call 32 bit offset", 0
74
 
75
// not supported:
76
//text_jump_64:           int8 "jump 64 bit absolute", 0
77
//text_call_64:           int8 "call 64 bit absolute", 0
78
 
79
// relative jump tables
80
jumptab8:  int8  (TARGET1-TARGET3)/4, (TARGET2-TARGET3)/4, 0, (TARGET4-TARGET3)/4, (TARGET5-TARGET3)/4, 0
81
jumptab16: int16 (TARGET1-TARGET3)/4, (TARGET2-TARGET3)/4, 0, (TARGET4-TARGET3)/4, (TARGET5-TARGET3)/4, 0
82
jumptab32: int32 (TARGET1-TARGET3)/4, (TARGET2-TARGET3)/4, 0, (TARGET4-TARGET3)/4, (TARGET5-TARGET3)/4, 0
83
jumptab64: int64 (TARGET1-TARGET3)/4, (TARGET2-TARGET3)/4, 0, (TARGET4-TARGET3)/4, (TARGET5-TARGET3)/4, 0
84
 
85
const end
86
 
87
 
88
code1 section execute                            // code section
89
 
90
__entry_point function public                    // skip startup code
91
_main function public
92
 
93
/* register use:
94
r0:  bits indicating success for int8, int16, int32, int64
95
r1:  operand
96
r2:  operand
97
r3:  result
98
r4:  scratch
99
r6:  int64 supported
100
r20: return address when testing jump
101
*/
102
 
103
// print intro text and heading
104
int64  r0 = address [text1]                      // address of string
105
//call   _puts                                   // print string and linefeed
106
call   _printf                                   // print string without linefeed
107
 
108
breakpoint                                       // debug breakpoint
109
 
110
int    r1 = 1
111
int    capab2 = write_capabilities(r1, 0)        // disable error trap for unknown instructions
112
 
113
// Test of each instruction:
114
 
115
// Test sub/jump_zero
116
int    r1 = 1
117
int    r0 = 1
118
int8   r2 = sub(r1,1), jump_zero A1
119
int    r0 = 0
120
A1:
121
int16  r3 = sub(r2,1), jump_zero A2
122
int32  r4 = r3 == 0xFFFF
123
int    r0 |= 2, mask = r4
124
       jump   A3
125
A2:    int r0 = 0
126
A3:
127
int32  r3 = sub(r3,0xFFFF), jump_zero A4
128
       jump  A5
129
A4:    int r0 |= 4
130
A5:
131
int64  r4 = sub(r0,7), jump_nzero A8
132
int64  r1 = r0 | 1 << 60
133
int64  r4 = sub(r1,7), jump_zero A8
134
int    r0 |= 8
135
A8:
136
int64  r1 = address [text_sub_jz]
137
call   print_result
138
 
139
 
140
// Test sub/jump_neg
141
int    r1 = 0x100
142
int8   r3 = sub(r1,1), jump_neg A10
143
int    r0 = 0
144
       jump A11
145
A10:   int r0 = 1
146
A11:
147
int16  r3 = sub(r3,r3), jump_neg A12
148
int    r0 |= 2
149
       jump A13
150
A12:   int r0 = 0
151
A13:
152
int32  r2 = -8      // sub(r3,-8) would be converted to add(r3,8)
153
int32  r3 = sub(r3, r2), jump_nneg A14
154
       jump A15
155
A14:   int r4 = r3 == 8
156
       int r0 |= 4, mask = r4
157
A15:
158
int64  r2 = 9
159
int64  r4 = sub(r3,r2), jump_nneg A16
160
int64  r5 = r4 == -1
161
int64  r3 |= 1 << 62
162
int64  r4 = sub(r3,r2), jump_neg A16
163
int    r0 |= 8, mask = r5
164
A16:
165
int64  r1 = address [text_sub_jneg]
166
call   print_result
167
 
168
 
169
// Test sub/jump_pos
170
int    r1 = 1
171
int    r2 = 0x100
172
int8   r3 = sub(r2,r1), jump_pos A30
173
int    r0 = r3 == 0xFF
174
       jump A31
175
A30:   int r0 = 0
176
A31:
177
int16  r3 = sub(r1,r3), jump_pos A32
178
int    r4 = r3 == 0xFF02
179
int    r0 |= 2, mask = r4
180
jump   A33
181
A32:   int r0 = 0
182
A33:
183
int32  r3 = sub(r2,r2), jump_npos A34
184
int    r0 = 0
185
jump   A35
186
A34:   int r4 = r3 == 0
187
       int r0 |= 4, mask = r4
188
A35:
189
int64  r1 |= 1 << 62
190
int64  r3 = sub(r1,r2), jump_npos A36
191
int    r0 |= 8
192
A36:
193
int64  r1 = address [text_sub_jpos]
194
call   print_result
195
 
196
 
197
// Test sub/jump_overflow
198
int    r1 = 0xA0
199
int    r2 = 0x21
200
int8   r3 = sub(r1,r2), jump_overfl A40
201
int    r0 = 0
202
jump   A41
203
A40:   int r0 = 1
204
A41:
205
int    r1 = 0xA000
206
int    r2 = 0x2000
207
int16  r3 = sub(r1,r2), jump_overfl A42
208
int    r0 |= 2
209
jump   A43
210
A42:   int r0 = 0
211
A43:
212
int32  r1 = 0x50000000
213
int32  r2 = 0xD0000000
214
int32  r3 = sub(r1,r2), jump_overfl A44
215
int    r0 = 0
216
jump   A45
217
A44:   int r0 |= 4
218
A45:
219
int64  r3 = sub(r1,r2), jump_noverfl A46
220
jump   A47
221
A46:   int64 r4 = r3 == 0xFFFFFFFF80000000
222
       int r0 |= 8, mask = r4
223
A47:
224
int64  r1 = address [text_sub_joverfl]
225
call   print_result
226
 
227
 
228
// Test sub/jump_borrow
229
int    r1 = 0x1280
230
int    r2 = 0x1281
231
int8   r3 = sub(r1,r2), jump_borrow A50
232
int    r0 = 0
233
jump   A51
234
A50:   int r0 = 1
235
A51:
236
int16  r3 = sub(r1,r2), jump_nborrow A52
237
int32  r4 = r3 == 0x0000FFFF
238
int    r0 |= 2, mask = r4
239
A52:
240
int32  r3 = sub(r1,r2), jump_nborrow A54
241
int64  r4 = r3 == 0x0000FFFFFFFF
242
int    r0 |= 4, mask = r4
243
A54:
244
int64  r1 |= 1 << 60
245
int64  r3 = sub(r2,r1), jump_nborrow A56
246
int    r0 |= 8
247
A56:
248
int64  r1 = address [text_sub_jborrow]
249
call   print_result
250
 
251
 
252
// Test add/jump_zero
253
int    r1 = 0x1271
254
int    r2 = 0x128F
255
int8   r3 = add(r1,r2), jump_zero B0
256
int    r0 = 0
257
jump   B1
258
B0:    int r0 = 1
259
B1:
260
int16  r3 = add(r1,r2), jump_zero B2
261
int    r0 |= 2
262
B2:
263
int32  r2 = -0x1271
264
int32  r3 = add(r1,r2), jump_nzero B4
265
int    r0 |= 4
266
B4:
267
int64  r3 = add(r1,r2), jump_zero B6
268
int    r0 |= 8
269
B6:
270
int64  r1 = address [text_add_jz]
271
call   print_result
272
 
273
 
274
// Test add/jump_neg
275
int    r1 = 0x1261
276
int    r2 = 0x1220
277
int8   r3 = add(r1,r2), jump_neg B10
278
int    r0 = 0
279
jump   B11
280
B10:   int r0 = 1
281
B11:
282
int16  r3 = add(r1,r2), jump_neg B12
283
int    r0 |= 2
284
B12:
285
int32  r2 = -0x1262
286
int32  r3 = add(r1,r2), jump_nneg B14
287
int    r0 |= 4
288
B14:
289
int64  r3 = add(r1,r2), jump_neg B16
290
int    r0 |= 8
291
B16:
292
int64  r1 = address [text_add_jneg]
293
call   print_result
294
 
295
 
296
// Test add/jump_pos
297
int    r1 = 0x1261
298
int    r2 = 0x1220
299
int8   r3 = add(r1,r2), jump_npos B20
300
int    r0 = 0
301
jump   B21
302
B20:   int r0 = r3 == 0x81
303
B21:
304
int32  r2 = -r1
305
int16  r3 = add(r1,r2), jump_pos B22
306
int32  r4 = r3 == 0
307
int    r0 |= 2, mask = r4
308
B22:
309
int32  r3 = add(r2,0), jump_pos B24
310
int    r0 |= 4
311
B24:
312
int64  r3 = add(r1,r2), jump_npos B26
313
int64  r4 = r3 == 1 << 32
314
int    r0 |= 8, mask = r4
315
B26:
316
int64  r1 = address [text_add_jpos]
317
call   print_result
318
 
319
 
320
// Test add/jump_overfl
321
int32  r1 = 0x1261
322
int32  r2 = 0x1220
323
int8   r3 = add(r1,r2), jump_overfl B30
324
int    r0 = 0
325
jump   B31
326
B30:   int r0 = 1
327
B31:
328
int16  r3 = add(r1,r2), jump_overfl B32
329
int    r0 |= 2
330
B32:
331
int32  r2 = 0x7FFFF000
332
int32  r3 = add(r1,r2), jump_noverfl B34
333
int    r0 |= 4
334
B34:
335
int64  r3 = add(r1,r2), jump_overfl B36
336
int    r0 |= 8
337
B36:
338
int64  r1 = address [text_add_joverfl]
339
call   print_result
340
 
341
 
342
// Test add/jump_carry
343
int32  r1 = 0x1261
344
int32  r2 = 0x1220
345
int8   r3 = add(r1,r2), jump_ncarry B40
346
int    r0 = 0
347
jump   B41
348
B40:   int r0 = 1
349
B41:
350
int16  r3 = add(r1,r2), jump_carry B42
351
int    r0 |= 2
352
B42:
353
int32  r2 = -r1
354
int32  r3 = add(r1,r2), jump_ncarry B44
355
int    r0 |= 4
356
B44:
357
int64  r2 <<= 32
358
int64  r3 = add(r2,r2), jump_ncarry B46
359
int    r0 |= 8
360
B46:
361
int64  r1 = address [text_add_jcarry]
362
call   print_result
363
 
364
 
365
// Test and/jump_zero
366
int32  r1 = 0x0100F055
367
int32  r2 = 0x10AA
368
int8   r3 = and(r1,r2), jump_zero C0
369
int    r0 = 0
370
jump   C1
371
C0:    int r0 = 1
372
C1:
373
int16  r3 = and(r1,r2), jump_zero C2
374
int    r4 = r3 == 0x1000
375
int    r0 |= 2, mask = r4
376
C2:
377
int32  r2 = 0x02220FAA
378
int32  r3 = and(r1,r2), jump_nzero C4
379
int    r0 |= 4
380
C4:
381
int64  r1 |= 1 << 60
382
int64  r2 |= 1 << 60
383
int64  r3 = and(r1,r2), jump_zero C6
384
int64  r4 = r3 == 1 << 60
385
int    r0 |= 8, mask = r4
386
C6:
387
int64  r1 = address [text_and_jz]
388
call   print_result
389
 
390
 
391
// Test or/jump_zero
392
int32  r1 = 0xF055
393
int32  r2 = 0x0FAA
394
int8   r3 = or(r1,r2), jump_zero C10
395
int    r0 = r3 == 0xFF
396
jump   C11
397
C10:   int r0 = 0
398
C11:
399
int    r1 = 0
400
int    r2 = 0
401
int16  r3 = or(r1,r2), jump_nzero C12
402
int    r0 |= 2
403
C12:
404
int32  r1 = 1 << 31
405
int32  r3 = or(r1,r2), jump_zero C14
406
int32  r4 = r3 == 1 << 31
407
int    r0 |= 4, mask = r4
408
C14:
409
int64  r1 = 1 << 32
410
int64  r3 = or(r1,r2), jump_zero C16
411
int64  r4 = r3 == 1 << 32
412
int    r0 |= 8, mask = r4
413
C16:
414
int64  r1 = address [text_or_jz]
415
call   print_result
416
 
417
 
418
// Test xor/jump_zero
419
int32  r1 = 0xF055
420
int32  r2 = r1
421
int8   r3 = xor(r1,r2), jump_zero C20
422
int    r0 = 0
423
jump   C21
424
C20:   int r0 = 1
425
C21:
426
int    r2 = 0
427
int16  r3 = xor(r1,r2), jump_zero C22
428
int32  r4 = r3 == r1
429
int    r0 |= 2, mask = r4
430
C22:
431
int32  r1 = -r1
432
int32  r2 = r1
433
int32  r3 = xor(r1,r2), jump_nzero C24
434
int    r0 |= 4
435
C24:
436
int64  r1 |= 1 << 63
437
int64  r3 = xor(r1,r2), jump_zero C26
438
int    r0 |= 8
439
C26:
440
int64  r1 = address [text_xor_jz]
441
call   print_result
442
 
443
 
444
// Test test_bit/jump_true
445
int32  r1 = 0x12345678
446
int8   test_bit(r1,4), jump_true E0
447
int    r0 = 0
448
jump   E1
449
E0:    int r0 = 1
450
E1:
451
int16  test_bit(r1,8), jump_true E2
452
int    r0 |= 2
453
E2:
454
int32  test_bit(r1,21), jump_false E4
455
int    r0 |= 4
456
E4:
457
int64  test_bit(r1,33), jump_true E6
458
int64  r1 |= 1 << 33
459
int64  test_bit(r1,33), jump_false E6
460
int    r0 |= 8
461
E6:
462
int64  r1 = address [text_test_bit_jtrue]
463
call   print_result
464
 
465
 
466
// Test test_bits_and/jump_true
467
int32  r1 = 0x12345678
468
int32  r2 = 0x2670
469
int8   test_bits_and(r1,r2), jump_true E10
470
int    r0 = 0
471
jump   E11
472
E10:   int r0 = 1
473
E11:
474
int16  test_bits_and(r1,r2), jump_true E12
475
int    r0 |= 2
476
E12:
477
int32  test_bits_and(r1,r1), jump_false E14
478
int    r0 |= 4
479
E14:
480
int64  r2 = r1 | 1 << 50
481
int64  test_bits_and(r1,r2), jump_true E16
482
int    r0 |= 8
483
E16:
484
int64  r1 = address [text_test_bits_and_jtrue]
485
call   print_result
486
 
487
 
488
// Test test_bits_or/jump_true
489
int32  r1 = 0x12345678
490
int32  r2 = 0xC0
491
int8   test_bits_or(r1,r2), jump_false E20
492
int    r0 = 1
493
jump   E21
494
E20:   int r0 = 0
495
E21:
496
int16  test_bits_or(r1,0x1001), jump_false E22
497
int    r0 |= 2
498
E22:
499
int32  test_bits_or(r2,0x1001), jump_true E24
500
int    r0 |= 4
501
E24:
502
int32  r2 = r1 ^ -1
503
int64  test_bits_or(r2,r1), jump_false E26
504
int    r0 &= ~ 4
505
E26:
506
int64  r1 |= 1 << 60
507
int64  r2 |= 1 << 60
508
int64  test_bits_or(r2,r1), jump_false E28
509
int    r0 |= 8
510
E28:
511
int64  r1 = address [text_test_bits_or_jtrue]
512
call   print_result
513
 
514
 
515
int64  r0 = address [press_run]                  // press run to continue
516
call   _printf                                   // print string
517
 
518
breakpoint
519
 
520
 
521
// Test compare/jump_equal
522
int32  r1 = 0x222212AB
523
int32  r2 = 0x222213AB
524
int8   compare(r1,r2), jump_equal F0
525
int    r0 = 0
526
jump   F1
527
F0:    int r0 = 1
528
F1:
529
int16  compare(r1,r2), jump_equal F2
530
int    r0 |= 2
531
F2:
532
int32  r2 &= ~0x100
533
int32  compare(r1,r2), jump_nequal F4
534
int    r0 |= 4
535
F4:
536
int64  r1 ^= 1 << 60
537
int64  compare(r1,r2), jump_equal F6
538
int    r0 |= 8
539
F6:
540
int64  r1 = address [text_compare_jequal]
541
call   print_result
542
 
543
 
544
// Test compare/jump_sbelow
545
int    r1 = 0x1111997F
546
int    r2 = 0x22228880
547
int8   compare(r1,r2), jump_sbelow F10
548
int    r0 = 1
549
jump   F11
550
F10:   int r0 = 0
551
F11:
552
int16  compare(r1,r2), jump_sbelow F12
553
int    r0 |= 2
554
F12:
555
int32  compare(r1,r2), jump_saboveeq F14
556
int    r0 |= 4
557
F14:
558
int64  r2 |= 1 << 63
559
int64  compare(r1,r2), jump_sbelow F16
560
int    r0 |= 8
561
F16:
562
int64  r1 = address [text_compare_jsbelow]
563
call   print_result
564
 
565
 
566
// Test compare/jump_sabove
567
int    r1 = 0x1111997F
568
int    r2 = 0x22228880
569
int8   compare(r1,r2), jump_sbeloweq F20
570
int    r0 = 1
571
jump   F21
572
F20:   int r0 = 0
573
F21:
574
int16  compare(r1,r2), jump_sbeloweq F22
575
int    r0 |= 2
576
F22:
577
int32  compare(r1,r2), jump_sabove F24
578
int    r0 |= 4
579
F24:
580
int32  compare(r1,r1), jump_sbeloweq F25
581
int    r0 &= ~ 4
582
F25:
583
int64  r2 |= 1 << 63
584
int64  compare(r1,r2), jump_sbeloweq F26
585
int    r0 |= 8
586
F26:
587
int64  r1 = address [text_compare_jsabove]
588
call   print_result
589
 
590
 
591
// Test compare/jump_ubelow
592
int    r1 = 0x1111997F
593
int    r2 = 0x22228880
594
int8   compare(r1,r2), jump_ubelow F30
595
int    r0 = 0
596
jump   F31
597
F30:   int r0 = 1
598
F31:
599
int16  compare(r1,r2), jump_ubelow F32
600
int    r0 |= 2
601
F32:
602
int32  compare(r1,r2), jump_uaboveeq F34
603
int    r0 |= 4
604
F34:
605
int32  compare(r1,r1), jump_uaboveeq F35
606
int    r0 &= ~ 4
607
F35:
608
int64  compare(r1,r2), jump_uaboveeq F36
609
int64  r1 |= 1 << 63
610
int64  compare(r1,r2), jump_ubelow F36
611
int    r0 |= 8
612
F36:
613
int64  r1 = address [text_compare_jubelow]
614
call   print_result
615
 
616
 
617
// Test compare/jump_uabove
618
int    r1 = 0x1111997F
619
int    r2 = 0x22228880
620
int8   compare(r1,r2), jump_ubeloweq F40
621
int    r0 = 0
622
jump   F41
623
F40:   int r0 = 1
624
F41:
625
int16  compare(r1,r2), jump_ubeloweq F42
626
int    r0 |= 2
627
F42:
628
int32  compare(r1,r2), jump_uabove F44
629
int    r0 |= 4
630
F44:
631
int32  compare(r1,r1), jump_ubeloweq F45
632
int    r0 &= ~ 4
633
F45:
634
int64  compare(r1,r2), jump_uabove F46
635
int64  r1 |= 1 << 63
636
int64  compare(r1,r2), jump_ubeloweq F46
637
int    r0 |= 8
638
F46:
639
int64  r1 = address [text_compare_juabove]
640
call   print_result
641
 
642
 
643
// Test inc_compare/jump_below
644
int    r2 = 0
645
for (int8 r1 = 0; r1 < 5; r1++) {
646
    int r2++
647
}
648
int    r0 = r2 == 5
649
for (int16 r1 = 0x7000; r1 < 0x7005; r1++) {
650
    int r2++
651
}
652
int    r4 = r2 == 10
653
int    r0 |= 2, mask = r4
654
 
655
for (int32 r1 = -2; r1 < 3; r1++) {
656
    int r2++
657
}
658
int32  r4 = r2 == 15
659
int    r0 |= 4, mask = r4
660
int32  r1 = 0x7FFFFFFE
661
int64  r3 = r1 + 5
662
for (int64 ; r1 < r3; r1++) {
663
    int r2++
664
}
665
int32  r4 = r2 == 20
666
int    r0 |= 8, mask = r4
667
int64  r1 = address [text_inc_compare_jbelow]
668
call   print_result
669
 
670
 
671
// Test inc_compare/jump_above
672
int    r2 = 0
673
for (int8 r1 = 0; r1 <= 5; r1++) {
674
    int r2++
675
}
676
int    r0 = r2 == 6
677
int    r3 = 0x7005
678
for (int16 r1 = 0x7000; r1 <= r3; r1++) {
679
    int r2++
680
}
681
int    r4 = r2 == 12
682
int    r0 |= 2, mask = r4
683
 
684
for (int32 r1 = -2; r1 <= 3; r1++) {
685
    int r2++
686
}
687
int32  r4 = r2 == 18
688
int    r0 |= 4, mask = r4
689
int32  r1 = 0x7FFFFFFE
690
int64  r3 = r1 + 5
691
for (int64 ; r1 <= r3; r1++) {
692
    int r2++
693
}
694
int32  r4 = r2 == 24
695
int    r0 |= 8, mask = r4
696
int64  r1 = address [text_inc_compare_jabove]
697
call   print_result
698
 
699
 
700
// Test sub_maxlen/jump_pos
701
// get max vector length without using vectors:
702
int    r6 = 0
703
int64  r6 = sub_maxlen(r6, 3), jump_pos H1
704
int    r6 = - r6                                 // max vector length
705
int    r2 = 0
706
H1:    int r0 = 0
707
if (int r6 > 0) {                                // avoid infinite loops if maxlen = 0
708
  // test all operand sizes for completeness, even though only int64 is used. int8 is likely to overflow
709
  int   r1 = 4
710
  H10:  int r2++
711
  int8  r1 = sub_maxlen(r1, 3), jump_pos H10
712
  int   r0 = r2 == 1
713
 
714
  int   r1 = r6 << 2
715
  int   r2 = 0
716
  H20:  int r2++
717
  int16 r1 = sub_maxlen(r1, 3), jump_pos H20
718
  int   r4 = r2 == 4
719
  int   r0 |= 2, mask = r4
720
 
721
  int   r1 = r6 << 2
722
  int   r1 += 4
723
  int   r2 = 0
724
  H30:  int r2++
725
  int32 r1 = sub_maxlen(r1, 3), jump_pos H30
726
  int   r4 = r2 == 5
727
  int   r0 |= 4, mask = r4
728
 
729
  int64 r3 = 1 << 60
730
  int64 r1 = sub_maxlen(r1, 3), jump_npos H42
731
  int   r1 = r6 << 2
732
  int   r1 += 4
733
  int   r2 = 0
734
  H40:  int r2++
735
  int64 r1 = sub_maxlen(r1, 3), jump_pos H40
736
  int   r4 = r2 == 5
737
  int   r0 |= 8, mask = r4
738
  H42:
739
}
740
int64  r1 = address [text_sub_maxlen_jpos]
741
call   print_result
742
 
743
 
744
// Test jump to relative pointer in memory
745
int    r1 = 0
746
int64  r10 = address [TARGET3]
747
int64  r11 = address [jumptab8]
748
int64  r20 = address [K00]
749
int8   jump_relative(r10,[r11])
750
K00:   int r0 = r3 == 1
751
 
752
int64  r20 = address [K10]
753
int16  jump_relative(r10,[jumptab16+4])
754
K10:   int r4 = r3 == 3
755
int    r0 |= 2, mask = r4
756
 
757
int64  r20 = address [K20]
758
int32  jump_relative(r10,[jumptab32+4])
759
K20:   int r4 = r3 == 2
760
int    r0 |= 4, mask = r4
761
 
762
int64  r20 = address [K30]
763
int64  r11 = address [jumptab64]
764
int64  jump_relative(r10,[r11+24])
765
K30:   int r4 = r3 == 4
766
int    r0 |= 8, mask = r4
767
 
768
int64  r1 = address [text_jump_relative]
769
call   print_result
770
 
771
 
772
// Test call to relative pointer in memory
773
int    r1 = 0
774
int64  r20 = address [TARGETRETURN]
775
int64  r11 = address [jumptab8]
776
int8   call_relative(r10,[r11])
777
int r0 = r3 == 1
778
 
779
int16  call_relative(r10,[jumptab16+4])
780
int    r4 = r3 == 3
781
int    r0 |= 2, mask = r4
782
 
783
int32  call_relative(r10,[jumptab32+4])
784
int    r4 = r3 == 2
785
int    r0 |= 4, mask = r4
786
 
787
int64  r11 = address [jumptab64]
788
int64  call_relative(r10,[r11+24])
789
int r4 = r3 == 4
790
int    r0 |= 8, mask = r4
791
 
792
int64  r1 = address [text_call_relative]
793
call   print_result
794
 
795
 
796
// Test jump to relative table in memory
797
int    r1 = 0
798
int64  r10 = address [TARGET3]
799
int64  r11 = address [jumptab8]
800
int64  r20 = address [L00]
801
int8   jump_relative(r10,[r11+r1])
802
L00:   int r4 = r3
803
int    r1 = 1
804
int64  r20 = address [L01]
805
int8   jump_relative(r10,[r11+r1])
806
L01:   int r4 <<= 4
807
       int r4 |= r3
808
int    r1 = 4
809
int64  r20 = address [L02]
810
int8   jump_relative(r10,[r11+r1])
811
L02:   int r4 <<= 4
812
int    r4 |= r3
813
int    r0 = r4 == 0x125
814
 
815
int    r1 = 2
816
int64  r11 = address [jumptab16]
817
int64  r20 = address [L10]
818
int16  jump_relative(r10,[r11+r1*2])
819
L10:   int r4 = r3
820
int    r1 = 1
821
int64  r20 = address [L11]
822
int16  jump_relative(r10,[r11+r1*2])
823
L11:   int r4 <<= 4
824
       int r4 |= r3
825
int    r1 = 3
826
int64  r20 = address [L12]
827
int16  jump_relative(r10,[r11+r1*2])
828
L12:   int r4 <<= 4
829
int    r4 |= r3
830
int    r4 = r4 == 0x324
831
int    r0 |= 2, mask = r4
832
 
833
int    r1 = 4
834
int64  r11 = address [jumptab32]
835
int64  r20 = address [L20]
836
int32  jump_relative(r10,[r11+r1*4])
837
L20:   int r4 = r3
838
int    r1 = 2
839
int64  r20 = address [L21]
840
int32  jump_relative(r10,[r11+r1*4])
841
L21:   int r4 <<= 4
842
       int r4 |= r3
843
int    r1 = 3
844
int64  r20 = address [L22]
845
int32  jump_relative(r10,[r11+r1*4])
846
L22:   int r4 <<= 4
847
int    r4 |= r3
848
int    r4 = r4 == 0x534
849
int    r0 |= 4, mask = r4
850
 
851
int    r1 = 0
852
int64  r11 = address [jumptab64]
853
int64  r20 = address [L30]
854
int64  jump_relative(r10,[r11+r1*8])
855
L30:   int r4 = r3
856
int    r1 = 4
857
int64  r20 = address [L31]
858
int64  jump_relative(r10,[r11+r1*8])
859
L31:   int r4 <<= 4
860
       int r4 |= r3
861
int    r1 = 2
862
int64  r20 = address [L32]
863
int64  jump_relative(r10,[r11+r1*8])
864
L32:   int r4 <<= 4
865
int    r4 |= r3
866
int    r4 = r4 == 0x153
867
int    r0 |= 8, mask = r4
868
 
869
int64  r1 = address [text_jump_relative_table]
870
call   print_result
871
 
872
 
873
// Test call to relative table in memory
874
int    r1 = 2
875
int64  r10 = address [TARGET3]
876
int64  r11 = address [jumptab8]
877
int64  r20 = address [TARGETRETURN]
878
int8   call_relative(r10,[r11+r1])
879
int    r4 = r3
880
int    r1 = 4
881
int8   call_relative(r10,[r11+r1])
882
int    r4 <<= 4
883
int    r4 |= r3
884
int    r1 = 3
885
int8   call_relative(r10,[r11+r1])
886
int    r4 <<= 4
887
int    r4 |= r3
888
int    r0 = r4 == 0x354
889
 
890
int64  r11 = address [jumptab16]
891
int    r1 = 2
892
int16  call_relative(r10,[r11+r1*2])
893
int    r4 = r3
894
int    r1 = 0
895
int16  call_relative(r10,[r11+r1*2])
896
int    r4 <<= 4
897
int    r4 |= r3
898
int    r1 = 4
899
int16  call_relative(r10,[r11+r1*2])
900
int    r4 <<= 4
901
int    r4 |= r3
902
int    r4 = r4 == 0x315
903
int    r0 |= 2, mask = r4
904
 
905
int64  r11 = address [jumptab32]
906
int    r1 = 4
907
int32  call_relative(r10,[r11+r1*4])
908
int    r4 = r3
909
int    r1 = 1
910
int32  call_relative(r10,[r11+r1*4])
911
int    r4 <<= 4
912
int    r4 |= r3
913
int    r1 = 2
914
int32  call_relative(r10,[r11+r1*4])
915
int    r4 <<= 4
916
int    r4 |= r3
917
int    r4 = r4 == 0x523
918
int    r0 |= 4, mask = r4
919
 
920
int64  r11 = address [jumptab64]
921
int    r1 = 3
922
int64  call_relative(r10,[r11+r1*8])
923
int    r4 = r3
924
int    r1 = 4
925
int64  call_relative(r10,[r11+r1*8])
926
int    r4 <<= 4
927
int    r4 |= r3
928
int    r1 = 0
929
int64  call_relative(r10,[r11+r1*8])
930
int    r4 <<= 4
931
int    r4 |= r3
932
int    r4 = r4 == 0x451
933
int    r0 |= 8, mask = r4
934
 
935
int64  r1 = address [text_call_relative_table]
936
call   print_result
937
 
938
 
939
// jump/call 24 bit relative need not be tested because we would not have got here if they didn't work
940
// jump/call to register value need not be tested because we would not have got here if they didn't work
941
int    r0 = 0x78
942
int64  r1 = address [text_jump_register]
943
call   print_result
944
int    r0 = 0x78
945
int64  r1 = address [text_call_register]
946
call   print_result
947
 
948
 
949
int64  sp -= 32                                  // allocate space on stack
950
 
951
// test jump absolute address in memory
952
int64  r2 = address [TARGET2]
953
int64  r3 = address [TARGET3]
954
int64  [sp] = r2                                 // put jump target address on stack
955
int64  [sp+8] = r3                               // put jump target address on stack
956
int64  r20 = address [M10]                       // destination for jump back
957
int64  jump ([sp+8])                             // 8 bit offset, format 1.6.1B
958
nop
959
M10:   int r4 = r3 == 3
960
int64  r1 = sp + 0x1000
961
int64  r20 = address [M11]                       // destination for jump back
962
int64  jump ([r1-0x1000])                        // 32 bit offset, format 2.5.2B
963
nop
964
M11:   int r4 = r3 == 2 && r4
965
int    r0 = r4 ? 0x78 : 0
966
 
967
int64  r1 = address [text_jump_absolute]
968
call   print_result
969
 
970
 
971
// test call absolute address in memory
972
int64  r20 = address [TARGETRETURN]
973
int    r3 = 0
974
int64  call ([sp])                               // 8 bit offset, format 1.6.1B
975
int    r4 = r3 == 2
976
int    r0 = r4 ? 0x78 : 0
977
int64  r1 = address [text_call_absolute]
978
call   print_result
979
 
980
 
981
// test jump 32 bit relative
982
options codesize = 1 << 30                       // make sure to use 32-bit jump address
983
int64  r20 = address [M20]
984
int    r3 = 0
985
jump   TARGET4
986
nop
987
M20:
988
int    r4 = r3 == 4
989
int    r0 = r4 ? 0x78 : 0
990
int64  r1 = address [text_jump_32]
991
call   print_result
992
 
993
 
994
// test call 32 bit relative
995
int64  r20 = address [TARGETRETURN]
996
int    r3 = 0
997
call   TARGET3
998
nop
999
int    r4 = r3 == 3
1000
int    r0 = r4 ? 0x78 : 0
1001
int64  r1 = address [text_call_32]
1002
call   print_result
1003
options codesize = 0                             // return to default codesize
1004
 
1005
int64  sp += 32                                  // free allocated space on stack
1006
 
1007
 
1008
int64 r0 = address [newline]
1009
call   _printf                                   // print string
1010
 
1011
 
1012
breakpoint
1013
 
1014
int r0 = 0                                       // program return value
1015
return                                           // return from main
1016
 
1017
_main end
1018
 
1019
 
1020
print_result function
1021
// Print the result of a single test. Parameters:
1022
// r0:  4 bits indicating success for for int8, int16, int32, int64. 4 additional bits for printing space (instruction not supported)
1023
// r1:  pointer to text string
1024
 
1025
// set up parameter list for printf
1026
int64 sp -= 5*8              // allocate space on stack
1027
int64 [sp] = r1              // text
1028
int r4 = 'N'
1029
int r2 = r0 ? 'Y' : r4       // Y or N
1030
int r5 = test_bit(r0, 4)
1031
int r2 = r5 ? ' ' : r2       // Y/N or space
1032
int64 [sp+0x08] = r2         // result for int8
1033
int r0 >>= 1
1034
int r2 = r0 ? 'Y' : r4       // Y or N
1035
int r5 = test_bit(r0, 4)
1036
int r2 = r5 ? ' ' : r2       // Y/N or space
1037
int64 [sp+0x10] = r2         // result for int16
1038
int r0 >>= 1
1039
int r2 = r0 ? 'Y' : r4       // Y or N
1040
int r5 = test_bit(r0, 4)
1041
int r2 = r5 ? ' ' : r2       // Y/N or space
1042
int64 [sp+0x18] = r2         // result for int32
1043
int r0 >>= 1
1044
int r2 = r0 ? 'Y' : r4       // Y or N
1045
int r5 = test_bit(r0, 4)
1046
int r2 = r5 ? ' ' : r2       // Y/N or space
1047
int64 [sp+0x20] = r2         // result for int64
1048
 
1049
int64 r0 = address [format1]
1050
int64 r1 = sp
1051
call _printf
1052
int64 sp += 5*8              // release parameter list
1053
return
1054
 
1055
print_result end
1056
 
1057
/*
1058
(If you add more test outputs here, you need another breakpoint because
1059
 the output buffer is close to full and the screen on RealTerm will be
1060
 full as well.)
1061
*/
1062
 
1063
code1 end
1064
 
1065
 
1066
code2 section execute
1067
// jump targets in a separate section for possible longer jump distance
1068
 
1069
TARGET1: int r3 = 1
1070
jump  r20                    // jump back
1071
 
1072
TARGET2: int r3 = 2
1073
jump  r20                    // jump back
1074
 
1075
TARGET3: int r3 = 3
1076
jump  r20                    // jump back
1077
 
1078
TARGET4: int r3 = 4
1079
jump  r20                    // jump back
1080
 
1081
TARGET5: int r3 = 5
1082
jump  r20                    // jump back
1083
 
1084
TARGETRETURN: nop            // for call/return
1085
return
1086
 
1087
code2 end

powered by: WebSVN 2.1.0

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