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

Subversion Repositories yacc

[/] [yacc/] [trunk/] [bench/] [c_src/] [dhrystone/] [dhry21_tak.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tak.sugawa
/*
2
 *************************************************************************
3
 *
4
 *                   "DHRYSTONE" Benchmark Program
5
 *                   -----------------------------
6
 *
7
 *  Version:    C, Version 2.1
8
 *
9
 *  File:       dhry_1.c (part 2 of 3)
10
 *
11
 *  Date:       May 25, 1988
12
 *
13
 *  Author:     Reinhold P. Weicker
14
 *
15
 *************************************************************************
16
 *
17
 Jun.30.2004 Add strcmp,strcpy Tak.Sugawara
18
                         print("$time"); print("$finish");
19
 
20
 
21
 
22
 /
23
 /*
24
#include <io.h>
25
#include <interrupt.h>
26
#include <progmem.h>
27
#include <stddef.h>
28
 
29
#ifdef __STDC__
30
#include <stdarg.h>
31
#else
32
#include <varargs.h>
33
#endif
34
#include <stdlib.h>
35
#include <string.h>
36
 
37
#include "ap_uart.h"
38
#include "printf_P.h"
39
*/
40
#include "dhry.h"
41
 
42
//#define DOS
43
 
44
/* Global Variables: */
45
 
46
Rec_Pointer     Ptr_Glob,
47
                Next_Ptr_Glob;
48
int             Int_Glob;
49
Boolean         Bool_Glob;
50
char            Ch_1_Glob,
51
                Ch_2_Glob;
52
int             Arr_1_Glob [50];
53
int             Arr_2_Glob [50] [50];
54
 
55
char Reg_Define[] = "Register option selected.";
56
extern int strcmp(char* a, register  char*b);//Jul.12.2004
57
 
58
  /*
59
  forward declaration necessary since Enumeration may not simply be int
60
  */
61
 
62
#ifndef ROPT
63
#define REG
64
        /* REG becomes defined as empty */
65
        /* i.e. no register variables   */
66
#else
67
#define REG register
68
#endif
69
 
70
//Verilog Specific Routines
71
 
72
 
73
 
74
#define print_port 0x3ff0
75
#define print_char_port 0x3ff1
76
#define print_int_port 0x3ff2
77
#define print_long_port 0x3ff4
78
 
79
 
80
 
81
void print(unsigned char* ptr)//Verilog Test Bench Use 
82
{
83
        #ifdef DOS
84
                        printf("%s ",ptr);
85
        #else
86
 
87
        while (*ptr) {
88
 
89
                *(volatile unsigned char*)print_port=*(ptr++);
90
        }
91
 
92
        *(volatile unsigned char*)print_port=0x00;//Write Done
93
        #endif
94
}
95
 
96
void print_char(unsigned char val)//Little Endian write out 16bit number 
97
{
98
        #ifdef DOS
99
                printf("%x ",val);
100
        #else
101
        *(volatile unsigned char*)print_char_port=(unsigned char)val ;
102
        #endif
103
 
104
}
105
void print_short(short val)//Little Endian write out 16bit number 
106
{
107
        #ifdef DOS
108
                printf("%x",val);
109
        #else
110
                *(volatile unsigned short*)print_int_port=val ;
111
        #endif
112
 
113
 
114
}
115
 
116
void print_long(unsigned long val)//Little Endian write out 32bit number 
117
{
118
        #ifdef DOS
119
                        printf("%x",val);
120
        #else
121
                        *(volatile unsigned long*)print_long_port=val;
122
 
123
        #endif
124
 
125
}
126
 
127
void strcpy(register char* dest,register char* source)
128
{
129
 
130
 
131
 
132
 
133
        while(*source) {
134
 
135
                *(dest++) =*(source++);
136
        }
137
 
138
 
139
        *dest=0;//Write Done
140
 
141
 
142
}
143
 
144
 
145
 
146
void main (void)
147
/*****/
148
 
149
  /* main program, corresponds to procedures        */
150
  /* Main and Proc_0 in the Ada version             */
151
{
152
        One_Fifty       Int_1_Loc;
153
  REG   One_Fifty       Int_2_Loc;
154
        One_Fifty       Int_3_Loc;
155
  REG   char            Ch_Index;
156
        Enumeration     Enum_Loc;
157
        Str_30          Str_1_Loc;
158
        Str_30          Str_2_Loc;
159
  REG   int             Run_Index;
160
  REG   int             Number_Of_Runs;
161
 
162
        Rec_Type rta,rtb;
163
        unsigned int _d1,_d2;
164
 
165
 
166
  print ("\n\rDhrystone Benchmark\n\r");
167
 
168
  Next_Ptr_Glob = &rta;
169
  Ptr_Glob = &rtb;
170
 
171
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
172
  Ptr_Glob->Discr                       = Ident_1;
173
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
174
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
175
  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
176
          "DHRYSTONE PROGRAM, SOME STRING");
177
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
178
 
179
  Arr_2_Glob [8][7] = 10;
180
        /* Was missing in published program. Without this statement,    */
181
        /* Arr_2_Glob [8][7] would have an undefined value.             */
182
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
183
        /* overflow may occur for this array element.                   */
184
 
185
 
186
  {
187
    int n;
188
    #ifdef DOS
189
        n=10000000;
190
    #else
191
    n =10;
192
    #endif
193
    Number_Of_Runs = n;
194
  }
195
 
196
 
197
//  printf ("Execution starts, %d runs through Dhrystone\n\r",Number_Of_Runs);
198
  print ("Execution starts");
199
  print_long(Number_Of_Runs);
200
  print(" runs through Dhrystone\n\r");
201
 
202
 
203
  print("$time");//For Bench Mark
204
  print("\n");
205
 
206
  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
207
  {
208
 
209
 
210
    Proc_5();
211
    Proc_4();
212
 
213
      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
214
    Int_1_Loc = 2;
215
    Int_2_Loc = 3;
216
    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
217
    Enum_Loc = Ident_2;
218
    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
219
 
220
 
221
      /* Bool_Glob == 1 */
222
    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
223
    {
224
      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
225
      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
226
 
227
      Int_1_Loc += 1;
228
    } /* while */
229
    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
230
 
231
    Proc_1 (Ptr_Glob);
232
    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
233
                             /* loop body executed twice */
234
    {
235
      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
236
          /* then, not executed */
237
        {
238
        Proc_6 (Ident_1, &Enum_Loc);
239
        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
240
        Int_2_Loc = Run_Index;
241
        Int_Glob = Run_Index;
242
        }
243
    }
244
 
245
    Int_2_Loc = Int_2_Loc * Int_1_Loc;
246
    Int_1_Loc = Int_2_Loc / Int_3_Loc;
247
    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
248
 
249
 
250
    Proc_2 (&Int_1_Loc);
251
 
252
 
253
  } /* loop "for Run_Index" */
254
 
255
 
256
        print("$time");//For Bench Mark
257
        print("\n");
258
    print("Execution ends\n\r");
259
        print("$finish");
260
 
261
}
262
 
263
 
264
Proc_1 (Ptr_Val_Par)
265
/******************/
266
 
267
REG Rec_Pointer Ptr_Val_Par;
268
    /* executed once */
269
{
270
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
271
                                        /* == Ptr_Glob_Next */
272
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
273
  /* corresponds to "rename" in Ada, "with" in Pascal           */
274
 
275
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
276
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
277
  Next_Record->variant.var_1.Int_Comp
278
        = Ptr_Val_Par->variant.var_1.Int_Comp;
279
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
280
 // print("In proc1");
281
  Proc_3 (&Next_Record->Ptr_Comp);
282
    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
283
                        == Ptr_Glob->Ptr_Comp */
284
   // print("In proc1 proc3 finished");
285
 
286
  if (Next_Record->Discr == Ident_1)
287
    /* then, executed */
288
  {
289
//      print(" In proc1 if\n");
290
    Next_Record->variant.var_1.Int_Comp = 6;
291
   // print(" In proc1 before proc6 finished\n");       
292
 
293
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
294
           &Next_Record->variant.var_1.Enum_Comp);
295
   // print(" In proc1 proc6 finished\n");       
296
 
297
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
298
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
299
           &Next_Record->variant.var_1.Int_Comp);
300
  }
301
  else /* not executed */
302
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
303
} /* Proc_1 */
304
 
305
 
306
Proc_2 (Int_Par_Ref)
307
/******************/
308
    /* executed once */
309
    /* *Int_Par_Ref == 1, becomes 4 */
310
 
311
One_Fifty   *Int_Par_Ref;
312
{
313
  One_Fifty  Int_Loc;
314
  Enumeration   Enum_Loc;
315
 
316
  Int_Loc = *Int_Par_Ref + 10;
317
  do /* executed once */
318
    if (Ch_1_Glob == 'A')
319
      /* then, executed */
320
    {
321
      Int_Loc -= 1;
322
      *Int_Par_Ref = Int_Loc - Int_Glob;
323
      Enum_Loc = Ident_1;
324
    } /* if */
325
  while (Enum_Loc != Ident_1); /* true */
326
} /* Proc_2 */
327
 
328
 
329
Proc_3 (Ptr_Ref_Par)
330
/******************/
331
    /* executed once */
332
    /* Ptr_Ref_Par becomes Ptr_Glob */
333
 
334
Rec_Pointer *Ptr_Ref_Par;
335
 
336
{
337
  if (Ptr_Glob != Null)
338
    /* then, executed */
339
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
340
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
341
} /* Proc_3 */
342
 
343
 
344
Proc_4 () /* without parameters */
345
/*******/
346
    /* executed once */
347
{
348
  Boolean Bool_Loc;
349
 
350
  Bool_Loc = Ch_1_Glob == 'A';
351
  Bool_Glob = Bool_Loc | Bool_Glob;
352
  Ch_2_Glob = 'B';
353
} /* Proc_4 */
354
 
355
 
356
Proc_5 () /* without parameters */
357
/*******/
358
    /* executed once */
359
{
360
  Ch_1_Glob = 'A';
361
  Bool_Glob = false;
362
} /* Proc_5 */
363
 
364
 
365
Proc_6 (Enum_Val_Par, Enum_Ref_Par)
366
/*********************************/
367
    /* executed once */
368
    /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
369
 
370
Enumeration  Enum_Val_Par;
371
Enumeration *Enum_Ref_Par;
372
{
373
//      print("proc6 entered\n");
374
  *Enum_Ref_Par = Enum_Val_Par;
375
  if (! Func_3 (Enum_Val_Par))
376
    /* then, not executed */
377
    *Enum_Ref_Par = Ident_4;
378
 
379
 
380
  switch (Enum_Val_Par)
381
  {
382
    case Ident_1:
383
      *Enum_Ref_Par = Ident_1;
384
      break;
385
    case Ident_2:
386
      if (Int_Glob > 100)
387
        /* then */
388
      *Enum_Ref_Par = Ident_1;
389
      else *Enum_Ref_Par = Ident_4;
390
      break;
391
    case Ident_3: /* executed */
392
      *Enum_Ref_Par = Ident_2;
393
      break;
394
    case Ident_4: break;
395
    case Ident_5:
396
      *Enum_Ref_Par = Ident_3;
397
      break;
398
  } /* switch */
399
} /* Proc_6 */
400
 
401
 
402
Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
403
/**********************************************/
404
    /* executed three times                                      */
405
    /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
406
    /*                  Int_Par_Ref becomes 7                    */
407
    /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
408
    /*                  Int_Par_Ref becomes 17                   */
409
    /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
410
    /*                  Int_Par_Ref becomes 18                   */
411
One_Fifty       Int_1_Par_Val;
412
One_Fifty       Int_2_Par_Val;
413
One_Fifty      *Int_Par_Ref;
414
{
415
  One_Fifty Int_Loc;
416
 
417
  Int_Loc = Int_1_Par_Val + 2;
418
  *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
419
} /* Proc_7 */
420
 
421
 
422
Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
423
/*********************************************************************/
424
    /* executed once      */
425
    /* Int_Par_Val_1 == 3 */
426
    /* Int_Par_Val_2 == 7 */
427
Arr_1_Dim       Arr_1_Par_Ref;
428
Arr_2_Dim       Arr_2_Par_Ref;
429
int             Int_1_Par_Val;
430
int             Int_2_Par_Val;
431
{
432
  REG One_Fifty Int_Index;
433
  REG One_Fifty Int_Loc;
434
 
435
  Int_Loc = Int_1_Par_Val + 5;
436
  Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
437
  Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
438
  Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
439
  for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
440
    Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
441
  Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
442
  Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
443
  Int_Glob = 5;
444
} /* Proc_8 */
445
 
446
 
447
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
448
/*************************************************/
449
    /* executed three times                                         */
450
    /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
451
    /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
452
    /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
453
 
454
Capital_Letter   Ch_1_Par_Val;
455
Capital_Letter   Ch_2_Par_Val;
456
{
457
  Capital_Letter        Ch_1_Loc;
458
  Capital_Letter        Ch_2_Loc;
459
 
460
  Ch_1_Loc = Ch_1_Par_Val;
461
  Ch_2_Loc = Ch_1_Loc;
462
  if (Ch_2_Loc != Ch_2_Par_Val)
463
    /* then, executed */
464
    return (Ident_1);
465
  else  /* not executed */
466
  {
467
    Ch_1_Glob = Ch_1_Loc;
468
    return (Ident_2);
469
   }
470
} /* Func_1 */
471
 
472
 
473
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
474
/*************************************************/
475
    /* executed once */
476
    /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
477
    /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
478
 
479
Str_30  Str_1_Par_Ref;
480
Str_30  Str_2_Par_Ref;
481
{
482
  REG One_Thirty        Int_Loc;
483
      Capital_Letter    Ch_Loc;
484
 
485
  Int_Loc = 2;
486
  while (Int_Loc <= 2) /* loop body executed once */
487
    if (Func_1 (Str_1_Par_Ref[Int_Loc],
488
                Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
489
      /* then, executed */
490
    {
491
      Ch_Loc = 'A';
492
      Int_Loc += 1;
493
    } /* if, while */
494
  if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
495
    /* then, not executed */
496
    Int_Loc = 7;
497
  if (Ch_Loc == 'R')
498
    /* then, not executed */
499
    return (true);
500
  else /* executed */
501
  {
502
    if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
503
      /* then, not executed */
504
    {
505
      Int_Loc += 7;
506
      Int_Glob = Int_Loc;
507
      return (true);
508
    }
509
    else /* executed */
510
      return (false);
511
  } /* if Ch_Loc */
512
} /* Func_2 */
513
 
514
 
515
Boolean Func_3 (Enum_Par_Val)
516
/***************************/
517
    /* executed once        */
518
    /* Enum_Par_Val == Ident_3 */
519
Enumeration Enum_Par_Val;
520
{
521
  Enumeration Enum_Loc;
522
 
523
  Enum_Loc = Enum_Par_Val;
524
  if (Enum_Loc == Ident_3)
525
    /* then, executed */
526
    return (true);
527
  else /* not executed */
528
    return (false);
529
} /* Func_3 */
530
 
531
 
532
 
533
        /* Procedure for the assignment of structures,          */
534
        /* if the C compiler doesn't support this feature       */
535
#ifdef  NOSTRUCTASSIGN
536
memcpy (d, s, l)
537
register char   *d;
538
register char   *s;
539
register int    l;
540
{
541
        while (l--) *d++ = *s++;
542
}
543
#endif
544
 
545
 

powered by: WebSVN 2.1.0

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