1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
5 * Dhrystone is widely available in the public domain. A GPL license is
9 /*****************************************************************************
10 * The BYTE UNIX Benchmarks - Release 3
11 * Module: dhry_1.c SID: 3.4 5/15/91 19:30:21
13 *****************************************************************************
14 * Bug reports, patches, comments, suggestions should be sent to:
16 * Ben Smith, Rick Grehan or Tom Yager
17 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
19 *****************************************************************************
21 * *** WARNING **** With BYTE's modifications applied, results obtained with
22 * ******* this version of the Dhrystone program may not be applicable
26 * 10/22/97 - code cleanup to remove ANSI C compiler warnings
27 * Andy Kahn <kahn@zk3.dec.com>
31 * "DHRYSTONE" Benchmark Program
32 * -----------------------------
34 * Version: C, Version 2.1
36 * File: dhry_1.c (part 2 of 3)
40 * Author: Reinhold P. Weicker
42 ***************************************************************************/
43 char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
50 unsigned long Run_Index;
54 printf("%ld loops\n", Run_Index);
57 /* Global Variables: */
66 int Arr_2_Glob [50] [50];
68 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
69 /* forward declaration necessary since Enumeration may not simply be int */
74 /* REG becomes defined as empty */
75 /* i.e. no register variables */
80 /* variables for time measurement: */
83 #define Too_Small_Time 120
84 /* Measurements should last at least about 2 seconds */
88 /* see library function "time" */
89 #define Too_Small_Time 2
90 /* Measurements should last at least 2 seconds */
97 /* end of variables for time measurement */
99 void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
100 void Proc_2 (One_Fifty *Int_Par_Ref);
101 void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
106 extern Boolean Func_2(Str_30, Str_30);
107 extern void Proc_6(Enumeration, Enumeration *);
108 extern void Proc_7(One_Fifty, One_Fifty, One_Fifty *);
109 extern void Proc_8(Arr_1_Dim, Arr_2_Dim, int, int);
111 void dhry(int Number_Of_Runs)
112 /* main program, corresponds to procedures */
113 /* Main and Proc_0 in the Ada version */
116 REG One_Fifty Int_2_Loc;
119 Enumeration Enum_Loc;
123 /* Initializations */
125 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
126 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
128 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
129 Ptr_Glob->Discr = Ident_1;
130 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
131 Ptr_Glob->variant.var_1.Int_Comp = 40;
132 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
133 "DHRYSTONE PROGRAM, SOME STRING");
134 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
136 Arr_2_Glob [8][7] = 10;
137 /* Was missing in published program. Without this statement, */
138 /* Arr_2_Glob [8][7] would have an undefined value. */
139 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
140 /* overflow may occur for this array element. */
144 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
148 printf ("Program compiled with 'register' attribute\n");
153 printf ("Program compiled without 'register' attribute\n");
156 printf ("Please give the number of runs through the benchmark: ");
164 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
176 Begin_Time = (long) time_info.tms_utime;
179 Begin_Time = time ( (long *) 0);
181 #endif /* SELF_TIMED */
183 for (Run_Index = 1; Run_Index < Number_Of_Runs; ++Run_Index)
188 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
191 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
193 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
195 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
197 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
199 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
203 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
204 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
207 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
208 /* loop body executed twice */
210 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
211 /* then, not executed */
213 Proc_6 (Ident_1, &Enum_Loc);
214 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
215 Int_2_Loc = Run_Index;
216 Int_Glob = Run_Index;
219 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
220 Int_2_Loc = Int_2_Loc * Int_1_Loc;
221 Int_1_Loc = Int_2_Loc / Int_3_Loc;
222 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
223 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
227 } /* loop "for Run_Index" */
235 End_Time = (long) time_info.tms_utime;
238 End_Time = time ( (long *) 0);
240 #endif /* SELF_TIMED */
242 /* BYTE version never executes this stuff */
244 printf ("Execution ends\n");
246 printf ("Final values of the variables used in the benchmark:\n");
248 printf ("Int_Glob: %d\n", Int_Glob);
249 printf (" should be: %d\n", 5);
250 printf ("Bool_Glob: %d\n", Bool_Glob);
251 printf (" should be: %d\n", 1);
252 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
253 printf (" should be: %c\n", 'A');
254 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
255 printf (" should be: %c\n", 'B');
256 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
257 printf (" should be: %d\n", 7);
258 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
259 printf (" should be: Number_Of_Runs + 10\n");
260 printf ("Ptr_Glob->\n");
261 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
262 printf (" should be: (implementation-dependent)\n");
263 printf (" Discr: %d\n", Ptr_Glob->Discr);
264 printf (" should be: %d\n", 0);
265 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
266 printf (" should be: %d\n", 2);
267 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
268 printf (" should be: %d\n", 17);
269 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
270 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
271 printf ("Next_Ptr_Glob->\n");
272 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
273 printf (" should be: (implementation-dependent), same as above\n");
274 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
275 printf (" should be: %d\n", 0);
276 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
277 printf (" should be: %d\n", 1);
278 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
279 printf (" should be: %d\n", 18);
280 printf (" Str_Comp: %s\n",
281 Next_Ptr_Glob->variant.var_1.Str_Comp);
282 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
283 printf ("Int_1_Loc: %d\n", Int_1_Loc);
284 printf (" should be: %d\n", 5);
285 printf ("Int_2_Loc: %d\n", Int_2_Loc);
286 printf (" should be: %d\n", 13);
287 printf ("Int_3_Loc: %d\n", Int_3_Loc);
288 printf (" should be: %d\n", 7);
289 printf ("Enum_Loc: %d\n", Enum_Loc);
290 printf (" should be: %d\n", 1);
291 printf ("Str_1_Loc: %s\n", Str_1_Loc);
292 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
293 printf ("Str_2_Loc: %s\n", Str_2_Loc);
294 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
297 User_Time = End_Time - Begin_Time;
299 if (User_Time < Too_Small_Time)
301 printf ("Measured time too small to obtain meaningful results\n");
302 printf ("Please increase number of runs\n");
308 Microseconds = (float) User_Time * Mic_secs_Per_Second
309 / (float) Number_Of_Runs;
310 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
312 Microseconds = (float) User_Time * Mic_secs_Per_Second
313 / ((float) HZ * ((float) Number_Of_Runs));
314 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
317 printf ("Microseconds for one run through Dhrystone: ");
318 printf ("%6.1f \n", Microseconds);
319 printf ("Dhrystones per Second: ");
320 printf ("%6.1f \n", Dhrystones_Per_Second);
323 #endif /* SELF_TIMED */
327 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
330 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
331 /* == Ptr_Glob_Next */
332 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
333 /* corresponds to "rename" in Ada, "with" in Pascal */
335 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
336 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
337 Next_Record->variant.var_1.Int_Comp
338 = Ptr_Val_Par->variant.var_1.Int_Comp;
339 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
340 Proc_3 (&Next_Record->Ptr_Comp);
341 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
342 == Ptr_Glob->Ptr_Comp */
343 if (Next_Record->Discr == Ident_1)
346 Next_Record->variant.var_1.Int_Comp = 6;
347 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
348 &Next_Record->variant.var_1.Enum_Comp);
349 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
350 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
351 &Next_Record->variant.var_1.Int_Comp);
353 else /* not executed */
354 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
358 void Proc_2 (One_Fifty *Int_Par_Ref)
360 /* *Int_Par_Ref == 1, becomes 4 */
363 Enumeration Enum_Loc;
367 Int_Loc = *Int_Par_Ref + 10;
368 do /* executed once */
369 if (Ch_1_Glob == 'A')
373 *Int_Par_Ref = Int_Loc - Int_Glob;
376 while (Enum_Loc != Ident_1); /* true */
380 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
382 /* Ptr_Ref_Par becomes Ptr_Glob */
384 if (Ptr_Glob != Null)
386 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
387 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
391 void Proc_4 (void) /* without parameters */
396 Bool_Loc = Ch_1_Glob == 'A';
397 Bool_Glob = Bool_Loc | Bool_Glob;
401 void Proc_5 (void) /* without parameters */
410 /* Procedure for the assignment of structures, */
411 /* if the C compiler doesn't support this feature */
412 #ifdef NOSTRUCTASSIGN
418 while (l--) *d++ = *s++;