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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [bench/] [asm/] [zipdhry.S] - Blame information for rev 43

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

Line No. Rev Author Line
1 41 dgisselq
// Under Verilator:
2
//      DMIPS:          25.57   100 MHz         0.26
3
// For comparison:
4
//      uBlaze:         255     177 MHz         1.44
5
//      LEON3                                   1.4
6
//      NiOS II:        218     185 MHz         1.16
7
//      OpenRisk        250     250 MHz         1.00
8
//      LM32                                    1.14
9
//      ZPU             2.6      50 MHz         0.05
10
//
11
 
12
// #define      NO_LOOP_UNROLLING
13
#define SKIP_SHORT_CIRCUITS
14
        sys.ctr.mtask   equ     0xc0000008
15
// int main(int argc, char **argv) {
16
//      dhrystone();
17
// }
18
entry:
19
        MOV     top_of_stack(PC),uSP
20
        MOV     entry(PC),uR12
21
        ; Store  our tick counter in R1
22
        LDI     sys.ctr.mtask,R1
23
        ; And start with our counter cleared at zero
24
        CLR     R0
25
        STO     R0,(R1)
26
#ifdef  SUPERVISOR_TASK
27
        MOV     __HERE__+3(PC),R0
28
        STO     R0,1(SP)
29
        BRA     dhrystone
30
#else
31
        MOV     dhrystone(PC),uPC
32
        RTU
33
#endif
34
        ; Read the tick counter back out
35
        LOD     (R1),R0
36
        HALT    ; Stop the CPU--We're done!!!!!!!
37
 
38
// typedef      enum { Ident_1, Ident_2, Ident_3, Ident_4, Ident_5 } test_enum;
39
// typedef      enum { false, true } bool;
40
 
41
// typedef      int     Arr_1_Dim[50];
42
// typedef      int     Arr_2_Dim[50][50];
43
#define RECSIZE 35
44
#define NUMBER_OF_RUNS  (512)
45
        ptr_comp                        equ     0
46
        discr                           equ     1
47
        variant.var_1.enum_comp         equ     2
48
        variant.var_1.int_comp          equ     3
49
        variant.var_1.str_comp          equ     4
50
 
51
gbl_arr_1:
52
        fill    50,0
53
gbl_arr_2:
54
        fill    2500,0
55
gbl_ch:
56
        word    0
57
gbl_ch_2:
58
        word    0
59
gbl_bool:
60
        word    0
61
gbl_int:
62
        word    0
63
gbl_ptr:
64
        word    0
65
// Arr_1_Dim    gbl_arr_1;
66
// Arr_2_Dim    gbl_arr_2;
67
// char gbl_ch, gbl_ch_2;
68
// bool gbl_bool;
69
// int  gbl_int;
70
// RECP gbl_ptr;
71
 
72
//char  *lcl_strcpy(char *d, char *s) {
73
//      char    *cpd = d, ch;
74
//
75
//      do{
76
//              *cpd++ = ch = *s++;
77
//      } while(ch);
78
//
79
//}
80
//
81
lcl_strcpy:
82
        ; R0 = d
83
        ; R1 = s
84
        ; R3 = ch
85
#ifdef  NO_LOOP_UNROLLING
86
copy_next_char:
87
        LOD     (R1),R2
88
        STO     R2,(R0)
89
        ADD     1,R0
90
        ADD     1,R1
91
        CMP     0,R2
92
        BNZ     copy_next_char
93
#else
94
copy_next_char:
95
        LOD     (R1),R2
96
        CMP     0,R2
97
        STO     R2,(R0)
98
        BZ      lcl_strcpy_end_of_loop
99
        LOD     1(R1),R2
100
        CMP     0,R2
101
        STO     R2,1(R0)
102
        BZ      lcl_strcpy_end_of_loop
103
        LOD     2(R1),R2
104
        CMP     0,R2
105
        STO     R2,2(R0)
106
        BZ      lcl_strcpy_end_of_loop
107
        LOD     3(R1),R2
108
        CMP     0,R2
109
        STO     R2,3(R0)
110
        BZ      lcl_strcpy_end_of_loop
111
        ADD     4,R0
112
        ADD     4,R1
113
        CMP     0,R2
114
        BNZ     copy_next_char
115
lcl_strcpy_end_of_loop:
116
#endif
117
        RETN
118
 
119
//int   lcl_strcmp(char *s1, char *s2) {
120
//      char    a, b;
121
//      do {
122
//              a = *s1++; b = *s2++;
123
//      } while((a)&&(a==b));
124
//
125
//      return a-b;
126
//}
127
 
128
lcl_strcmp:
129
        SUB     1,SP
130
        STO     R3,1(SP)
131
 
132
strcmp_top_of_loop:
133
#ifdef  NO_LOOP_UNROLLING
134
        LOD     (R0),R2
135
        LOD     (R1),R3                 ; Alternate approach:
136
        ; CMP   R2,R3                   ;       CMP     0,R2
137
        ; BNZ   strcmp_end_loop         ;       BZ      strcmp_end_loop
138
        ; CMP   0,R2                    ;       CMP     R2,R3
139
        ; BZ    strcmp_end_loop         ;       BZ      strcmp_top_of_loop
140
        ; CMP   0,R3                    ;
141
        ; BZ    strcmp_end_loop         ;
142
        ; ADD   1,R0
143
        ; ADD   1,R1
144
        ; BRA   strcmp_top_of_loop
145
        LOD     (R0),R2
146
        LOD     (R1),R3
147
        CMP     0,R2
148
        BZ      strcmp_end_loop
149
        CMP     R2,R3
150
        BZ      strcmp_top_of_loop
151
#else
152
        LOD     (R0),R2
153
        LOD     (R1),R3
154
        CMP     0,R2
155
        BZ      strcmp_end_loop
156
        CMP     R2,R3
157
        BNZ     strcmp_end_loop
158
        LOD     1(R0),R2
159
        LOD     1(R1),R3
160
        CMP     0,R2
161
        BZ      strcmp_end_loop
162
        CMP     R2,R3
163
        BNZ     strcmp_end_loop
164
        LOD     2(R0),R2
165
        LOD     2(R1),R3
166
        CMP     0,R2
167
        BZ      strcmp_end_loop
168
        CMP     R2,R3
169
        BNZ     strcmp_end_loop
170
        LOD     3(R0),R2
171
        LOD     3(R1),R3
172
        CMP     0,R2
173
        BZ      strcmp_end_loop
174
        CMP     R2,R3
175
        BNZ     strcmp_end_loop
176
        ADD     4,R0
177
        ADD     4,R1
178
        BRA     strcmp_top_of_loop
179
#endif
180
 
181
strcmp_end_loop:
182
        SUB     R3,R2
183
        MOV     R2,R0
184
 
185
        LOD     1(SP),R3
186
        ADD     1,SP
187
        RETN
188
 
189
 
190
//test_enum     func_1(char ch_1, char ch_2) {
191
//      char    lcl_ch_1, lcl_ch_2;
192
//
193
//      lcl_ch_1 = ch_1;
194
//      lcl_ch_2 = lcl_ch_1;
195
//      if (lcl_ch_2 != ch_2)
196
//              return 0;
197
//      else {
198
//              gbl_ch = lcl_ch_1;
199
//              return 1;
200
//      }
201
 
202
#ifdef  NO_INLINE
203
func_1:
204
        ; On input,
205
        ; R0 = ch_1
206
        ; R1 = ch_2
207
        ; R2 = available
208
        ; On output, R0 is our return value
209
 
210
        MOV     R0,R2
211
        CMP     R2,R1
212
        CLR.NZ  R0
213
        STO.Z   R2,gbl_ch(R12)
214
        LDILO.Z 1,R0
215
        RETN
216
#endif
217
 
218
//bool  func_2(char *str_1, char *str_2) {
219
//      int     lcl_int;
220
//      char    lcl_ch;
221
//
222
//      lcl_int = 2;
223
//      while(lcl_int <= 2) {
224
//              if (func_1(str_1[lcl_int], str_2[lcl_int+1])==0) {
225
//                      lcl_ch = 'A';
226
//                      lcl_int ++;
227
//              }
228
//      }
229
//
230
//      if ((lcl_ch >= 'W')&&(lcl_ch < 'Z'))
231
//              lcl_int = 7;
232
//      if (lcl_ch == 'R')
233
//              return true;
234
//      else {
235
//              if (lcl_strcmp(str_1, str_2)>0) {
236
//                      lcl_int += 7;
237
//                      gbl_int = lcl_int;
238
//              } else
239
//                      return false;
240
//      }
241
//}
242
func_2:
243
        ;
244
        SUB     6,SP
245
        STO     R3,2(SP)
246
        STO     R4,3(SP)
247
        STO     R5,4(SP)
248
        STO     R6,5(SP)
249
        STO     R7,6(SP)
250
 
251
        MOV     R0,R3   ; R3 = str_1
252
        MOV     R1,R4   ; R4 = str_2
253
        LDI     2,R5    ; R5 = lcl_int
254
        LDI     'A',R7  ; R7 = lcl_ch
255
func_2_while_loop:
256
        CMP     2,R5
257
        BGT     func_2_end_while_loop
258
func_2_top_while_loop:
259
        MOV     R3,R6
260
        ADD     R5,R6
261
 
262
#ifdef  NO_INLINE
263
        LOD     (R6),R0
264
        MOV     R4,R6
265
        ADD     R5,R6
266
        LOD     1(R6),R1
267
 
268
        MOV     __HERE__+3(PC),R2
269
        STO     R2,1(SP)
270
        BRA     func_1
271
 
272
        CMP     0,R0
273
        ADD.Z   1,R5
274
#else
275
        LOD     (R6),R2
276
        MOV     R4,R6
277
        ADD     R5,R6
278
        LOD     1(R6),R1
279
 
280
        CMP     R2,R1
281
        STO.Z   R2,gbl_ch(R12)
282
        LDILO.Z 1,R0
283
 
284
        ADD.NZ  1,R5
285
#endif
286
 
287
#ifndef SKIP_SHORT_CIRCUITS
288
        BUSY.NZ
289
#endif
290
        CMP     3,R5
291
#ifndef SKIP_SHORT_CIRCUITS
292
        BUSY.LT
293
#endif
294
        BLT     func_2_top_while_loop
295
 
296
func_2_end_while_loop:
297
 
298
        // CMP  'W',R7                  // BUT! We know lcl_ch='A'
299
        // BLT  skip_if                 // So we can skip this
300
        // CMP  'Z',R7                  // entire  section
301
        // LDI.LT       7,R5
302
        // CMP  'R',R7
303
        // BNZ alt_if_case
304
        // LLO.Z        1,R0
305
        // BRA  func_2_return_and_cleanup
306
        //
307
        MOV     R3,R0
308
        MOV     R4,R1
309
        MOV     __HERE__+3(PC),R2
310
        STO     R2,1(SP)
311
        BRA     lcl_strcmp
312
        CMP     0,R0
313
        BGT     func_2_final_then
314
#ifndef SKIP_SHORT_CIRCUITS
315
        BUSY
316
#endif
317
        CLR     R0
318
        BRA     func_2_return_and_cleanup
319
func_2_final_then:
320
        // ADD  7,R5            ; Never read, so useless code
321
        LDI     1,R0
322
#ifndef SKIP_SHORT_CIRCUITS
323
        BUSY
324
#endif
325
func_2_return_and_cleanup:
326
 
327
        LOD     2(SP),R3
328
        LOD     3(SP),R4
329
        LOD     4(SP),R5
330
        LOD     5(SP),R6
331
        LOD     6(SP),R7
332
        ADD     6,SP
333
        RETN
334
 
335
//bool  func_3(test_enum a) {
336
//      test_enum       lcl_enum;
337
//
338
//      lcl_enum = a;
339
//      if (lcl_enum == Ident_3)
340
//              return true;
341
//      else
342
//              return false;
343
//}
344
 
345
#ifdef  NO_INLINE
346
func_3:
347
        ; On entry,
348
        ;  R0 = a
349
        ;  R1 - available
350
        CMP     2,R0
351
        CLR             R0      ; CLR Doesn't set flags
352
        LDILO.Z         1,R0
353
        RETN
354
#endif
355
 
356
 
357
// void proc_6(test_enum ev, test_enum *ep) {
358
//      *ep = ev;
359
//      if (!func_3(ev))
360
//              *ep = 3;
361
//      switch(ev) {
362
//              case 0: *ep = 0; break;
363
//              case 1:
364
//                      if (gbl_int > 100)
365
//                              *ep = 0;
366
//                      else
367
//                              *ep = 3;
368
//                      break;
369
//              case 2:
370
//                      *ep = 1;
371
//                      break;
372
//              case 3:
373
//                      break;
374
//              case 4:
375
//                      *ep = 2;
376
//      }
377
//}
378
 
379
proc_6:
380
        ; On entry:
381
        ;       R0 = ev
382
        ;       R1 = ep
383
        ;       R2 - unassigned
384
        ; Since we call func_3, we have to reserve R0 and R1
385
        ; for other purposes.  Thus
386
        ;       R2 = ev
387
        ;       R3 = ep
388
        SUB     2,SP
389
        STO     R3,2(SP)
390
 
391
        MOV     R1,R3
392
        MOV     R0,R2
393
        ; *ep = ev
394
        STO     R0,(R1)
395
#ifndef SKIP_SHORT_CIRCUITS
396
        CMP     2,R0
397
        BUSY.NZ
398
#endif
399
 
400
#ifdef  NO_INLINE
401
        ; !func_3(ev)
402
        MOV     __HERE__+3(PC),R1
403
        STO     R1,1(SP)
404
        BRA     func_3
405
 
406
        TST     -1,R0
407
        LDI     3,R1
408
        STO.Z   R1,(R3)
409
#else
410
        CMP             2,R0
411
        LDI     3,R1
412
        STO.Z   R1,(R3)
413
#endif
414
 
415
        TST     -1,R0
416
        LDI     3,R1
417
#ifndef SKIP_SHORT_CIRCUITS
418
        BUSY.Z
419
#endif
420
        STO.Z   R1,(R3)
421
 
422
#ifndef SKIP_SHORT_CIRCUITS
423
        CMP     2,R2
424
        BUSY.NZ
425
#endif
426
        CMP     0,R2
427
        BNZ     proc_6_case_not_zero
428
#ifndef SKIP_SHORT_CIRCUITS
429
        BUSY
430
#endif
431
        LDI     0,R1
432
        STO     R1,(R3)
433
        BRA     proc_6_end_of_case
434
proc_6_case_not_zero:
435
        CMP     1,R2
436
        BNZ     proc_6_case_not_one
437
#ifndef SKIP_SHORT_CIRCUITS
438
        BUSY
439
#endif
440
        LDI     3,R0
441
        LOD     gbl_int(R12),R1
442
        CMP     100,R1
443
        CLR.GT  R0
444
        STO     R0,(R3)
445
        BRA     proc_6_end_of_case
446
proc_6_case_not_one:
447
        CMP     2,R2
448
        BNZ     proc_6_case_not_two
449
        LDI     1,R1                            // Executed, if done properly
450
        STO     R1,(R3)
451
        BRA     proc_6_end_of_case
452
proc_6_case_not_two:
453
#ifndef SKIP_SHORT_CIRCUITS
454
        BUSY
455
#endif
456
        CMP     4,R2
457
        BNZ     proc_6_case_not_four
458
        LDI     2,R1
459
        STO     R1,(R3)
460
        // BRA  proc_6_end_of_case
461
proc_6_case_not_four:
462
proc_6_end_of_case:
463
        LOD     2(SP),R3
464
        ADD     2,SP
465
        RETN
466
 
467
// void proc_7(int a, int b, int *c) {
468
//      int     lcl;
469
//
470
//      lcl = a + 2;
471
//      *c = b + a;
472
//}
473
 
474
#ifdef  NO_INLINE
475
proc_7:
476
        ADD 2+R0,R1
477
        STO R1,(R2)
478
 
479
        RETN
480
#endif
481
 
482
//      int     a[50];
483
//      int     b[50][50];
484
//
485
// void proc_8(Arr_1_Dim a, Arr_2_Dim b, int c, int d) {
486
//      int     idx, loc;
487
//
488
//      loc = c+5;
489
//      a[loc] = d;
490
//      a[loc+1] = a[loc];
491
//      a[loc+30] = loc;
492
//      for(idx=loc; idx<= loc+1; idx++)
493
//              b[loc][idx] = loc;
494
//      b[loc][loc-1] += 1;
495
//      b[loc+20][loc] = a[loc];
496
//      gbl_int = 5;
497
//}
498
proc_8:
499
        ; R0 = a
500
        ; R1 = b
501
        ; R2 = c
502
        ; R3 = d
503
        ; R4 - unassigned
504
        ; Makes no function/procedure calls, so these can keep
505
        ; R2 = loc = c+5, replaces c
506
        ; R4 = idx
507
        SUB     2,SP
508
        STO     R5,1(SP)
509
        STO     R6,2(SP)
510
 
511
        ADD     5,R2    ; loc = c+5
512
        MOV     R0,R5
513
        ADD     R2,R5
514
        STO     R3,(R5)
515
        STO     R3,1(R5)
516
        STO     R2,30(R5)
517
        MOV     R2,R5
518
        MPYU    50,R5   ; R5 = 50 * R2 = 50 * loc
519
        ADD     R1,R5   ; R5 = &b[loc][0]
520
        MOV     R5,R6   ; R6 = &b[loc][0]
521
        ADD     R2,R5   ; R5 = &b[loc][loc]
522
        MOV     R2,R4   ; R4 = loc = index
523
proc_8_top_of_loop:
524
        CMP     1(R2),R4
525
        BGT     proc_8_end_of_loop
526
proc_8_loop_after_condition:
527
        STO     R2,(R5)
528
        ADD     1,R5
529
        ADD     1,R4
530
        CMP     2(R2),R4
531
        BLT     proc_8_loop_after_condition
532
proc_8_end_of_loop:
533
 
534
        ; b[loc][loc-1] += 1
535
        ADD     R2,R6           ; R6 = &b[loc][loc]
536
        LOD     -1(R6),R5
537
        ADD     1,R5
538
        STO     R5,-1(R6)
539
        ; b[loc+20][loc] = a[loc]
540
        MOV     R0,R4
541
        ADD     R2,R4
542
        LOD     (R4),R3
543
        STO     R3,20*50(R6)
544
        LDI     5,R3
545
        STO     R3,gbl_int(R12)
546
 
547
        LOD     1(SP),R5
548
        LOD     2(SP),R6
549
        ADD     2,SP
550
        RETN
551
 
552
// void proc_5(void) {
553
//      gbl_ch = 'A';
554
//      gbl_bool = false;
555
//}
556
#ifdef  NO_INLINE
557
proc_5:
558
        LDI     'A',R0
559
        STO     R0,gbl_ch(R12)
560
        CLR     R0
561
        STO     R0,gbl_bool(R12)
562
        ;
563
        RETN
564
#endif
565
 
566
// void proc_4(void) {
567
//      bool    lcl_bool;
568
//      lcl_bool = (gbl_ch == 'A');
569
//      gbl_ch_2 = 'B';
570
// }
571
#ifdef  NO_INLINE
572
proc_4:
573
        //
574
        ; LDI   GBL,R12 // Already in R12
575
        ; Setting lcl_bool is irrelevant, so the optimizer should remove it.
576
        ; R0 doesn't need to be saved, since it's already trashed by the
577
        ; subroutine call.
578
        ;
579
        ; LOD   gbl_ch(R12),R0
580
        ; CLR   R1
581
        ; CMP   'A',R0
582
        ; ADD.Z 1,R1
583
        ;
584
        LDI     'B',R0
585
        STO     R0,gbl_ch_2(R12)
586
        ;
587
        RETN
588
#endif
589
 
590
// void proc_3(RECP *a) {
591
//      if (gbl_ptr != NULL)
592
//              *a = gbl_ptr->ptr_comp;
593
//      proc_7(10,gbl_int, &gbl_ptr->variant.var_1.int_comp); // ??
594
//}
595
proc_3:
596
        SUB     3,SP
597
        STO     R3,2(SP)
598
        STO     R2,3(SP)
599
        ; Save one for the return address from our JSR "instruction"
600
        ;
601
        LOD     gbl_ptr(R12),R2
602
        TST     -1,R2
603
#ifndef SKIP_SHORT_CIRCUITS
604
        BUSY.Z
605
#endif
606
        LOD.NZ  ptr_comp(R2),R3
607
        STO.NZ  R3,(R0)
608
#ifdef  NO_INLINE
609
        LDI     10,R0
610
        LOD     gbl_int(R12),R1
611
        MOV     variant.var_1.int_comp(R2),R2
612
        MOV     __HERE__+3(PC),R3
613
        STO     R3,1(SP)
614
        BRA     proc_7
615
#else
616
        LOD     gbl_int(R12),R1
617
        ADD      12,R1
618
        STO      R1,variant.var_1.int_comp(R2)
619
#endif
620
        ;
621
        LOD     2(SP),R3
622
        LOD     3(SP),R2
623
        ADD     3,SP
624
        RETN
625
 
626
 
627
// void proc_2(int *a) {
628
//      int             lcl_int;
629
//      test_enum       lcl_enum;
630
//
631
//      lcl_int = *a + 10;
632
//      do {
633
//              if (gbl_ch == 'A') {
634
//                      lcl_int -= 1;
635
//                      *a = lcl_int - gbl_int;
636
//                      lcl_enum = Ident_1;
637
//              }
638
//      } while(lcl_enum != Ident_1);
639
//}
640
proc_2:
641
        SUB     5,SP
642
        STO     R6,1(SP)
643
        STO     R5,2(SP)
644
        STO     R4,3(SP)
645
        STO     R3,4(SP)
646
        STO     R2,5(SP)
647
        // R1 doesn't need to be stored, it was used in the subroutine
648
        // call calculation
649
 
650
        LOD     (R0),R1
651
        MOV     10(R1),R2       ; R2 = lcl_int
652
        LOD     gbl_ch(R12),R4  ; R4 = gbl_ch
653
#ifdef  NO_CHEATING
654
proc_2_loop:
655
        CMP     'A',R4
656
        SUB.Z   1,R2
657
        LOD.Z   gbl_int(R12),R5 ; R5 = gbl_int
658
        MOV.Z   R2,R6           ; R6 = lcl_int
659
        SUB.Z   R5,R6           ; lcl_int - gbl_int
660
        STO.Z   R6,(R0)         ; *a = R6
661
        CLR.Z   R3              ; lcl_enum = 0
662
// #ifndef      SKIP_SHORT_CIRCUITS
663
        // BUSY.NZ
664
// #endif
665
 
666
        TST     -1,R3
667
// #ifndef      SKIP_SHORT_CIRCUITS
668
        // BUSY.NZ
669
// #endif
670
        BNZ     proc_2_loop
671
#else
672
        LOD     gbl_int(R12),R5
673
        SUB     1(R5),R2
674
        STO     R2,(R0)
675
#endif
676
        ;
677
        LOD     1(SP),R6
678
        LOD     2(SP),R5
679
        LOD     3(SP),R4
680
        LOD     4(SP),R3
681
        LOD     5(SP),R2
682
        ADD     5,SP
683
        RETN
684
 
685
//void  proc_1 (RECP a) {
686
//      RECP    nxt = a->ptr_comp;
687
//
688
//      // structassign(a->ptr_comp, gbl_ptr);
689
//      *(a->ptr_comp) = *(gbl_ptr);
690
//
691
//      a->variant.var_1.int_comp = 5;
692
//      nxt->variant.var_1.int_comp = a->variant.var_1.int_comp;
693
//      proc_3(&nxt->ptr_comp);
694
//
695
//      if (nxt->discr == 0) {
696
//              nxt->variant.var_1.int_comp = 6;
697
//              proc_6(a->variant.var_1.enum_comp, &nxt->variant.var_1.enum_comp);
698
//              nxt->ptr_comp = gbl_ptr->ptr_comp;
699
//              proc_7(nxt->variant.var_1.int_comp, 10, &nxt->variant.var_1.int_comp);
700
//      } else
701
//              // structassign(a, a->ptr_comp);
702
//              *a = *(a->ptr_comp);
703
//}
704
proc_1:
705
        SUB     9,SP
706
        STO     R2,2(SP)
707
        STO     R3,3(SP)
708
        STO     R4,4(SP)
709
        STO     R5,5(SP)
710
        STO     R6,6(SP)
711
        STO     R7,7(SP)
712
        STO     R8,8(SP)
713
        STO     R9,9(SP)
714
 
715
        ; R9 = a
716
        ; R4 = nxt
717
        ; R12 = GBL
718
        ; R13 = SP
719
        MOV     R0,R9
720
        LOD     ptr_comp(R9),R4
721
#ifndef SKIP_SHORT_CIRCUITS
722
        TST     -1,R4
723
        BUSY.Z
724
#endif
725
        LDI     35,R5
726
        MOV     R9,R6
727
        LOD     gbl_ptr(R12),R7
728
proc_1_assign_loop_1:
729
        LOD     (R6),R8
730
        ADD     1,R6
731
        STO     R8,(R7)
732
        ADD     1,R7
733
        SUB     1,R5
734
        BNZ     proc_1_assign_loop_1;
735
 
736
#ifndef SKIP_SHORT_CIRCUITS
737
        LOD     gbl_ptr(R12),R2
738
        TST     -1,R2
739
        BUSY.Z
740
#endif
741
 
742
        LDI     5,R5
743
        STO     R5,variant.var_1.int_comp(R9)
744
        STO     R5,variant.var_1.int_comp(R4)
745
        MOV     ptr_comp(R4),R0
746
        MOV     __HERE__+3(PC),R1
747
        STO     R1,1(SP)
748
        BRA     proc_3          ; Uses R0 and R1
749
 
750
        LOD     discr(R4),R5
751
        CMP     0,R5
752
        BNZ     proc_1_last_struct_assign
753
        ; This is the juncture that is "supposed" to be taken
754
        LDI     6,R5
755
 
756
        STO     R5,variant.var_1.int_comp(R4)
757
        LOD     variant.var_1.enum_comp(R9), R0
758
#ifndef SKIP_SHORT_CIRCUITS
759
        CMP     2,R0
760
        BUSY.NZ
761
#endif
762
        MOV     variant.var_1.enum_comp+R4, R1
763
        MOV     __HERE__+3(PC),R2
764
        STO     R2,1(SP)
765
        BRA     proc_6
766
        ;
767
        LOD     gbl_ptr(R12),R5
768
        LOD     ptr_comp(R5),R5
769
        STO     R5,ptr_comp(R4)
770
        ;
771
#ifdef  NO_INLINE
772
        LOD     variant.var_1.int_comp(R4),R0
773
        LDI     10,R1
774
        MOV     variant.var_1.int_comp(R4),R2
775
        MOV     proc_1_return_closeout(PC),R3
776
        STO     R3,1(SP)
777
        BRA     proc_7
778
#else
779
        LOD     variant.var_1.int_comp(R4),R0
780
        ADD     12,R0
781
        STO     R0,variant.var_1.int_comp(R4)
782
        BRA     proc_1_return_closeout
783
#endif
784
        ;
785
proc_1_last_struct_assign:
786
#ifndef SKIP_SHORT_CIRCUITS
787
        BUSY
788
#endif
789
        LDI     35,R4
790
        MOV     R2,R5
791
        LOD     gbl_ptr(R12),R6
792
proc_1_assign_loop_2:
793
        LOD     (R6),R8
794
        STO     R8,(R7)
795
        ADD     1,R6
796
        ADD     1,R7
797
        SUB     1,R5
798
        BNZ     proc_1_assign_loop_2
799
        //
800
proc_1_return_closeout:
801
        //
802
        LOD     2(SP),R2
803
        LOD     3(SP),R3
804
        LOD     4(SP),R4
805
        LOD     5(SP),R5
806
        LOD     6(SP),R6
807
        LOD     7(SP),R7
808
        LOD     8(SP),R8
809
        LOD     9(SP),R9
810
        ADD     9,SP
811
        RETN
812
 
813
// void dhrystone(void) {
814
//      int     lcl_int_1, lcl_int_2, lcl_int_3, index, number_of_runs = 500;
815
//      test_enum       lcl_enum;
816
//      char    lcl_str_1[30], lcl_str_2[30], ch_index;
817
//      REC_T   a, b, *nxt = &a;
818
//
819
//      gbl_ptr = &b;
820
//      gbl_ptr->ptr_comp = nxt;
821
//      gbl_ptr->variant.var_1.enum_comp = 2;
822
//      gbl_ptr->variant.var_1.int_comp = 40;
823
//      lcl_strcpy(gbl_ptr->variant.var_1.str_comp, "DHRYSTONE PROGRAM, SOME STRING");
824
//      lcl_strcpy(lcl_str_1, "DHRYSTONE PROGRAM, 1\'ST STRING");
825
//
826
//      gbl_arr_2[8][7] = 10;
827
//
828
//      for(index=0; index < number_of_runs; index++) {
829
//              proc_5();
830
//              proc_4();
831
//              lcl_int_1 = 2;
832
//              lcl_int_2 = 3;
833
//              lcl_strcpy(lcl_str_2, "DHRYSTONE PROGRAM, 2\'ND STRING");
834
//              lcl_enum = Ident_2;
835
//              gbl_bool = !func_2(lcl_str_1, lcl_str_2);
836
//              while(lcl_int_1 < lcl_int_2) {
837
//                      lcl_int_3 = 5 * lcl_int_1 - lcl_int_2;
838
//                      proc_7(lcl_int_1, lcl_int_2, &lcl_int_3);
839
//                      lcl_int_1 += 1;
840
//              }
841
//
842
//              proc_8(gbl_arr_1, gbl_arr_2, lcl_int_1, lcl_int_3);
843
//              proc_1(gbl_ptr);
844
//
845
//              for(ch_index='A'; ch_index <= gbl_ch_2; ch_index++) {
846
//                      if (lcl_enum == func_1(ch_index, 'C')) {
847
//                              // Then not executed??
848
//                              proc_6(0, &lcl_enum);
849
//                              lcl_strcpy(lcl_str_2, "DHRYSTONE PROGRAM, 3\'RD STRING");
850
//                              lcl_int_2 = index;
851
//                              gbl_int = index;
852
//                      }
853
//              }
854
//
855
//              lcl_int_2 = lcl_int_2 * lcl_int_1;
856
//              lcl_int_1 = lcl_int_2 / lcl_int_3;
857
//              lcl_int_2 = 7 * ( lcl_int_2 - lcl_int_3) - lcl_int_1;
858
//              proc_2(&lcl_int_1);
859
//      }
860
//}
861
 
862
some_string:
863
        word    'D','H','R','Y','S','T','O','N','E',' '
864
        word    'P','R','O','G','R','A','M',',',' '
865
        word    'S','O','M','E',' ','S','T','R','I','N','G'
866
        word    0
867
 
868
first_string:
869
        word    'D','H','R','Y','S','T','O','N','E',' '
870
        word    'P','R','O','G','R','A','M',','
871
        word    ' ','1','\'','S','T'
872
        word    ' ','S','T','R','I','N','G'
873
        word    0
874
 
875
second_string:
876
        word    'D','H','R','Y','S','T','O','N','E',' '
877
        word    'P','R','O','G','R','A','M',',',' '
878
        word    '2','\'','N','D',' ','S','T','R','I','N','G'
879
        word    0
880
 
881
third_string:
882
        word    'D','H','R','Y','S','T','O','N','E',' '
883
        word    'P','R','O','G','R','A','M',',',' '
884
        word    '3','\'','R','D',' ','S','T','R','I','N','G'
885
        word    0
886
 
887
dhrystone:
888
#ifdef  SUPERVISOR_TASK
889
        SUB     12+RECSIZE+RECSIZE+30+30+3,SP
890
        ; Leave a space on the top of the stack for calling
891
        ; subroutines.
892
        STO     R1,2(SP)
893
        STO     R2,3(SP)
894
        STO     R3,4(SP)
895
        STO     R4,5(SP)
896
        STO     R5,6(SP)
897
        STO     R6,7(SP)
898
        STO     R7,8(SP)
899
        STO     R8,9(SP)
900
        STO     R9,10(SP)
901
        STO     R10,11(SP)
902
        STO     R11,12(SP)
903
        lcl_int_1       equ     12                      ; plus SP
904
#else
905
        lcl_int_1       equ     2                       ; plus SP
906
        SUB     2+RECSIZE+RECSIZE+30+30+3,SP
907
#endif
908
        // 12 is the global variable pointer
909
        // 13 is our stack
910
        // 14 is our condition code register
911
        // 15 is the program counter
912
        ;
913
        lcl_int_3       equ     lcl_int_1+1             ; plus SP
914
        lcl_enum        equ     lcl_int_3+1             ; plus SP
915
        lcl_str_1       equ     lcl_enum+1              ; plus SP
916
        lcl_str_2       equ     lcl_str_1+30            ; plus SP
917
        rec_a           equ     lcl_str_2+30            ; plus SP
918
        rec_b           equ     rec_a+RECSIZE           ; plus SP
919
 
920
//      int     lcl_int_1, lcl_int_2, lcl_int_3, index, number_of_runs = 500;
921
//      test_enum       lcl_enum;
922
//      char    lcl_str_1[30], lcl_str_2[30], ch_index;
923
//      REC_T   a, b, *nxt = &a;
924
//
925
//      gbl_ptr = &b;
926
        MOV     rec_b(SP),R0            ; R0 = &b
927
        STO     R0,gbl_ptr(PC)
928
//      gbl_ptr->ptr_comp = nxt;
929
        MOV     rec_a(SP),R1            ; R1 = &a = nxt
930
        STO     R1,ptr_comp(R0)         ; gbp_ptr->ptr.comp=b->ptr.comp=R1=nxt
931
//      gbl_ptr->variant.var_1.enum_comp = 2;
932
        LDI     2,R2
933
        STO     R2,variant.var_1.enum_comp(R0)
934
//      gbl_ptr->variant.var_1.int_comp = 40;
935
        LDI     40,R2
936
        STO     R2,variant.var_1.int_comp(R0)
937
//      lcl_strcpy(gbl_ptr->variant.var_1.str_comp, "DHRYSTONE PROGRAM, SOME STRING");
938
        MOV     variant.var_1.str_comp(R0),R0
939
        MOV     some_string(PC),R1
940
        MOV     __HERE__+3(PC),R2
941
        STO     R2,1(SP)
942
        BRA     lcl_strcpy
943
 
944
//      lcl_strcpy(lcl_str_1, "DHRYSTONE PROGRAM, 1\'ST STRING");
945
        MOV     lcl_str_1(SP),R0
946
        MOV     first_string(PC),R1
947
        MOV     __HERE__+3(PC),R2
948
        STO     R2,1(SP)
949
        BRA     lcl_strcpy
950
 
951
//      gbl_arr_2[8][7] = 10;
952
        LDI     10,R0
953
        STO     R0,8*50+7+gbl_arr_2(R12)
954
//
955
//      for(index=0; index < number_of_runs; index++) {
956
        ; Let R11 be our index
957
        CLR     R11
958
dhrystone_main_loop:
959
        ;; Start of Dhrystone main loop
960
        ; proc_5();
961
#ifdef  NO_INLINE
962
        MOV     __HERE__+3(PC),R0
963
        STO     R0,1(SP)
964
        BRA     proc_5
965
#else
966
        LDI     'A',R0
967
        STO     R0,gbl_ch(R12)
968
        CLR     R0
969
        STO     R0,gbl_bool(R12)
970
#endif
971
        ; proc_4();
972
#ifdef  NO_INLINE
973
        MOV     __HERE__+3(PC),R0
974
        STO     R0,1(SP)
975
        BRA     proc_4
976
#else
977
        LDI     'B',R0
978
        STO     R0,gbl_ch_2(R12)
979
#endif
980
//              lcl_int_1 = 2;
981
        LDI     2,R5
982
        STO     R5,lcl_int_1(SP)
983
//              lcl_int_2 = 3;
984
        LDI     3,R6
985
//              lcl_strcpy(lcl_str_2, "DHRYSTONE PROGRAM, 2\'ND STRING");
986
        MOV     lcl_str_2(SP),R0
987
        MOV     second_string(PC),R1
988
        MOV     __HERE__+3(PC),R2
989
        STO     R2,1(SP)
990
        BRA     lcl_strcpy
991
//              lcl_enum = Ident_2;
992
        LDI     2,R0
993
        STO     R0,lcl_enum(SP)
994
//              gbl_bool = !func_2(lcl_str_1, lcl_str_2);
995
        MOV     lcl_str_1(SP),R0
996
        MOV     lcl_str_2(SP),R1
997
        MOV     __HERE__+3(PC),R2
998
        STO     R2,1(SP)
999
        BRA     func_2
1000
        CLR     R1
1001
        TST     -1,R0
1002
        LDILO.Z 1,R1
1003
        STO     R1,gbl_bool(PC)
1004
 
1005
//              while(lcl_int_1 < lcl_int_2) {
1006
        ; R5 = lcl_int_1 = 2 on entry
1007
        ; R6 = lcl_int_2 = 3 on entry, so no entry test is required
1008
        LOD     lcl_int_1(SP),R5
1009
        // The 'while' comparison
1010
        CMP     R6,R5
1011
        BGE     dhrystone_end_while_loop
1012
dhrystone_while_loop:
1013
//                      lcl_int_3 = 5 * lcl_int_1 - lcl_int_2;
1014
        MOV     R5,R7
1015
        MPYS    5,R7
1016
        SUB     R6,R7
1017
        STO     R7,lcl_int_3(SP)
1018
//                      proc_7(lcl_int_1, lcl_int_2, &lcl_int_3);
1019
#ifdef  NO_INLINE
1020
        MOV     R5,R0
1021
        MOV     R6,R1
1022
        MOV     lcl_int_3(SP),R2
1023
        MOV     __HERE__+3(PC),R3
1024
        STO     R3,1(SP)
1025
        BRA     proc_7
1026
#else
1027
        MOV     R6,R1
1028
        ADD     2+R5,R1
1029
        STO     R1,lcl_int_3(SP)
1030
#endif
1031
//                      lcl_int_1 += 1;
1032
        LOD     lcl_int_1(SP),R5
1033
        ADD     1,R5
1034
        STO     R5,lcl_int_1(SP)
1035
;
1036
        ; BRA   dhrystone_while_loop    ; We'll unroll the loop, and put an
1037
        CMP     R6,R5                   ; additional comparison at the bottom
1038
        BLT     dhrystone_while_loop
1039
dhrystone_end_while_loop:
1040
//              }
1041
//
1042
//              proc_8(gbl_arr_1, gbl_arr_2, lcl_int_1, lcl_int_3);
1043
        MOV     gbl_arr_1(PC),R0
1044
        MOV     gbl_arr_2(PC),R1
1045
        MOV     R5,R2
1046
        MOV     R6,R3
1047
        MOV     __HERE__+3(PC),R4
1048
        STO     R4,1(SP)
1049
        BRA     proc_8
1050
//              proc_1(gbl_ptr);
1051
        LOD     gbl_ptr(PC),R0
1052
        MOV     __HERE__+3(PC),R2
1053
        STO     R2,1(SP)
1054
        BRA     proc_1
1055
//
1056
//              for(ch_index='A'; ch_index <= gbl_ch_2; ch_index++) {
1057
        LDI     'A',R7
1058
        LOD     gbl_ch_2(SP),R8
1059
        CMP     R7,R8
1060
        BLT     dhrystone_end_of_for_loop
1061
dhrystone_top_of_for_loop:
1062
//                      if (lcl_enum == func_1(ch_index, 'C')) {
1063
#ifdef  NO_INLINE
1064
        MOV     R7,R0
1065
        LDI     'C',R1
1066
        MOV     __HERE__+3(PC),R2
1067
        STO     R2,1(SP)
1068
        BRA     func_1
1069
#else
1070
        CMP     'C',R7
1071
        CLR.NZ  R0
1072
        STO.Z   R7,gbl_ch(R12)
1073
        LDILO.Z 1,R0
1074
#endif
1075
 
1076
        ; Result is now in R0
1077
        LOD     lcl_enum(SP),R1
1078
        CMP     R0,R1
1079
        BNZ     dhrystone_skip_then_clause
1080
//                              // Then not executed??
1081
//                              proc_6(0, &lcl_enum);
1082
 
1083
#ifndef SKIP_SHORT_CIRCUITS
1084
        BUSY
1085
#endif
1086
 
1087
        CLR     R0
1088
        MOV     lcl_enum(SP),R1
1089
        MOV     __HERE__+3(PC),R2
1090
        STO     R2,1(SP)
1091
        BRA     proc_6
1092
 
1093
//                              lcl_strcpy(lcl_str_2, "DHRYSTONE PROGRAM, 3\'RD STRING");
1094
        MOV     lcl_str_2(SP),R0
1095
        MOV     third_string(PC),R1
1096
        MOV     __HERE__+3(PC),R2
1097
        STO     R2,1(SP)
1098
        BRA     lcl_strcpy
1099
//                              lcl_int_2 = index;
1100
        MOV     R11,R6
1101
//                              gbl_int = index;
1102
        STO     R11,gbl_int(PC)
1103
//                      }
1104
dhrystone_skip_then_clause:
1105
        ADD     1,R7
1106
        LOD     gbl_ch_2(SP),R8
1107
        CMP     R8,R7
1108
        BGE     dhrystone_top_of_for_loop
1109
dhrystone_end_of_for_loop:
1110
//              }
1111
//
1112
//              lcl_int_2 = lcl_int_2 * lcl_int_1;
1113
        LOD     lcl_int_1(SP),R5
1114
        MPYS    R5,R6   ; lcl_int_2 =
1115
//              lcl_int_1 = lcl_int_2 / lcl_int_3;
1116
#ifndef SKIP_DIVIDE
1117
        MOV     R6,R0
1118
        LOD     lcl_int_3(SP),R1
1119
        MOV     __HERE__+3(PC),R2
1120
        STO     R2,1(SP)
1121
        BRA     divs
1122
#else
1123
        LDI     9,R0
1124
#endif
1125
        STO     R0,lcl_int_1(SP)
1126
//              lcl_int_2 = 7 * ( lcl_int_2 - lcl_int_3) - lcl_int_1;
1127
        LOD     lcl_int_3(SP),R2
1128
        SUB     R2,R6
1129
        MPYS    7,R6
1130
        SUB     R0,R6
1131
//              proc_2(&lcl_int_1);
1132
        MOV     lcl_int_1(SP),R0
1133
        MOV     __HERE__+3(PC),R1
1134
        STO     R1,1(SP)
1135
        BRA     proc_2
1136
 
1137
        ;; Bottom of (and return from) Dhrystone main loop
1138
        ADD     1,R11
1139
        CMP     NUMBER_OF_RUNS,R11
1140
        BLT     dhrystone_main_loop
1141
//      }
1142
 
1143
#ifdef  SUPERVISOR_TASK
1144
        LOD     2(SP),R1
1145
        LOD     3(SP),R2
1146
        LOD     4(SP),R3
1147
        LOD     5(SP),R4
1148
        LOD     6(SP),R5
1149
        LOD     7(SP),R6
1150
        LOD     8(SP),R7
1151
        LOD     9(SP),R8
1152
        LOD     10(SP),R9
1153
        LOD     11(SP),R10
1154
        LOD     12(SP),R11
1155
        ;
1156
        ADD     12+RECSIZE+RECSIZE+30+30+3,SP
1157
        ; Return from subroutine
1158
        RETN
1159
#else
1160
        LDI     0,CC
1161
        NOP
1162
        NOP
1163
        BUSY
1164
#endif

powered by: WebSVN 2.1.0

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