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

Subversion Repositories zipcpu

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

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

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

powered by: WebSVN 2.1.0

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