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 "dhry.h"
19 
20 #ifdef STATIC
21    #define REG           static
22    Boolean Regb          = true;
23    #define REGSTRING     "static"
24 #else
25    #ifdef REGISTER
26       #define REG        register
27       Boolean Regb       = true;
28       #define REGSTRING  "register"
29    #else
30       #define REG
31       Boolean Regb       = false;
32       #define REGSTRING  "no"
33    #endif
34 #endif
35 
36 /* Global Variables: */
37 
38 Rec_Pointer     Ptr_Glob,
39                 Next_Ptr_Glob;
40 int             Int_Glob;
41 Boolean         Bool_Glob;
42 char            Ch_1_Glob,
43                 Ch_2_Glob;
44 int             Arr_1_Glob [50];
45 int             Arr_2_Glob [50] [50];
46 
47 /* variables for time measurement: */
48 
49 #define Too_Small_Time 2
50                 /* Measurements should last at least about 2 seconds */
51 
52 long            Begin_Time,
53                 End_Time,
54                 User_Time;
55 double_t        Microseconds,
56                 Dhrystones_Per_Second;
57 
58 /* end of variables for time measurement */
59 
60 Rec_Type malloc_1;
61 Rec_Type malloc_2;
62 
main(void)63 void main (void)
64 /*****/
65 
66   /* main program, corresponds to procedures        */
67   /* Main and Proc_0 in the Ada version             */
68 {
69         One_Fifty       Int_1_Loc;
70   REG   One_Fifty       Int_2_Loc;
71         One_Fifty       Int_3_Loc;
72   REG   char            Ch_Index;
73         Enumeration     Enum_Loc;
74         Str_30          Str_1_Loc;
75         Str_30          Str_2_Loc;
76   REG   int             Run_Index;
77         int             Number_Of_Runs;
78 
79   /* Initializations */
80 
81   Next_Ptr_Glob = &malloc_1;
82   Ptr_Glob = &malloc_2;
83 
84   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
85   Ptr_Glob->Discr                       = Ident_1;
86   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
87   Ptr_Glob->variant.var_1.Int_Comp      = 40;
88   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
89           "DHRYSTONE PROGRAM, SOME STRING");
90   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
91 
92   Arr_2_Glob [8][7] = 10;
93         /* Was missing in published program. Without this statement,    */
94         /* Arr_2_Glob [8][7] would have an undefined value.             */
95         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
96         /* overflow may occur for this array element.                   */
97 
98 #ifdef PRINTF
99   printf ("\n");
100   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
101   printf ("\n");
102   if (Regb)
103   {
104     printf ("Program compiled with " REGSTRING " attribute\n");
105     printf ("\n");
106   }
107   else
108   {
109     printf ("Program compiled without 'register' or 'static' attribute\n");
110     printf ("\n");
111   }
112   printf ("Please give the number of runs through the benchmark: ");
113   scanf ("%d", &Number_Of_Runs);
114 
115   printf ("\n");
116 
117   printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
118 #else
119   Number_Of_Runs = 20000;
120 #endif
121 
122   /***************/
123   /* Start timer */
124   /***************/
125 
126 #ifdef TIMEFUNC
127   Begin_Time = native_timer_start();
128 #endif
129 
130 TIMER_START();
131 
132   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
133   {
134 
135     Proc_5();
136     Proc_4();
137       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
138     Int_1_Loc = 2;
139     Int_2_Loc = 3;
140     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
141     Enum_Loc = Ident_2;
142     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
143       /* Bool_Glob == 1 */
144     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
145     {
146       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
147         /* Int_3_Loc == 7 */
148       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
149         /* Int_3_Loc == 7 */
150       Int_1_Loc += 1;
151     } /* while */
152       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
153     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
154       /* Int_Glob == 5 */
155     Proc_1 (Ptr_Glob);
156     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
157                              /* loop body executed twice */
158     {
159       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
160           /* then, not executed */
161         {
162         Proc_6 (Ident_1, &Enum_Loc);
163         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
164         Int_2_Loc = Run_Index;
165         Int_Glob = Run_Index;
166         }
167     }
168       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
169     Int_2_Loc = Int_2_Loc * Int_1_Loc;
170     Int_1_Loc = Int_2_Loc / Int_3_Loc;
171     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
172       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
173     Proc_2 (&Int_1_Loc);
174       /* Int_1_Loc == 5 */
175 
176   } /* loop "for Run_Index" */
177 
178   /**************/
179   /* Stop timer */
180   /**************/
181 
182 TIMER_STOP();
183 
184 #ifdef TIMEFUNC
185   End_Time = native_timer_stop();
186 #endif
187 
188 #ifdef PRINTF
189   printf ("Execution ends\n");
190   printf ("\n");
191   printf ("Final values of the variables used in the benchmark:\n");
192   printf ("\n");
193   printf ("Int_Glob:            %d\n", Int_Glob);
194   printf ("        should be:   %d\n", 5);
195   printf ("Bool_Glob:           %d\n", Bool_Glob);
196   printf ("        should be:   %d\n", 1);
197   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
198   printf ("        should be:   %c\n", 'A');
199   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
200   printf ("        should be:   %c\n", 'B');
201   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
202   printf ("        should be:   %d\n", 7);
203   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
204   printf ("        should be:   %d\n", Number_Of_Runs + 10);
205   printf ("Ptr_Glob->\n");
206   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
207   printf ("        should be:   (implementation-dependent)\n");
208   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
209   printf ("        should be:   %d\n", 0);
210   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
211   printf ("        should be:   %d\n", 2);
212   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
213   printf ("        should be:   %d\n", 17);
214   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
215   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
216   printf ("Next_Ptr_Glob->\n");
217   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
218   printf ("        should be:   (implementation-dependent), same as above\n");
219   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
220   printf ("        should be:   %d\n", 0);
221   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
222   printf ("        should be:   %d\n", 1);
223   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
224   printf ("        should be:   %d\n", 18);
225   printf ("  Str_Comp:          %s\n",
226                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
227   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
228   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
229   printf ("        should be:   %d\n", 5);
230   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
231   printf ("        should be:   %d\n", 13);
232   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
233   printf ("        should be:   %d\n", 7);
234   printf ("Enum_Loc:            %d\n", Enum_Loc);
235   printf ("        should be:   %d\n", 1);
236   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
237   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
238   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
239   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
240   printf ("\n");
241 
242 #ifdef TIMEFUNC
243   User_Time = End_Time - Begin_Time;
244 
245   if (User_Time < Too_Small_Time)
246   {
247     printf ("Measured time too small to obtain meaningful results\n");
248     printf ("Please increase number of runs\n");
249     printf ("\n");
250   }
251   else
252   {
253     Microseconds = (double_t) User_Time * 1e6
254                         / (double_t) Number_Of_Runs;
255     Dhrystones_Per_Second = (double_t) Number_Of_Runs / (double_t) User_Time;
256 
257     printf ("Microseconds for one run through Dhrystone: ");
258     printf ("%6.1f \n", Microseconds);
259     printf ("Dhrystones per Second:                      ");
260     printf ("%6.1f \n", Dhrystones_Per_Second);
261     printf ("\n");
262   }
263 #endif
264 #endif
265 }
266 
267 #ifndef STATIC
Proc_1(REG Rec_Pointer Ptr_Val_Par)268 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
269 #else
270 void Proc_1 (Rec_Pointer Ptr_Val_Par)
271 #endif
272 /******************/
273 
274     /* executed once */
275 {
276 #ifndef STATIC
277   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
278 #else
279   REG Rec_Pointer Next_Record;
280   Next_Record = Ptr_Val_Par->Ptr_Comp;
281 #endif
282                                         /* == Ptr_Glob_Next */
283   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
284   /* corresponds to "rename" in Ada, "with" in Pascal           */
285 
286   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
287   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
288   Next_Record->variant.var_1.Int_Comp
289         = Ptr_Val_Par->variant.var_1.Int_Comp;
290   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
291   Proc_3 (&Next_Record->Ptr_Comp);
292     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
293                         == Ptr_Glob->Ptr_Comp */
294   if (Next_Record->Discr == Ident_1)
295     /* then, executed */
296   {
297     Next_Record->variant.var_1.Int_Comp = 6;
298     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
299            &Next_Record->variant.var_1.Enum_Comp);
300     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
301     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
302            &Next_Record->variant.var_1.Int_Comp);
303   }
304   else /* not executed */
305     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
306 } /* Proc_1 */
307 
308 
Proc_2(One_Fifty * Int_Par_Ref)309 void Proc_2 (One_Fifty *Int_Par_Ref)
310 /******************/
311     /* executed once */
312     /* *Int_Par_Ref == 1, becomes 4 */
313 
314 {
315   One_Fifty  Int_Loc;
316   Enumeration   Enum_Loc;
317 
318   Int_Loc = *Int_Par_Ref + 10;
319   do /* executed once */
320     if (Ch_1_Glob == 'A')
321       /* then, executed */
322     {
323       Int_Loc -= 1;
324       *Int_Par_Ref = Int_Loc - Int_Glob;
325       Enum_Loc = Ident_1;
326     } /* if */
327   while (Enum_Loc != Ident_1); /* true */
328 } /* Proc_2 */
329 
330 
Proc_3(Rec_Pointer * Ptr_Ref_Par)331 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
332 /******************/
333     /* executed once */
334     /* Ptr_Ref_Par becomes Ptr_Glob */
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 
Proc_4(void)344 void Proc_4 (void) /* without parameters */
345 /*******/
346     /* executed once */
347 {
348   Boolean Bool_Loc;
349   Bool_Loc = Ch_1_Glob == 'A';
350   Bool_Glob = Bool_Loc | Bool_Glob;
351   Ch_2_Glob = 'B';
352 } /* Proc_4 */
353 
354 
Proc_5(void)355 void Proc_5 (void) /* without parameters */
356 /*******/
357     /* executed once */
358 {
359   Ch_1_Glob = 'A';
360   Bool_Glob = false;
361 } /* Proc_5 */
362