source: trunk/Softwares/Basic_test/src/c/dhry21a.c @ 98

Last change on this file since 98 was 81, checked in by rosiere, 17 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 11.7 KB
Line 
1/*
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 <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include "dhry.h"
22#include "dhry21.h"
23
24/* Global Variables: */
25
26Rec_Pointer     Ptr_Glob,
27                Next_Ptr_Glob;
28int             Int_Glob;
29Boolean         Bool_Glob;
30char            Ch_1_Glob,
31                Ch_2_Glob;
32int             Arr_1_Glob [50];
33int             Arr_2_Glob [50] [50];
34
35char Reg_Define[] = "Register option selected.";
36
37//extern char     *malloc ();
38//Enumeration     Func_1 ();
39  /*
40  forward declaration necessary since Enumeration may not simply be int
41  */
42
43#ifndef ROPT
44#define REG
45        /* REG becomes defined as empty */
46        /* i.e. no register variables   */
47#else
48#define REG register
49#endif
50
51
52/* variables for time measurement: */
53
54#define Too_Small_Time 2
55                /* Measurements should last at least 2 seconds */
56
57DOUBLE          Begin_Time,
58                End_Time,
59                User_Time;
60
61DOUBLE          Microseconds,
62                Dhrystones_Per_Second,
63                Vax_Mips;
64
65/* end of variables for time measurement */
66
67int main_dhry21 (unsigned int NUMBER_OF_RUNS)
68/*****/
69
70  /* main program, corresponds to procedures        */
71  /* Main and Proc_0 in the Ada version             */
72{
73  DOUBLE   dtime();
74
75        One_Fifty       Int_1_Loc;
76  REG   One_Fifty       Int_2_Loc;
77        One_Fifty       Int_3_Loc;
78  REG   char            Ch_Index;
79        Enumeration     Enum_Loc;
80        Str_30          Str_1_Loc;
81        Str_30          Str_2_Loc;
82  REG   int             Run_Index;
83  REG   int             Number_Of_Runs;
84
85        FILE            *Ap;
86
87  /* Initializations */
88
89  if ((Ap = fopen("dhry.res","a+")) == NULL)
90    {
91       printf("Can not open dhry.res\n\n");
92       exit(1);
93    }
94
95  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
96  Ptr_Glob      = (Rec_Pointer) malloc (sizeof (Rec_Type));
97
98  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
99  Ptr_Glob->Discr                       = Ident_1;
100  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
101  Ptr_Glob->variant.var_1.Int_Comp      = 40;
102  strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
103          "DHRYSTONE PROGRAM, SOME STRING");
104  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
105
106  Arr_2_Glob [8][7] = 10;
107        /* Was missing in published program. Without this statement,    */
108        /* Arr_2_Glob [8][7] would have an undefined value.             */
109        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
110        /* overflow may occur for this array element.                   */
111
112  printf ("\n");
113  printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
114  printf ("\n");
115
116  /*
117  if (Reg)
118  {
119    printf ("Program compiled with 'register' attribute\n");
120    printf ("\n");
121  }
122  else
123  {
124    printf ("Program compiled without 'register' attribute\n");
125    printf ("\n");
126  }
127  */
128
129//**********************************************************************
130//  printf ("Please give the number of runs through the benchmark: ");
131//  {
132//    int n;
133//    scanf ("%d", &n);
134//    Number_Of_Runs = n;
135//  }
136//  printf ("\n");
137//**********************************************************************
138
139  Number_Of_Runs = NUMBER_OF_RUNS;
140 
141  printf ("Execution starts, %d runs through Dhrystone\n",Number_Of_Runs);
142
143  /***************/
144  /* Start timer */
145  /***************/
146 
147  Begin_Time = dtime();
148 
149  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
150  {
151
152    Proc_5();
153    Proc_4();
154      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
155    Int_1_Loc = 2;
156    Int_2_Loc = 3;
157    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
158    Enum_Loc = Ident_2;
159    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
160      /* Bool_Glob == 1 */
161    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
162    {
163      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
164        /* Int_3_Loc == 7 */
165      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
166        /* Int_3_Loc == 7 */
167      Int_1_Loc += 1;
168    } /* while */
169      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
170    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
171      /* Int_Glob == 5 */
172    Proc_1 (Ptr_Glob);
173    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
174                             /* loop body executed twice */
175    {
176      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
177          /* then, not executed */
178        {
179        Proc_6 (Ident_1, &Enum_Loc);
180        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
181        Int_2_Loc = Run_Index;
182        Int_Glob = Run_Index;
183        }
184    }
185      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
186    Int_2_Loc = Int_2_Loc * Int_1_Loc;
187    Int_1_Loc = Int_2_Loc / Int_3_Loc;
188    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
189      /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
190    Proc_2 (&Int_1_Loc);
191      /* Int_1_Loc == 5 */
192
193  } /* loop "for Run_Index" */
194
195  /**************/
196  /* Stop timer */
197  /**************/
198
199  End_Time = dtime();
200
201  printf ("Execution ends\n");
202  /*******************************************************************
203  printf ("\n");
204  printf ("Final values of the variables used in the benchmark:\n");
205  printf ("\n");
206  printf ("Int_Glob:            %d\n", Int_Glob);
207  printf ("        should be:   %d\n", 5);
208  printf ("Bool_Glob:           %d\n", Bool_Glob);
209  printf ("        should be:   %d\n", 1);
210  printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
211  printf ("        should be:   %c\n", 'A');
212  printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
213  printf ("        should be:   %c\n", 'B');
214  printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
215  printf ("        should be:   %d\n", 7);
216  printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
217  printf ("        should be:   Number_Of_Runs + 10\n");
218  printf ("Ptr_Glob->\n");
219  printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
220  printf ("        should be:   (implementation-dependent)\n");
221  printf ("  Discr:             %d\n", Ptr_Glob->Discr);
222  printf ("        should be:   %d\n", 0);
223  printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
224  printf ("        should be:   %d\n", 2);
225  printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
226  printf ("        should be:   %d\n", 17);
227  printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
228  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
229  printf ("Next_Ptr_Glob->\n");
230  printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
231  printf ("        should be:   (implementation-dependent), same as above\n");
232  printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
233  printf ("        should be:   %d\n", 0);
234  printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
235  printf ("        should be:   %d\n", 1);
236  printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
237  printf ("        should be:   %d\n", 18);
238  printf ("  Str_Comp:          %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
239  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
240  printf ("Int_1_Loc:           %d\n", Int_1_Loc);
241  printf ("        should be:   %d\n", 5);
242  printf ("Int_2_Loc:           %d\n", Int_2_Loc);
243  printf ("        should be:   %d\n", 13);
244  printf ("Int_3_Loc:           %d\n", Int_3_Loc);
245  printf ("        should be:   %d\n", 7);
246  printf ("Enum_Loc:            %d\n", Enum_Loc);
247  printf ("        should be:   %d\n", 1);
248  printf ("Str_1_Loc:           %s\n", Str_1_Loc);
249  printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
250  printf ("Str_2_Loc:           %s\n", Str_2_Loc);
251  printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
252  printf ("\n");
253  ********************************************************************/
254
255  User_Time = End_Time - Begin_Time;
256
257  if (User_Time < Too_Small_Time)
258  {
259    printf ("Measured time too small to obtain meaningful results : %f\n",User_Time);
260    printf ("Please increase number of runs\n");
261    printf ("\n");
262  }
263  else
264  {
265    Microseconds          = User_Time * Mic_secs_Per_Second / (DOUBLE) Number_Of_Runs;
266    Dhrystones_Per_Second = (DOUBLE) Number_Of_Runs / User_Time;
267    Vax_Mips              = Dhrystones_Per_Second / 1757.0;
268
269#ifdef ROPT
270    printf ("Register option selected?  YES\n");
271#else
272    printf ("Register option selected?  NO\n");
273    strcpy(Reg_Define, "Register option not selected.");
274#endif
275
276    printf ("Microseconds for one run through Dhrystone : %.1lf  \n",Microseconds);
277    printf ("Dhrystones per Second                      : %.1lf \n",Dhrystones_Per_Second);
278    printf ("VAX MIPS rating                            : %.3lf \n",Vax_Mips);
279    printf ("\n");
280 
281  fprintf(Ap,"\n");
282  fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n");
283  fprintf(Ap,"%s\n",Reg_Define);
284
285  fprintf(Ap,"Microseconds for one loop : %.1lf\n",Microseconds);
286  fprintf(Ap,"Dhrystones per second     : %.1lf\n",Dhrystones_Per_Second);
287  fprintf(Ap,"VAX MIPS rating           : %.3lf\n",Vax_Mips);
288  }
289  fclose(Ap);
290  return 0;
291 
292}
293
294void
295Proc_1 (Ptr_Val_Par)
296/******************/
297
298REG Rec_Pointer Ptr_Val_Par;
299    /* executed once */
300{
301  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; 
302                                        /* == Ptr_Glob_Next */
303  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
304  /* corresponds to "rename" in Ada, "with" in Pascal           */
305 
306  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
307  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
308  Next_Record->variant.var_1.Int_Comp
309        = Ptr_Val_Par->variant.var_1.Int_Comp;
310  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
311  Proc_3 (&Next_Record->Ptr_Comp);
312    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
313                        == Ptr_Glob->Ptr_Comp */
314  if (Next_Record->Discr == Ident_1)
315    /* then, executed */
316  {
317    Next_Record->variant.var_1.Int_Comp = 6;
318    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
319           &Next_Record->variant.var_1.Enum_Comp);
320    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
321    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
322           &Next_Record->variant.var_1.Int_Comp);
323  }
324  else /* not executed */
325    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
326} /* Proc_1 */
327
328void
329Proc_2 (Int_Par_Ref)
330/******************/
331    /* executed once */
332    /* *Int_Par_Ref == 1, becomes 4 */
333
334One_Fifty   *Int_Par_Ref;
335{
336  One_Fifty  Int_Loc;
337  Enumeration   Enum_Loc;
338
339  Int_Loc = *Int_Par_Ref + 10;
340  do /* executed once */
341    if (Ch_1_Glob == 'A')
342      /* then, executed */
343    {
344      Int_Loc -= 1;
345      *Int_Par_Ref = Int_Loc - Int_Glob;
346      Enum_Loc = Ident_1;
347    } /* if */
348  while (Enum_Loc != Ident_1); /* true */
349} /* Proc_2 */
350
351void
352Proc_3 (Ptr_Ref_Par)
353/******************/
354    /* executed once */
355    /* Ptr_Ref_Par becomes Ptr_Glob */
356
357Rec_Pointer *Ptr_Ref_Par;
358
359{
360  if (Ptr_Glob != Null)
361    /* then, executed */
362    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
363  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
364} /* Proc_3 */
365
366void
367Proc_4 () /* without parameters */
368/*******/
369    /* executed once */
370{
371  Boolean Bool_Loc;
372
373  Bool_Loc = Ch_1_Glob == 'A';
374  Bool_Glob = Bool_Loc | Bool_Glob;
375  Ch_2_Glob = 'B';
376} /* Proc_4 */
377
378void
379Proc_5 () /* without parameters */
380/*******/
381    /* executed once */
382{
383  Ch_1_Glob = 'A';
384  Bool_Glob = false;
385} /* Proc_5 */
386
387
388        /* Procedure for the assignment of structures,          */
389        /* if the C compiler doesn't support this feature       */
390#ifdef  NOSTRUCTASSIGN
391memcpy (d, s, l)
392register char   *d;
393register char   *s;
394register int    l;
395{
396        while (l--) *d++ = *s++;
397}
398#endif
Note: See TracBrowser for help on using the repository browser.