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 17, 1988
12 *
13 *  Author:     Reinhold P. Weicker
14 *
15 ****************************************************************************
16 */
17
18#include "dhry.h"
19
20/* Global Variables: */
21
22Rec_Pointer     Ptr_Glob,
23                Next_Ptr_Glob;
24int             Int_Glob;
25Boolean         Bool_Glob;
26char            Ch_1_Glob,
27                Ch_2_Glob;
28int             Arr_1_Glob [50];
29int             Arr_2_Glob [50] [50];
30
31extern char     *malloc ();
32Enumeration     Func_1 ();
33  /* forward declaration necessary since Enumeration may not simply be int */
34
35#ifndef REG
36        Boolean Reg = false;
37#define REG
38        /* REG becomes defined as empty */
39        /* i.e. no register variables   */
40#else
41        Boolean Reg = true;
42#endif
43
44/* variables for time measurement: */
45
46#ifdef TIMES
47struct tms      time_info;
48extern  int     times ();
49                /* see library function "times" */
50#define Too_Small_Time (2*HZ)
51                /* Measurements should last at least about 2 seconds */
52#endif
53#ifdef TIME
54extern long     time();
55                /* see library function "time"  */
56#define Too_Small_Time 2
57                /* Measurements should last at least 2 seconds */
58#endif
59#ifdef MSC_CLOCK
60extern clock_t        clock();
61#define Too_Small_Time (2*HZ)
62#endif
63
64long            Begin_Time,
65                End_Time,
66                User_Time;
67float           Microseconds,
68                Dhrystones_Per_Second;
69
70/* end of variables for time measurement */
71
72
73main ()
74/*****/
75
76  /* main program, corresponds to procedures        */
77  /* Main and Proc_0 in the Ada version             */
78{
79        One_Fifty       Int_1_Loc;
80  REG   One_Fifty       Int_2_Loc;
81        One_Fifty       Int_3_Loc;
82  REG   char            Ch_Index;
83        Enumeration     Enum_Loc;
84        Str_30          Str_1_Loc;
85        Str_30          Str_2_Loc;
86  REG   int             Run_Index;
87  REG   int             Number_Of_Runs;
88
89  /* Initializations */
90
91  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
92  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
93
94  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
95  Ptr_Glob->Discr                       = Ident_1;
96  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
97  Ptr_Glob->variant.var_1.Int_Comp      = 40;
98  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
99          "DHRYSTONE PROGRAM, SOME STRING");
100  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
101
102  Arr_2_Glob [8][7] = 10;
103        /* Was missing in published program. Without this statement,    */
104        /* Arr_2_Glob [8][7] would have an undefined value.             */
105        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
106        /* overflow may occur for this array element.                   */
107     int n;
108     scanf ("%d", &n);
109     Number_Of_Runs = n;
110
111
112  /***************/
113  /* Start timer */
114  /***************/
115
116#ifdef TIMES
117  times (&time_info);
118  Begin_Time = (long) time_info.tms_utime;
119#endif
120#ifdef TIME
121  Begin_Time = time ( (long *) 0);
122#endif
123#ifdef MSC_CLOCK
124  Begin_Time = clock();
125#endif
126
127  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
128  {
129
130    Proc_5();
131    Proc_4();
132      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
133    Int_1_Loc = 2;
134    Int_2_Loc = 3;
135    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
136    Enum_Loc = Ident_2;
137    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
138      /* Bool_Glob == 1 */
139    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
140    {
141      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
142        /* Int_3_Loc == 7 */
143      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
144        /* Int_3_Loc == 7 */
145      Int_1_Loc += 1;
146    } /* while */
147      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
148    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
149      /* Int_Glob == 5 */
150    Proc_1 (Ptr_Glob);
151    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
152                             /* loop body executed twice */
153    {
154      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
155          /* then, not executed */
156        {
157        Proc_6 (Ident_1, &Enum_Loc);
158        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
159        Int_2_Loc = Run_Index;
160        Int_Glob = Run_Index;
161        }
162    }
163      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
164    Int_2_Loc = Int_2_Loc * Int_1_Loc;
165    Int_1_Loc = Int_2_Loc / Int_3_Loc;
166    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
167      /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
168    Proc_2 (&Int_1_Loc);
169      /* Int_1_Loc == 5 */
170
171  } /* loop "for Run_Index" */
172
173  /**************/
174  /* Stop timer */
175  /**************/
176
177#ifdef TIMES
178  times (&time_info);
179  End_Time = (long) time_info.tms_utime;
180#endif
181#ifdef TIME
182  End_Time = time ( (long *) 0);
183#endif
184#ifdef MSC_CLOCK
185  End_Time = clock();
186#endif
187  User_Time = End_Time - Begin_Time;
188
189  if (User_Time < Too_Small_Time)
190  {
191    printf ("Measured time too small to obtain meaningful results\n");
192    printf ("Please increase number of runs\n");
193    printf ("\n");
194  }
195  else
196  {
197#ifdef TIME
198    Microseconds = (float) User_Time * Mic_secs_Per_Second
199                        / (float) Number_Of_Runs;
200    Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
201#else
202    Microseconds = (float) User_Time * Mic_secs_Per_Second
203                        / ((float) HZ * ((float) Number_Of_Runs));
204    Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
205                        / (float) User_Time;
206#endif
207    printf ("%6.1f \n", Dhrystones_Per_Second);
208  }
209
210}
211
212
213Proc_1 (Ptr_Val_Par)
214/******************/
215
216REG Rec_Pointer Ptr_Val_Par;
217    /* executed once */
218{
219  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
220                                        /* == Ptr_Glob_Next */
221  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
222  /* corresponds to "rename" in Ada, "with" in Pascal           */
223
224  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
225  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
226  Next_Record->variant.var_1.Int_Comp
227        = Ptr_Val_Par->variant.var_1.Int_Comp;
228  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
229  Proc_3 (&Next_Record->Ptr_Comp);
230    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
231                        == Ptr_Glob->Ptr_Comp */
232  if (Next_Record->Discr == Ident_1)
233    /* then, executed */
234  {
235    Next_Record->variant.var_1.Int_Comp = 6;
236    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
237           &Next_Record->variant.var_1.Enum_Comp);
238    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
239    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
240           &Next_Record->variant.var_1.Int_Comp);
241  }
242  else /* not executed */
243    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
244return 0; } /* Proc_1 */
245
246
247Proc_2 (Int_Par_Ref)
248/******************/
249    /* executed once */
250    /* *Int_Par_Ref == 1, becomes 4 */
251
252One_Fifty   *Int_Par_Ref;
253{
254  One_Fifty  Int_Loc;
255  Enumeration   Enum_Loc;
256
257  Int_Loc = *Int_Par_Ref + 10;
258  do /* executed once */
259    if (Ch_1_Glob == 'A')
260      /* then, executed */
261    {
262      Int_Loc -= 1;
263      *Int_Par_Ref = Int_Loc - Int_Glob;
264      Enum_Loc = Ident_1;
265    } /* if */
266  while (Enum_Loc != Ident_1); /* true */
267return 0; } /* Proc_2 */
268
269
270Proc_3 (Ptr_Ref_Par)
271/******************/
272    /* executed once */
273    /* Ptr_Ref_Par becomes Ptr_Glob */
274
275Rec_Pointer *Ptr_Ref_Par;
276
277{
278  if (Ptr_Glob != Null)
279    /* then, executed */
280    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
281  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
282return 0; } /* Proc_3 */
283
284
285Proc_4 () /* without parameters */
286/*******/
287    /* executed once */
288{
289  Boolean Bool_Loc;
290
291  Bool_Loc = Ch_1_Glob == 'A';
292  Bool_Glob = Bool_Loc | Bool_Glob;
293  Ch_2_Glob = 'B';
294return 0; } /* Proc_4 */
295
296
297Proc_5 () /* without parameters */
298/*******/
299    /* executed once */
300{
301  Ch_1_Glob = 'A';
302  Bool_Glob = false;
303return 0; } /* Proc_5 */
304
305
306        /* Procedure for the assignment of structures,          */
307        /* if the C compiler doesn't support this feature       */
308#ifdef  NOSTRUCTASSIGN
309memcpy (d, s, l)
310register char   *d;
311register char   *s;
312register int    l;
313{
314        while (l--) *d++ = *s++;
315}
316#endif
317
318
319