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

Subversion Repositories mblite

[/] [mblite/] [trunk/] [sw/] [testbench/] [dhry.c] - Blame information for rev 10

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

Line No. Rev Author Line
1 2 takar
/*
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
 
18
#include "dhry.h"
19
 
20
/* Global Variables: */
21
 
22
Rec_Pointer     Ptr_Glob,
23
                Next_Ptr_Glob;
24
int             Int_Glob;
25
Boolean         Bool_Glob;
26
char            Ch_1_Glob,
27
                Ch_2_Glob;
28
int             Arr_1_Glob [50];
29
int             Arr_2_Glob [50] [50];
30
 
31
Enumeration     Func_1 ();
32
  /* forward declaration necessary since Enumeration may not simply be int */
33
 
34
#ifndef REG
35
        Boolean Reg = false;
36
#define REG
37
        /* REG becomes defined as empty */
38
        /* i.e. no register variables   */
39
#else
40
        Boolean Reg = true;
41
#endif
42
 
43
int dhry ()
44
{
45
        One_Fifty       Int_1_Loc;
46
  REG   One_Fifty       Int_2_Loc;
47
        One_Fifty       Int_3_Loc;
48
  REG   char            Ch_Index;
49
        Enumeration     Enum_Loc;
50
        Str_30          Str_1_Loc;
51
        Str_30          Str_2_Loc;
52
  REG   int             Run_Index;
53
  REG   int             Number_Of_Runs;
54
 
55
  /* Initializations */
56
 
57
  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
58
  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
59
 
60
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
61
  Ptr_Glob->Discr                       = Ident_1;
62
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
63
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
64
  strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING");
65
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
66
 
67
  Arr_2_Glob [8][7] = 10;
68
        /* Was missing in published program. Without this statement,    */
69
        /* Arr_2_Glob [8][7] would have an undefined value.             */
70
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
71
        /* overflow may occur for this array element.                   */
72
 
73
  Number_Of_Runs = 1;
74
 
75
  xil_printf ("\n");
76
  xil_printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
77
  xil_printf ("\n");
78
  if (Reg)
79
  {
80
    xil_printf ("Program compiled with 'register' attribute\n");
81
    xil_printf ("\n");
82
  }
83
  else
84
  {
85
    xil_printf ("Program compiled without 'register' attribute\n");
86
    xil_printf ("\n");
87
  }
88
  xil_printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
89
 
90
  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
91
  {
92
 
93
    Proc_5();
94
    Proc_4();
95
      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
96
    Int_1_Loc = 2;
97
    Int_2_Loc = 3;
98
    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
99
    Enum_Loc = Ident_2;
100
    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
101
      /* Bool_Glob == 1 */
102
    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
103
    {
104
      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
105
        /* Int_3_Loc == 7 */
106
      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
107
        /* Int_3_Loc == 7 */
108
      Int_1_Loc += 1;
109
    } /* while */
110
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
111
    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
112
      /* Int_Glob == 5 */
113
    Proc_1 (Ptr_Glob);
114
    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
115
                             /* loop body executed twice */
116
    {
117
      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
118
        {
119
        Proc_6 (Ident_1, &Enum_Loc);
120
        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
121
        Int_2_Loc = Run_Index;
122
        Int_Glob = Run_Index;
123
        }
124
    }
125
    Int_2_Loc = Int_2_Loc * Int_1_Loc;
126
    Int_1_Loc = Int_2_Loc / Int_3_Loc;
127
    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
128
    Proc_2 (&Int_1_Loc);
129
  }
130
 
131
  printf ("Execution ends\n");
132
  xil_printf ("\n");
133
  xil_printf ("Final values of the variables used in the benchmark:\n");
134
  xil_printf ("\n");
135
  xil_printf ("Int_Glob:            %d\n", Int_Glob);
136
  xil_printf ("        should be:   %d\n", 5);
137
  xil_printf ("Bool_Glob:           %d\n", Bool_Glob);
138
  xil_printf ("        should be:   %d\n", 1);
139
  xil_printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
140
  xil_printf ("        should be:   %c\n", 'A');
141
  xil_printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
142
  xil_printf ("        should be:   %c\n", 'B');
143
  xil_printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
144
  xil_printf ("        should be:   %d\n", 7);
145
  xil_printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
146
  xil_printf ("        should be:   Number_Of_Runs + 10\n");
147
  xil_printf ("Ptr_Glob->\n");
148
  xil_printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
149
  xil_printf ("        should be:   (implementation-dependent)\n");
150
  xil_printf ("  Discr:             %d\n", Ptr_Glob->Discr);
151
  xil_printf ("        should be:   %d\n", 0);
152
  xil_printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
153
  xil_printf ("        should be:   %d\n", 2);
154
  xil_printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
155
  xil_printf ("        should be:   %d\n", 17);
156
  xil_printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
157
  xil_printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
158
  xil_printf ("Next_Ptr_Glob->\n");
159
  xil_printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
160
  xil_printf ("        should be:   (implementation-dependent), same as above\n");
161
  xil_printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
162
  xil_printf ("        should be:   %d\n", 0);
163
  xil_printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
164
  xil_printf ("        should be:   %d\n", 1);
165
  xil_printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
166
  xil_printf ("        should be:   %d\n", 18);
167
  xil_printf ("  Str_Comp:          %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
168
  xil_printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
169
  xil_printf ("Int_1_Loc:           %d\n", Int_1_Loc);
170
  xil_printf ("        should be:   %d\n", 5);
171
  xil_printf ("Int_2_Loc:           %d\n", Int_2_Loc);
172
  xil_printf ("        should be:   %d\n", 13);
173
  xil_printf ("Int_3_Loc:           %d\n", Int_3_Loc);
174
  xil_printf ("        should be:   %d\n", 7);
175
  xil_printf ("Enum_Loc:            %d\n", Enum_Loc);
176
  xil_printf ("        should be:   %d\n", 1);
177
  xil_printf ("Str_1_Loc:           %s\n", Str_1_Loc);
178
  xil_printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
179
  xil_printf ("Str_2_Loc:           %s\n", Str_2_Loc);
180
  xil_printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
181
  xil_printf ("\n");
182
 
183
  return 0;
184
}
185
 
186
 
187
void Proc_1 (Ptr_Val_Par)
188
REG Rec_Pointer Ptr_Val_Par;
189
{
190
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
191
                                        /* == Ptr_Glob_Next */
192
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
193
  /* corresponds to "rename" in Ada, "with" in Pascal           */
194
 
195
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
196
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
197
  Next_Record->variant.var_1.Int_Comp
198
        = Ptr_Val_Par->variant.var_1.Int_Comp;
199
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
200
  Proc_3 (&Next_Record->Ptr_Comp);
201
  if (Next_Record->Discr == Ident_1)
202
  {
203
    Next_Record->variant.var_1.Int_Comp = 6;
204
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
205
           &Next_Record->variant.var_1.Enum_Comp);
206
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
207
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
208
           &Next_Record->variant.var_1.Int_Comp);
209
  }
210
  else
211
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
212
}
213
 
214
 
215
void Proc_2 (Int_Par_Ref)
216
 
217
One_Fifty   *Int_Par_Ref;
218
{
219
  One_Fifty  Int_Loc;
220
  Enumeration   Enum_Loc;
221
 
222
  Int_Loc = *Int_Par_Ref + 10;
223
  do /* executed once */
224
    if (Ch_1_Glob == 'A')
225
      /* then, executed */
226
    {
227
      Int_Loc -= 1;
228
      *Int_Par_Ref = Int_Loc - Int_Glob;
229
      Enum_Loc = Ident_1;
230
    } /* if */
231
  while (Enum_Loc != Ident_1); /* true */
232
} /* Proc_2 */
233
 
234
 
235
void Proc_3 (Ptr_Ref_Par)
236
/******************/
237
    /* executed once */
238
    /* Ptr_Ref_Par becomes Ptr_Glob */
239
 
240
Rec_Pointer *Ptr_Ref_Par;
241
 
242
{
243
  if (Ptr_Glob != Null)
244
    /* then, executed */
245
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
246
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
247
} /* Proc_3 */
248
 
249
 
250
void Proc_4 () /* without parameters */
251
/*******/
252
    /* executed once */
253
{
254
  Boolean Bool_Loc;
255
 
256
  Bool_Loc = Ch_1_Glob == 'A';
257
  Bool_Glob = Bool_Loc | Bool_Glob;
258
  Ch_2_Glob = 'B';
259
} /* Proc_4 */
260
 
261
 
262
void Proc_5 () /* without parameters */
263
/*******/
264
    /* executed once */
265
{
266
  Ch_1_Glob = 'A';
267
  Bool_Glob = false;
268
} /* Proc_5 */
269
 
270
 
271
        /* Procedure for the assignment of structures,          */
272
        /* if the C compiler doesn't support this feature       */
273
#ifdef  NOSTRUCTASSIGN
274
memcpy (d, s, l)
275
register char   *d;
276
register char   *s;
277
register int    l;
278
{
279
        while (l--) *d++ = *s++;
280
}
281
#endif
282
 
283
 
284
/*
285
 ****************************************************************************
286
 *
287
 *                   "DHRYSTONE" Benchmark Program
288
 *                   -----------------------------
289
 *
290
 *  Version:    C, Version 2.1
291
 *
292
 *  File:       dhry_2.c (part 3 of 3)
293
 *
294
 *  Date:       May 25, 1988
295
 *
296
 *  Author:     Reinhold P. Weicker
297
 *
298
 ****************************************************************************
299
 */
300
 
301
#ifndef REG
302
#define REG
303
        /* REG becomes defined as empty */
304
        /* i.e. no register variables   */
305
#endif
306
 
307
extern  int     Int_Glob;
308
extern  char    Ch_1_Glob;
309
 
310
 
311
void Proc_6 (Enum_Val_Par, Enum_Ref_Par)
312
/*********************************/
313
    /* executed once */
314
    /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
315
 
316
Enumeration  Enum_Val_Par;
317
Enumeration *Enum_Ref_Par;
318
{
319
  *Enum_Ref_Par = Enum_Val_Par;
320
  if (! Func_3 (Enum_Val_Par))
321
    /* then, not executed */
322
    *Enum_Ref_Par = Ident_4;
323
  switch (Enum_Val_Par)
324
  {
325
    case Ident_1:
326
      *Enum_Ref_Par = Ident_1;
327
      break;
328
    case Ident_2:
329
      if (Int_Glob > 100)
330
        /* then */
331
      *Enum_Ref_Par = Ident_1;
332
      else *Enum_Ref_Par = Ident_4;
333
      break;
334
    case Ident_3: /* executed */
335
      *Enum_Ref_Par = Ident_2;
336
      break;
337
    case Ident_4: break;
338
    case Ident_5:
339
      *Enum_Ref_Par = Ident_3;
340
      break;
341
  } /* switch */
342
} /* Proc_6 */
343
 
344
 
345
void Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
346
/**********************************************/
347
    /* executed three times                                      */
348
    /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
349
    /*                  Int_Par_Ref becomes 7                    */
350
    /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
351
    /*                  Int_Par_Ref becomes 17                   */
352
    /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
353
    /*                  Int_Par_Ref becomes 18                   */
354
One_Fifty       Int_1_Par_Val;
355
One_Fifty       Int_2_Par_Val;
356
One_Fifty      *Int_Par_Ref;
357
{
358
  One_Fifty Int_Loc;
359
 
360
  Int_Loc = Int_1_Par_Val + 2;
361
  *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
362
} /* Proc_7 */
363
 
364
 
365
void Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
366
/*********************************************************************/
367
    /* executed once      */
368
    /* Int_Par_Val_1 == 3 */
369
    /* Int_Par_Val_2 == 7 */
370
Arr_1_Dim       Arr_1_Par_Ref;
371
Arr_2_Dim       Arr_2_Par_Ref;
372
int             Int_1_Par_Val;
373
int             Int_2_Par_Val;
374
{
375
  REG One_Fifty Int_Index;
376
  REG One_Fifty Int_Loc;
377
 
378
  Int_Loc = Int_1_Par_Val + 5;
379
  Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
380
  Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
381
  Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
382
  for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
383
    Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
384
  Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
385
  Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
386
  Int_Glob = 5;
387
} /* Proc_8 */
388
 
389
 
390
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
391
/*************************************************/
392
    /* executed three times                                         */
393
    /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
394
    /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
395
    /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
396
 
397
Capital_Letter   Ch_1_Par_Val;
398
Capital_Letter   Ch_2_Par_Val;
399
{
400
  Capital_Letter        Ch_1_Loc;
401
  Capital_Letter        Ch_2_Loc;
402
 
403
  Ch_1_Loc = Ch_1_Par_Val;
404
  Ch_2_Loc = Ch_1_Loc;
405
  if (Ch_2_Loc != Ch_2_Par_Val)
406
    /* then, executed */
407
    return (Ident_1);
408
  else  /* not executed */
409
  {
410
    Ch_1_Glob = Ch_1_Loc;
411
    return (Ident_2);
412
   }
413
} /* Func_1 */
414
 
415
 
416
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
417
/*************************************************/
418
    /* executed once */
419
    /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
420
    /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
421
 
422
Str_30  Str_1_Par_Ref;
423
Str_30  Str_2_Par_Ref;
424
{
425
  REG One_Thirty        Int_Loc;
426
      Capital_Letter    Ch_Loc;
427
 
428
  Int_Loc = 2;
429
  while (Int_Loc <= 2) /* loop body executed once */
430
    if (Func_1 (Str_1_Par_Ref[Int_Loc],
431
                Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
432
      /* then, executed */
433
    {
434
      Ch_Loc = 'A';
435
      Int_Loc += 1;
436
    } /* if, while */
437
  if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
438
    /* then, not executed */
439
    Int_Loc = 7;
440
  if (Ch_Loc == 'R')
441
    /* then, not executed */
442
    return (true);
443
  else /* executed */
444
  {
445
    if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
446
      /* then, not executed */
447
    {
448
      Int_Loc += 7;
449
      Int_Glob = Int_Loc;
450
      return (true);
451
    }
452
    else /* executed */
453
      return (false);
454
  } /* if Ch_Loc */
455
} /* Func_2 */
456
 
457
 
458
Boolean Func_3 (Enum_Par_Val)
459
/***************************/
460
    /* executed once        */
461
    /* Enum_Par_Val == Ident_3 */
462
Enumeration Enum_Par_Val;
463
{
464
  Enumeration Enum_Loc;
465
 
466
  Enum_Loc = Enum_Par_Val;
467
  if (Enum_Loc == Ident_3)
468
    /* then, executed */
469
    return (true);
470
  else /* not executed */
471
    return (false);
472
} /* Func_3 */
473
 

powered by: WebSVN 2.1.0

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