source: trunk/Softwares/Dhrystone/src/c/dhry21a.c @ 114

Last change on this file since 114 was 114, checked in by rosiere, 15 years ago

1) Fix bug with previous commit
2) Add test libc
3) Change Dhrystone

  • Property svn:keywords set to Id
File size: 12.3 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 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//#ifdef HAVE_DOUBLE
260//    printf ("Measured time too small to obtain meaningful results : %f\n",User_Time);
261//#else
262//    printf ("Measured time too small to obtain meaningful results : %d\n",User_Time);
263//#endif
264//    printf ("Please increase number of runs\n");
265//    printf ("\n");
266//  }
267//  else
268  {
269#ifdef HAVE_DOUBLE
270    Microseconds          = User_Time * Mic_secs_Per_Second / (DOUBLE) Number_Of_Runs;
271    Dhrystones_Per_Second = (DOUBLE) Number_Of_Runs / User_Time;
272    Vax_Mips              = Dhrystones_Per_Second / 1757.0;
273#else
274    Microseconds          = User_Time                       / (DOUBLE) Number_Of_Runs;
275#endif
276
277#ifdef ROPT
278    printf ("Register option selected?  YES\n");
279#else
280    printf ("Register option selected?  NO\n");
281    strcpy(Reg_Define, "Register option not selected.");
282#endif
283
284#ifdef HAVE_DOUBLE
285    printf ("Microseconds for one run through Dhrystone : %.1lf  \n",Microseconds);
286    printf ("Dhrystones per Second                      : %.1lf \n",Dhrystones_Per_Second);
287    printf ("VAX MIPS rating                            : %.3lf \n",Vax_Mips);
288#else
289    printf ("Begin_Time : %d\n",Begin_Time);
290    printf ("End_Time   : %d\n",End_Time  );
291    printf ("User_Time  : %d\n",User_Time );
292    printf ("Numbers of cycle for one run through Dhrystone : %d  \n",Microseconds);
293#endif
294    printf ("\n");
295 
296  fprintf(Ap,"\n");
297  fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n");
298  fprintf(Ap,"%s\n",Reg_Define);
299
300#ifdef HAVE_DOUBLE
301  fprintf(Ap,"Microseconds for one loop : %.1lf\n",Microseconds);
302  fprintf(Ap,"Dhrystones per second     : %.1lf\n",Dhrystones_Per_Second);
303  fprintf(Ap,"VAX MIPS rating           : %.3lf\n",Vax_Mips);
304#else
305  fprintf(Ap,"Numbers of cycle for one loop : %.1d\n",Microseconds);
306#endif
307  }
308  fclose(Ap);
309  return 0;
310}
311
312void
313Proc_1 (Ptr_Val_Par)
314/******************/
315
316REG Rec_Pointer Ptr_Val_Par;
317    /* executed once */
318{
319  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; 
320                                        /* == Ptr_Glob_Next */
321  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
322  /* corresponds to "rename" in Ada, "with" in Pascal           */
323 
324  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
325  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
326  Next_Record->variant.var_1.Int_Comp
327        = Ptr_Val_Par->variant.var_1.Int_Comp;
328  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
329  Proc_3 (&Next_Record->Ptr_Comp);
330    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
331                        == Ptr_Glob->Ptr_Comp */
332  if (Next_Record->Discr == Ident_1)
333    /* then, executed */
334  {
335    Next_Record->variant.var_1.Int_Comp = 6;
336    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
337           &Next_Record->variant.var_1.Enum_Comp);
338    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
339    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
340           &Next_Record->variant.var_1.Int_Comp);
341  }
342  else /* not executed */
343    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
344} /* Proc_1 */
345
346void
347Proc_2 (Int_Par_Ref)
348/******************/
349    /* executed once */
350    /* *Int_Par_Ref == 1, becomes 4 */
351
352One_Fifty   *Int_Par_Ref;
353{
354  One_Fifty  Int_Loc;
355  Enumeration   Enum_Loc;
356
357  Int_Loc = *Int_Par_Ref + 10;
358  do /* executed once */
359    if (Ch_1_Glob == 'A')
360      /* then, executed */
361    {
362      Int_Loc -= 1;
363      *Int_Par_Ref = Int_Loc - Int_Glob;
364      Enum_Loc = Ident_1;
365    } /* if */
366  while (Enum_Loc != Ident_1); /* true */
367} /* Proc_2 */
368
369void
370Proc_3 (Ptr_Ref_Par)
371/******************/
372    /* executed once */
373    /* Ptr_Ref_Par becomes Ptr_Glob */
374
375Rec_Pointer *Ptr_Ref_Par;
376
377{
378  if (Ptr_Glob != Null)
379    /* then, executed */
380    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
381  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
382} /* Proc_3 */
383
384void
385Proc_4 () /* without parameters */
386/*******/
387    /* executed once */
388{
389  Boolean Bool_Loc;
390
391  Bool_Loc = Ch_1_Glob == 'A';
392  Bool_Glob = Bool_Loc | Bool_Glob;
393  Ch_2_Glob = 'B';
394} /* Proc_4 */
395
396void
397Proc_5 () /* without parameters */
398/*******/
399    /* executed once */
400{
401  Ch_1_Glob = 'A';
402  Bool_Glob = false;
403} /* Proc_5 */
404
405
406        /* Procedure for the assignment of structures,          */
407        /* if the C compiler doesn't support this feature       */
408#ifdef  NOSTRUCTASSIGN
409memcpy (d, s, l)
410register char   *d;
411register char   *s;
412register int    l;
413{
414        while (l--) *d++ = *s++;
415}
416#endif
Note: See TracBrowser for help on using the repository browser.