2 * (C) Copyright 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
6 * Dhrystone is widely available in the public domain. A GPL license is
10 /*****************************************************************************
11 * The BYTE UNIX Benchmarks - Release 3
12 * Module: dhry_1.c SID: 3.4 5/15/91 19:30:21
14 *****************************************************************************
15 * Bug reports, patches, comments, suggestions should be sent to:
17 * Ben Smith, Rick Grehan or Tom Yager
18 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
20 *****************************************************************************
22 * *** WARNING **** With BYTE's modifications applied, results obtained with
23 * ******* this version of the Dhrystone program may not be applicable
27 * 10/22/97 - code cleanup to remove ANSI C compiler warnings
28 * Andy Kahn <kahn@zk3.dec.com>
32 * "DHRYSTONE" Benchmark Program
33 * -----------------------------
35 * Version: C, Version 2.1
37 * File: dhry_1.c (part 2 of 3)
41 * Author: Reinhold P. Weicker
43 ***************************************************************************/
44 char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
51 unsigned long Run_Index;
55 printf("%ld loops\n", Run_Index);
58 /* Global Variables: */
67 int Arr_2_Glob [50] [50];
69 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
70 /* forward declaration necessary since Enumeration may not simply be int */
75 /* REG becomes defined as empty */
76 /* i.e. no register variables */
81 /* variables for time measurement: */
84 #define Too_Small_Time 120
85 /* Measurements should last at least about 2 seconds */
89 /* see library function "time" */
90 #define Too_Small_Time 2
91 /* Measurements should last at least 2 seconds */
98 /* end of variables for time measurement */
100 void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
101 void Proc_2 (One_Fifty *Int_Par_Ref);
102 void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
107 extern Boolean Func_2(Str_30, Str_30);
108 extern void Proc_6(Enumeration, Enumeration *);
109 extern void Proc_7(One_Fifty, One_Fifty, One_Fifty *);
110 extern void Proc_8(Arr_1_Dim, Arr_2_Dim, int, int);
112 void dhry(int Number_Of_Runs)
113 /* main program, corresponds to procedures */
114 /* Main and Proc_0 in the Ada version */
117 REG One_Fifty Int_2_Loc;
120 Enumeration Enum_Loc;
124 /* Initializations */
126 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
127 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
129 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
130 Ptr_Glob->Discr = Ident_1;
131 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
132 Ptr_Glob->variant.var_1.Int_Comp = 40;
133 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
134 "DHRYSTONE PROGRAM, SOME STRING");
135 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
137 Arr_2_Glob [8][7] = 10;
138 /* Was missing in published program. Without this statement, */
139 /* Arr_2_Glob [8][7] would have an undefined value. */
140 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
141 /* overflow may occur for this array element. */
145 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
149 printf ("Program compiled with 'register' attribute\n");
154 printf ("Program compiled without 'register' attribute\n");
157 printf ("Please give the number of runs through the benchmark: ");
165 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
177 Begin_Time = (long) time_info.tms_utime;
180 Begin_Time = time ( (long *) 0);
182 #endif /* SELF_TIMED */
184 for (Run_Index = 1; Run_Index < Number_Of_Runs; ++Run_Index)
189 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
192 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
194 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
196 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
198 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
200 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
204 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
205 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
208 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
209 /* loop body executed twice */
211 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
212 /* then, not executed */
214 Proc_6 (Ident_1, &Enum_Loc);
215 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
216 Int_2_Loc = Run_Index;
217 Int_Glob = Run_Index;
220 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
221 Int_2_Loc = Int_2_Loc * Int_1_Loc;
222 Int_1_Loc = Int_2_Loc / Int_3_Loc;
223 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
224 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
228 } /* loop "for Run_Index" */
236 End_Time = (long) time_info.tms_utime;
239 End_Time = time ( (long *) 0);
241 #endif /* SELF_TIMED */
243 /* BYTE version never executes this stuff */
245 printf ("Execution ends\n");
247 printf ("Final values of the variables used in the benchmark:\n");
249 printf ("Int_Glob: %d\n", Int_Glob);
250 printf (" should be: %d\n", 5);
251 printf ("Bool_Glob: %d\n", Bool_Glob);
252 printf (" should be: %d\n", 1);
253 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
254 printf (" should be: %c\n", 'A');
255 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
256 printf (" should be: %c\n", 'B');
257 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
258 printf (" should be: %d\n", 7);
259 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
260 printf (" should be: Number_Of_Runs + 10\n");
261 printf ("Ptr_Glob->\n");
262 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
263 printf (" should be: (implementation-dependent)\n");
264 printf (" Discr: %d\n", Ptr_Glob->Discr);
265 printf (" should be: %d\n", 0);
266 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
267 printf (" should be: %d\n", 2);
268 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
269 printf (" should be: %d\n", 17);
270 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
271 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
272 printf ("Next_Ptr_Glob->\n");
273 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
274 printf (" should be: (implementation-dependent), same as above\n");
275 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
276 printf (" should be: %d\n", 0);
277 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
278 printf (" should be: %d\n", 1);
279 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
280 printf (" should be: %d\n", 18);
281 printf (" Str_Comp: %s\n",
282 Next_Ptr_Glob->variant.var_1.Str_Comp);
283 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
284 printf ("Int_1_Loc: %d\n", Int_1_Loc);
285 printf (" should be: %d\n", 5);
286 printf ("Int_2_Loc: %d\n", Int_2_Loc);
287 printf (" should be: %d\n", 13);
288 printf ("Int_3_Loc: %d\n", Int_3_Loc);
289 printf (" should be: %d\n", 7);
290 printf ("Enum_Loc: %d\n", Enum_Loc);
291 printf (" should be: %d\n", 1);
292 printf ("Str_1_Loc: %s\n", Str_1_Loc);
293 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
294 printf ("Str_2_Loc: %s\n", Str_2_Loc);
295 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
298 User_Time = End_Time - Begin_Time;
300 if (User_Time < Too_Small_Time)
302 printf ("Measured time too small to obtain meaningful results\n");
303 printf ("Please increase number of runs\n");
309 Microseconds = (float) User_Time * Mic_secs_Per_Second
310 / (float) Number_Of_Runs;
311 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
313 Microseconds = (float) User_Time * Mic_secs_Per_Second
314 / ((float) HZ * ((float) Number_Of_Runs));
315 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
318 printf ("Microseconds for one run through Dhrystone: ");
319 printf ("%6.1f \n", Microseconds);
320 printf ("Dhrystones per Second: ");
321 printf ("%6.1f \n", Dhrystones_Per_Second);
324 #endif /* SELF_TIMED */
328 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
331 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
332 /* == Ptr_Glob_Next */
333 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
334 /* corresponds to "rename" in Ada, "with" in Pascal */
336 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
337 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
338 Next_Record->variant.var_1.Int_Comp
339 = Ptr_Val_Par->variant.var_1.Int_Comp;
340 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
341 Proc_3 (&Next_Record->Ptr_Comp);
342 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
343 == Ptr_Glob->Ptr_Comp */
344 if (Next_Record->Discr == Ident_1)
347 Next_Record->variant.var_1.Int_Comp = 6;
348 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
349 &Next_Record->variant.var_1.Enum_Comp);
350 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
351 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
352 &Next_Record->variant.var_1.Int_Comp);
354 else /* not executed */
355 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
359 void Proc_2 (One_Fifty *Int_Par_Ref)
361 /* *Int_Par_Ref == 1, becomes 4 */
364 Enumeration Enum_Loc;
368 Int_Loc = *Int_Par_Ref + 10;
369 do /* executed once */
370 if (Ch_1_Glob == 'A')
374 *Int_Par_Ref = Int_Loc - Int_Glob;
377 while (Enum_Loc != Ident_1); /* true */
381 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
383 /* Ptr_Ref_Par becomes Ptr_Glob */
385 if (Ptr_Glob != Null)
387 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
388 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
392 void Proc_4 (void) /* without parameters */
397 Bool_Loc = Ch_1_Glob == 'A';
398 Bool_Glob = Bool_Loc | Bool_Glob;
402 void Proc_5 (void) /* without parameters */
411 /* Procedure for the assignment of structures, */
412 /* if the C compiler doesn't support this feature */
413 #ifdef NOSTRUCTASSIGN
419 while (l--) *d++ = *s++;