2 ****************************************************************************
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
7 * Version: C, Version 2.1
9 * File: dhry_1.c (part 2 of 3)
13 * Author: Reinhold P. Weicker
15 ****************************************************************************
20 /* Global Variables: */
29 int Arr_2_Glob
[50] [50];
31 extern char *malloc ();
32 Enumeration
Func_1 ();
33 /* forward declaration necessary since Enumeration may not simply be int */
38 /* REG becomes defined as empty */
39 /* i.e. no register variables */
44 /* variables for time measurement: */
57 #define Too_Small_Time 2
58 /* Measurements should last at least 2 seconds */
64 Dhrystones_Per_Second
;
66 /* end of variables for time measurement */
72 /* main program, corresponds to procedures */
73 /* Main and Proc_0 in the Ada version */
76 REG One_Fifty Int_2_Loc
;
83 REG
int Number_Of_Runs
;
87 Next_Ptr_Glob
= (Rec_Pointer
) malloc (sizeof (Rec_Type
));
88 Ptr_Glob
= (Rec_Pointer
) malloc (sizeof (Rec_Type
));
90 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
91 Ptr_Glob
->Discr
= Ident_1
;
92 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
93 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
94 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
95 "DHRYSTONE PROGRAM, SOME STRING");
96 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
98 Arr_2_Glob
[8][7] = 10;
99 /* Was missing in published program. Without this statement, */
100 /* Arr_2_Glob [8][7] would have an undefined value. */
101 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
102 /* overflow may occur for this array element. */
106 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
112 printf ("Program compiled with 'register' attribute\n");
119 printf ("Program compiled without 'register' attribute\n");
124 printf ("Please give the number of runs through the benchmark: ");
131 Number_Of_Runs
= n
=1000;
136 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
146 Begin_Time = (long) time_info.tms_utime;
149 Begin_Time = time ( (long *) 0);
153 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
158 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
161 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
163 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
165 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
167 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
169 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
173 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
174 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
177 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
178 /* loop body executed twice */
180 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
181 /* then, not executed */
183 Proc_6 (Ident_1
, &Enum_Loc
);
184 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
185 Int_2_Loc
= Run_Index
;
186 Int_Glob
= Run_Index
;
189 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
190 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
191 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
192 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
193 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
197 } /* loop "for Run_Index" */
206 End_Time = (long) time_info.tms_utime;
209 End_Time = time ( (long *) 0);
214 printf ("Execution ends\n");
216 printf ("Final values of the variables used in the benchmark:\n");
218 printf ("Int_Glob: %d\n", Int_Glob);
219 printf (" should be: %d\n", 5);
220 printf ("Bool_Glob: %d\n", Bool_Glob);
221 printf (" should be: %d\n", 1);
222 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
223 printf (" should be: %c\n", 'A');
224 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
225 printf (" should be: %c\n", 'B');
226 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
227 printf (" should be: %d\n", 7);
228 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
229 printf (" should be: Number_Of_Runs + 10\n");
230 printf ("Ptr_Glob->\n");
231 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
232 printf (" should be: (implementation-dependent)\n");
233 printf (" Discr: %d\n", Ptr_Glob->Discr);
234 printf (" should be: %d\n", 0);
235 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
236 printf (" should be: %d\n", 2);
237 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
238 printf (" should be: %d\n", 17);
239 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
240 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
241 printf ("Next_Ptr_Glob->\n");
242 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
243 printf (" should be: (implementation-dependent), same as above\n");
244 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
245 printf (" should be: %d\n", 0);
246 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
247 printf (" should be: %d\n", 1);
248 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
249 printf (" should be: %d\n", 18);
250 printf (" Str_Comp: %s\n",
251 Next_Ptr_Glob->variant.var_1.Str_Comp);
252 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
253 printf ("Int_1_Loc: %d\n", Int_1_Loc);
254 printf (" should be: %d\n", 5);
255 printf ("Int_2_Loc: %d\n", Int_2_Loc);
256 printf (" should be: %d\n", 13);
257 printf ("Int_3_Loc: %d\n", Int_3_Loc);
258 printf (" should be: %d\n", 7);
259 printf ("Enum_Loc: %d\n", Enum_Loc);
260 printf (" should be: %d\n", 1);
261 printf ("Str_1_Loc: %s\n", Str_1_Loc);
262 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
263 printf ("Str_2_Loc: %s\n", Str_2_Loc);
264 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
268 User_Time
= End_Time
- Begin_Time
;
270 if (User_Time
< Too_Small_Time
)
273 printf ("Measured time too small to obtain meaningful results\n");
274 printf ("Please increase number of runs\n");
282 Microseconds = (float) User_Time * Mic_secs_Per_Second
283 / (float) Number_Of_Runs;
284 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
288 Microseconds = (float) User_Time * Mic_secs_Per_Second
289 / ((float) HZ * ((float) Number_Of_Runs));
290 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
295 printf ("Microseconds for one run through Dhrystone: ");
296 printf ("%6.1f \n", Microseconds);
297 printf ("Dhrystones per Second: ");
298 printf ("%6.1f \n", Dhrystones_Per_Second);
310 REG Rec_Pointer Ptr_Val_Par
;
313 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
314 /* == Ptr_Glob_Next */
315 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
316 /* corresponds to "rename" in Ada, "with" in Pascal */
318 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
319 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
320 Next_Record
->variant
.var_1
.Int_Comp
321 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
322 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
323 Proc_3 (&Next_Record
->Ptr_Comp
);
324 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
325 == Ptr_Glob->Ptr_Comp */
326 if (Next_Record
->Discr
== Ident_1
)
329 Next_Record
->variant
.var_1
.Int_Comp
= 6;
330 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
331 &Next_Record
->variant
.var_1
.Enum_Comp
);
332 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
333 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
334 &Next_Record
->variant
.var_1
.Int_Comp
);
336 else /* not executed */
337 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
344 /* *Int_Par_Ref == 1, becomes 4 */
346 One_Fifty
*Int_Par_Ref
;
349 Enumeration Enum_Loc
;
351 Int_Loc
= *Int_Par_Ref
+ 10;
352 do /* executed once */
353 if (Ch_1_Glob
== 'A')
357 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
360 while (Enum_Loc
!= Ident_1
); /* true */
367 /* Ptr_Ref_Par becomes Ptr_Glob */
369 Rec_Pointer
*Ptr_Ref_Par
;
372 if (Ptr_Glob
!= Null
)
374 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
375 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
379 Proc_4 () /* without parameters */
385 Bool_Loc
= Ch_1_Glob
== 'A';
386 Bool_Glob
= Bool_Loc
| Bool_Glob
;
391 Proc_5 () /* without parameters */
400 /* Procedure for the assignment of structures, */
401 /* if the C compiler doesn't support this feature */
402 #ifdef NOSTRUCTASSIGN
408 while (l
--) *d
++ = *s
++;
414 ****************************************************************************
416 * "DHRYSTONE" Benchmark Program
417 * -----------------------------
419 * Version: C, Version 2.1
421 * File: dhry_2.c (part 3 of 3)
425 * Author: Reinhold P. Weicker
427 ****************************************************************************
432 /* REG becomes defined as empty */
433 /* i.e. no register variables */
437 extern char Ch_1_Glob
;
440 Proc_6 (Enum_Val_Par
, Enum_Ref_Par
)
441 /*********************************/
443 /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
445 Enumeration Enum_Val_Par
;
446 Enumeration
*Enum_Ref_Par
;
448 *Enum_Ref_Par
= Enum_Val_Par
;
449 if (! Func_3 (Enum_Val_Par
))
450 /* then, not executed */
451 *Enum_Ref_Par
= Ident_4
;
452 switch (Enum_Val_Par
)
455 *Enum_Ref_Par
= Ident_1
;
460 *Enum_Ref_Par
= Ident_1
;
461 else *Enum_Ref_Par
= Ident_4
;
463 case Ident_3
: /* executed */
464 *Enum_Ref_Par
= Ident_2
;
468 *Enum_Ref_Par
= Ident_3
;
474 Proc_7 (Int_1_Par_Val
, Int_2_Par_Val
, Int_Par_Ref
)
475 /**********************************************/
476 /* executed three times */
477 /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
478 /* Int_Par_Ref becomes 7 */
479 /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
480 /* Int_Par_Ref becomes 17 */
481 /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
482 /* Int_Par_Ref becomes 18 */
483 One_Fifty Int_1_Par_Val
;
484 One_Fifty Int_2_Par_Val
;
485 One_Fifty
*Int_Par_Ref
;
489 Int_Loc
= Int_1_Par_Val
+ 2;
490 *Int_Par_Ref
= Int_2_Par_Val
+ Int_Loc
;
494 Proc_8 (Arr_1_Par_Ref
, Arr_2_Par_Ref
, Int_1_Par_Val
, Int_2_Par_Val
)
495 /*********************************************************************/
497 /* Int_Par_Val_1 == 3 */
498 /* Int_Par_Val_2 == 7 */
499 Arr_1_Dim Arr_1_Par_Ref
;
500 Arr_2_Dim Arr_2_Par_Ref
;
504 REG One_Fifty Int_Index
;
505 REG One_Fifty Int_Loc
;
507 Int_Loc
= Int_1_Par_Val
+ 5;
508 Arr_1_Par_Ref
[Int_Loc
] = Int_2_Par_Val
;
509 Arr_1_Par_Ref
[Int_Loc
+1] = Arr_1_Par_Ref
[Int_Loc
];
510 Arr_1_Par_Ref
[Int_Loc
+30] = Int_Loc
;
511 for (Int_Index
= Int_Loc
; Int_Index
<= Int_Loc
+1; ++Int_Index
)
512 Arr_2_Par_Ref
[Int_Loc
] [Int_Index
] = Int_Loc
;
513 Arr_2_Par_Ref
[Int_Loc
] [Int_Loc
-1] += 1;
514 Arr_2_Par_Ref
[Int_Loc
+20] [Int_Loc
] = Arr_1_Par_Ref
[Int_Loc
];
519 Enumeration
Func_1 (Ch_1_Par_Val
, Ch_2_Par_Val
)
520 /*************************************************/
521 /* executed three times */
522 /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
523 /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
524 /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
526 Capital_Letter Ch_1_Par_Val
;
527 Capital_Letter Ch_2_Par_Val
;
529 Capital_Letter Ch_1_Loc
;
530 Capital_Letter Ch_2_Loc
;
532 Ch_1_Loc
= Ch_1_Par_Val
;
534 if (Ch_2_Loc
!= Ch_2_Par_Val
)
537 else /* not executed */
539 Ch_1_Glob
= Ch_1_Loc
;
545 Boolean
Func_2 (Str_1_Par_Ref
, Str_2_Par_Ref
)
546 /*************************************************/
548 /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
549 /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
551 Str_30 Str_1_Par_Ref
;
552 Str_30 Str_2_Par_Ref
;
554 REG One_Thirty Int_Loc
;
555 Capital_Letter Ch_Loc
;
558 while (Int_Loc
<= 2) /* loop body executed once */
559 if (Func_1 (Str_1_Par_Ref
[Int_Loc
],
560 Str_2_Par_Ref
[Int_Loc
+1]) == Ident_1
)
566 if (Ch_Loc
>= 'W' && Ch_Loc
< 'Z')
567 /* then, not executed */
570 /* then, not executed */
574 if (strcmp (Str_1_Par_Ref
, Str_2_Par_Ref
) > 0)
575 /* then, not executed */
587 Boolean
Func_3 (Enum_Par_Val
)
588 /***************************/
590 /* Enum_Par_Val == Ident_3 */
591 Enumeration Enum_Par_Val
;
593 Enumeration Enum_Loc
;
595 Enum_Loc
= Enum_Par_Val
;
596 if (Enum_Loc
== Ident_3
)
599 else /* not executed */