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];
33 //extern void *malloc (unsigned int s);
34 int scanf(const char *format
, ...);
35 /*Enumeration Func_1 (); Forward declaration now in dhry.h */
36 /* forward declaration necessary since Enumeration may not simply be int */
41 /* REG becomes defined as empty */
42 /* i.e. no register variables */
47 /* variables for time measurement: */
52 /* see library function "times" */
53 #define Too_Small_Time 120
54 /* Measurements should last at least about 2 seconds */
57 extern long time(long *);
58 /* see library function "time" */
59 #define Too_Small_Time 2
60 /* Measurements should last at least 2 seconds */
64 unsigned int clock(void);
65 #define CLOCKS_PER_SEC 1000
66 #define HZ CLOCKS_PER_SEC
69 #define Too_Small_Time 2000
75 Dhrystones_Per_Second
;
77 /* end of variables for time measurement */
87 /* main program, corresponds to procedures */
88 /* Main and Proc_0 in the Ada version */
91 REG One_Fifty Int_2_Loc
;
98 REG
int Number_Of_Runs
;
100 /* Initializations */
104 Next_Ptr_Glob
= /*(Rec_Pointer) malloc (sizeof (Rec_Type))*/ &malloc_1
;
105 Ptr_Glob
= /*(Rec_Pointer) malloc (sizeof (Rec_Type))*/ &malloc_2
;
107 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
108 Ptr_Glob
->Discr
= Ident_1
;
109 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
110 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
111 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
112 "DHRYSTONE PROGRAM, SOME STRING");
113 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
115 Arr_2_Glob
[8][7] = 10;
116 /* Was missing in published program. Without this statement, */
117 /* Arr_2_Glob [8][7] would have an undefined value. */
118 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
119 /* overflow may occur for this array element. */
122 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
126 printf ("Program compiled with 'register' attribute\n");
131 printf ("Program compiled without 'register' attribute\n");
134 printf ("Please give the number of runs through the benchmark: ");
137 /*scanf ("%d", &n)*/;
138 Number_Of_Runs
= 25000/*n*/;
142 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs
);
150 Begin_Time
= (long) time_info
.tms_utime
;
153 Begin_Time
= time ( (long *) 0);
156 Begin_Time
= clock();
159 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
164 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
167 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
169 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
171 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
173 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
175 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
179 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
180 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
183 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
184 /* loop body executed twice */
186 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
187 /* then, not executed */
189 Proc_6 (Ident_1
, &Enum_Loc
);
190 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
191 Int_2_Loc
= Run_Index
;
192 Int_Glob
= Run_Index
;
195 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
196 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
197 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
198 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
199 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
203 } /* loop "for Run_Index" */
211 End_Time
= (long) time_info
.tms_utime
;
214 End_Time
= time ( (long *) 0);
220 printf ("Execution ends\n");
222 printf ("Final values of the variables used in the benchmark:\n");
224 printf ("Int_Glob: %d\n", Int_Glob
);
225 printf (" should be: %d\n", 5);
226 printf ("Bool_Glob: %d\n", Bool_Glob
);
227 printf (" should be: %d\n", 1);
228 printf ("Ch_1_Glob: %c\n", Ch_1_Glob
);
229 printf (" should be: %c\n", 'A');
230 printf ("Ch_2_Glob: %c\n", Ch_2_Glob
);
231 printf (" should be: %c\n", 'B');
232 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
233 printf (" should be: %d\n", 7);
234 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
235 printf (" should be: Number_Of_Runs + 10\n");
236 printf ("Ptr_Glob->\n");
237 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob
->Ptr_Comp
);
238 printf (" should be: (implementation-dependent)\n");
239 printf (" Discr: %d\n", Ptr_Glob
->Discr
);
240 printf (" should be: %d\n", 0);
241 printf (" Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
242 printf (" should be: %d\n", 2);
243 printf (" Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
244 printf (" should be: %d\n", 17);
245 printf (" Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
246 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
247 printf ("Next_Ptr_Glob->\n");
248 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob
->Ptr_Comp
);
249 printf (" should be: (implementation-dependent), same as above\n");
250 printf (" Discr: %d\n", Next_Ptr_Glob
->Discr
);
251 printf (" should be: %d\n", 0);
252 printf (" Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
253 printf (" should be: %d\n", 1);
254 printf (" Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
255 printf (" should be: %d\n", 18);
256 printf (" Str_Comp: %s\n",
257 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
258 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
259 printf ("Int_1_Loc: %d\n", Int_1_Loc
);
260 printf (" should be: %d\n", 5);
261 printf ("Int_2_Loc: %d\n", Int_2_Loc
);
262 printf (" should be: %d\n", 13);
263 printf ("Int_3_Loc: %d\n", Int_3_Loc
);
264 printf (" should be: %d\n", 7);
265 printf ("Enum_Loc: %d\n", Enum_Loc
);
266 printf (" should be: %d\n", 1);
267 printf ("Str_1_Loc: %s\n", Str_1_Loc
);
268 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
269 printf ("Str_2_Loc: %s\n", Str_2_Loc
);
270 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
273 User_Time
= End_Time
- Begin_Time
;
275 if (User_Time
< Too_Small_Time
)
277 printf ("Measured time too small to obtain meaningful results\n");
278 printf ("Please increase number of runs\n");
284 Microseconds
= (float) User_Time
* Mic_secs_Per_Second
285 / (float) Number_Of_Runs
;
286 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
)
293 printf ("Microseconds for one run through Dhrystone: ");
294 //printf ("%6.1f \n", Microseconds);
295 printf ("%ld \n", (long int)Microseconds
);
296 printf ("Dhrystones per Second: ");
297 //printf ("%6.1f \n", Dhrystones_Per_Second);
298 printf ("%ld \n", (long int)Dhrystones_Per_Second
);
305 void Proc_1 (REG Rec_Pointer Ptr_Val_Par
)
311 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
312 /* == Ptr_Glob_Next */
313 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
314 /* corresponds to "rename" in Ada, "with" in Pascal */
316 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
317 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
318 Next_Record
->variant
.var_1
.Int_Comp
319 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
320 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
321 Proc_3 (&Next_Record
->Ptr_Comp
);
322 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
323 == Ptr_Glob->Ptr_Comp */
324 if (Next_Record
->Discr
== Ident_1
)
327 Next_Record
->variant
.var_1
.Int_Comp
= 6;
328 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
329 &Next_Record
->variant
.var_1
.Enum_Comp
);
330 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
331 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
332 &Next_Record
->variant
.var_1
.Int_Comp
);
334 else /* not executed */
335 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
339 void Proc_2 (One_Fifty
*Int_Par_Ref
)
342 /* *Int_Par_Ref == 1, becomes 4 */
346 Enumeration Enum_Loc
;
348 Int_Loc
= *Int_Par_Ref
+ 10;
349 do /* executed once */
350 if (Ch_1_Glob
== 'A')
354 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
357 while (Enum_Loc
!= Ident_1
); /* true */
361 void Proc_3 (Rec_Pointer
*Ptr_Ref_Par
)
364 /* Ptr_Ref_Par becomes Ptr_Glob */
367 if (Ptr_Glob
!= Null
)
369 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
370 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
374 void Proc_4 (void) /* without parameters */
379 Bool_Loc
= Ch_1_Glob
== 'A';
380 Bool_Glob
= Bool_Loc
| Bool_Glob
;
385 void Proc_5 (void) /* without parameters */
394 /* Procedure for the assignment of structures, */
395 /* if the C compiler doesn't support this feature */
396 #ifdef NOSTRUCTASSIGN
402 while (l--) *d++ = *s++;