1 /*****************************************************************************
2 * The BYTE UNIX Benchmarks - Release 3
3 * Module: dhry_1.c SID: 3.4 5/15/91 19:30:21
5 *****************************************************************************
6 * Bug reports, patches, comments, suggestions should be sent to:
8 * Ben Smith, Rick Grehan or Tom Yager
9 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
11 *****************************************************************************
13 * *** WARNING **** With BYTE's modifications applied, results obtained with
14 * ******* this version of the Dhrystone program may not be applicable
18 * 10/22/97 - code cleanup to remove ANSI C compiler warnings
19 * Andy Kahn <kahn@zk3.dec.com>
23 * "DHRYSTONE" Benchmark Program
24 * -----------------------------
26 * Version: C, Version 2.1
28 * File: dhry_1.c (part 2 of 3)
32 * Author: Reinhold P. Weicker
34 ***************************************************************************/
35 char SCCSid
[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
43 unsigned long Run_Index
;
45 Enumeration
Func_1(Capital_Letter
, Capital_Letter
);
49 fprintf(stderr
,"COUNT|%ld|1|lps\n", Run_Index
);
53 /* Global Variables: */
62 int Arr_2_Glob
[50] [50];
68 /* REG becomes defined as empty */
69 /* i.e. no register variables */
74 /* variables for time measurement: */
79 /* see library function "times" */
80 #define Too_Small_Time 120
81 /* Measurements should last at least about 2 seconds */
84 #define Too_Small_Time 2
85 /* Measurements should last at least 2 seconds */
92 Dhrystones_Per_Second
;
94 /* end of variables for time measurement */
96 void Proc_1 (REG Rec_Pointer Ptr_Val_Par
);
97 void Proc_2 (One_Fifty
*Int_Par_Ref
);
98 void Proc_3 (Rec_Pointer
*Ptr_Ref_Par
);
103 extern Boolean
Func_2(Str_30
, Str_30
);
104 extern void Proc_6(Enumeration
, Enumeration
*);
105 extern void Proc_7(One_Fifty
, One_Fifty
, One_Fifty
*);
106 extern void Proc_8(Arr_1_Dim
, Arr_2_Dim
, int, int);
108 int main (int argc
, char *argv
[])
109 /* main program, corresponds to procedures */
110 /* Main and Proc_0 in the Ada version */
114 REG One_Fifty Int_2_Loc
;
117 Enumeration Enum_Loc
;
121 /* Initializations */
123 Next_Ptr_Glob
= (Rec_Pointer
) malloc (sizeof (Rec_Type
));
124 Ptr_Glob
= (Rec_Pointer
) malloc (sizeof (Rec_Type
));
126 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
127 Ptr_Glob
->Discr
= Ident_1
;
128 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
129 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
130 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
131 "DHRYSTONE PROGRAM, SOME STRING");
132 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
134 Arr_2_Glob
[8][7] = 10;
135 /* Was missing in published program. Without this statement, */
136 /* Arr_2_Glob [8][7] would have an undefined value. */
137 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
138 /* overflow may occur for this array element. */
142 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
146 printf ("Program compiled with 'register' attribute\n");
151 printf ("Program compiled without 'register' attribute\n");
154 printf ("Please give the number of runs through the benchmark: ");
162 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs
);
166 fprintf(stderr
, "Usage: %s duration\n", argv
[0]);
170 duration
= atoi(argv
[1]);
172 wake_me(duration
, report
);
181 Begin_Time
= (long) time_info
.tms_utime
;
184 Begin_Time
= time ( (long *) 0);
186 #endif /* SELF_TIMED */
188 for (Run_Index
= 1; ; ++Run_Index
)
193 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
196 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
198 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
200 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
202 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
204 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
208 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
209 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
212 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
213 /* loop body executed twice */
215 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
216 /* then, not executed */
218 Proc_6 (Ident_1
, &Enum_Loc
);
219 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
220 Int_2_Loc
= Run_Index
;
221 Int_Glob
= Run_Index
;
224 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
225 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
226 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
227 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
228 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
232 } /* loop "for Run_Index" */
240 End_Time
= (long) time_info
.tms_utime
;
243 End_Time
= time ( (long *) 0);
245 #endif /* SELF_TIMED */
247 /* BYTE version never executes this stuff */
249 printf ("Execution ends\n");
251 printf ("Final values of the variables used in the benchmark:\n");
253 printf ("Int_Glob: %d\n", Int_Glob
);
254 printf (" should be: %d\n", 5);
255 printf ("Bool_Glob: %d\n", Bool_Glob
);
256 printf (" should be: %d\n", 1);
257 printf ("Ch_1_Glob: %c\n", Ch_1_Glob
);
258 printf (" should be: %c\n", 'A');
259 printf ("Ch_2_Glob: %c\n", Ch_2_Glob
);
260 printf (" should be: %c\n", 'B');
261 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
262 printf (" should be: %d\n", 7);
263 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
264 printf (" should be: Number_Of_Runs + 10\n");
265 printf ("Ptr_Glob->\n");
266 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob
->Ptr_Comp
);
267 printf (" should be: (implementation-dependent)\n");
268 printf (" Discr: %d\n", Ptr_Glob
->Discr
);
269 printf (" should be: %d\n", 0);
270 printf (" Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
271 printf (" should be: %d\n", 2);
272 printf (" Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
273 printf (" should be: %d\n", 17);
274 printf (" Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
275 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
276 printf ("Next_Ptr_Glob->\n");
277 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob
->Ptr_Comp
);
278 printf (" should be: (implementation-dependent), same as above\n");
279 printf (" Discr: %d\n", Next_Ptr_Glob
->Discr
);
280 printf (" should be: %d\n", 0);
281 printf (" Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
282 printf (" should be: %d\n", 1);
283 printf (" Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
284 printf (" should be: %d\n", 18);
285 printf (" Str_Comp: %s\n",
286 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
287 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
288 printf ("Int_1_Loc: %d\n", Int_1_Loc
);
289 printf (" should be: %d\n", 5);
290 printf ("Int_2_Loc: %d\n", Int_2_Loc
);
291 printf (" should be: %d\n", 13);
292 printf ("Int_3_Loc: %d\n", Int_3_Loc
);
293 printf (" should be: %d\n", 7);
294 printf ("Enum_Loc: %d\n", Enum_Loc
);
295 printf (" should be: %d\n", 1);
296 printf ("Str_1_Loc: %s\n", Str_1_Loc
);
297 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
298 printf ("Str_2_Loc: %s\n", Str_2_Loc
);
299 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
302 User_Time
= End_Time
- Begin_Time
;
304 if (User_Time
< Too_Small_Time
)
306 printf ("Measured time too small to obtain meaningful results\n");
307 printf ("Please increase number of runs\n");
313 Microseconds
= (float) User_Time
* Mic_secs_Per_Second
314 / (float) Number_Of_Runs
;
315 Dhrystones_Per_Second
= (float) Number_Of_Runs
/ (float) User_Time
;
317 Microseconds
= (float) User_Time
* Mic_secs_Per_Second
318 / ((float) HZ
* ((float) Number_Of_Runs
));
319 Dhrystones_Per_Second
= ((float) HZ
* (float) Number_Of_Runs
)
322 printf ("Microseconds for one run through Dhrystone: ");
323 printf ("%6.1f \n", Microseconds
);
324 printf ("Dhrystones per Second: ");
325 printf ("%6.1f \n", Dhrystones_Per_Second
);
328 #endif /* SELF_TIMED */
332 void Proc_1 (REG Rec_Pointer Ptr_Val_Par
)
335 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
336 /* == Ptr_Glob_Next */
337 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
338 /* corresponds to "rename" in Ada, "with" in Pascal */
340 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
341 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
342 Next_Record
->variant
.var_1
.Int_Comp
343 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
344 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
345 Proc_3 (&Next_Record
->Ptr_Comp
);
346 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
347 == Ptr_Glob->Ptr_Comp */
348 if (Next_Record
->Discr
== Ident_1
)
351 Next_Record
->variant
.var_1
.Int_Comp
= 6;
352 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
353 &Next_Record
->variant
.var_1
.Enum_Comp
);
354 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
355 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
356 &Next_Record
->variant
.var_1
.Int_Comp
);
358 else /* not executed */
359 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
363 void Proc_2 (One_Fifty
*Int_Par_Ref
)
365 /* *Int_Par_Ref == 1, becomes 4 */
368 Enumeration Enum_Loc
;
372 Int_Loc
= *Int_Par_Ref
+ 10;
373 do /* executed once */
374 if (Ch_1_Glob
== 'A')
378 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
381 while (Enum_Loc
!= Ident_1
); /* true */
385 void Proc_3 (Rec_Pointer
*Ptr_Ref_Par
)
387 /* Ptr_Ref_Par becomes Ptr_Glob */
389 if (Ptr_Glob
!= Null
)
391 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
392 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
396 void Proc_4 (void) /* without parameters */
401 Bool_Loc
= Ch_1_Glob
== 'A';
402 Bool_Glob
= Bool_Loc
| Bool_Glob
;
406 void Proc_5 (void) /* without parameters */
415 /* Procedure for the assignment of structures, */
416 /* if the C compiler doesn't support this feature */
417 #ifdef NOSTRUCTASSIGN
423 while (l
--) *d
++ = *s
++;