1 /*****************************************************************************
2 * The BYTE UNIX Benchmarks - Release 3
3 * Module: dhry_1.c SID: 3.4 5/15/91 19:30:21
4 *
5 *****************************************************************************
6 * Bug reports, patches, comments, suggestions should be sent to:
7 *
8 * Ben Smith, Rick Grehan or Tom Yager
9 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
10 *
11 *****************************************************************************
12 *
13 * *** WARNING **** With BYTE's modifications applied, results obtained with
14 * ******* this version of the Dhrystone program may not be applicable
15 * to other versions.
16 *
17 * Modification Log:
18 * 10/22/97 - code cleanup to remove ANSI C compiler warnings
19 * Andy Kahn <kahn@zk3.dec.com>
20 *
21 * Adapted from:
22 *
23 * "DHRYSTONE" Benchmark Program
24 * -----------------------------
25 *
26 * Version: C, Version 2.1
27 *
28 * File: dhry_1.c (part 2 of 3)
29 *
30 * Date: May 25, 1988
31 *
32 * Author: Reinhold P. Weicker
33 *
34 ***************************************************************************/
35 char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include "dhry.h"
41 #include "timeit.c"
42
43 unsigned long Run_Index;
44
report()45 void report()
46 {
47 fprintf(stderr,"COUNT|%ld|1|lps\n", Run_Index);
48 exit(0);
49 }
50
51 /* Global Variables: */
52
53 Rec_Pointer Ptr_Glob,
54 Next_Ptr_Glob;
55 int Int_Glob;
56 Boolean Bool_Glob;
57 char Ch_1_Glob,
58 Ch_2_Glob;
59 int Arr_1_Glob [50];
60 int Arr_2_Glob [50] [50];
61
62 Enumeration Func_1 ();
63 /* forward declaration necessary since Enumeration may not simply be int */
64
65 #ifndef REG
66 Boolean Reg = false;
67 #define REG
68 /* REG becomes defined as empty */
69 /* i.e. no register variables */
70 #else
71 Boolean Reg = true;
72 #endif
73
74 /* variables for time measurement: */
75
76 #ifdef TIMES
77 #include <time.h>
78 #include <sys/times.h>
79 #define Too_Small_Time 120
80 /* Measurements should last at least about 2 seconds */
81 #endif
82 #ifdef TIME
83 #include <time.h>
84 #define Too_Small_Time 2
85 /* Measurements should last at least 2 seconds */
86 #endif
87
88 long Begin_Time,
89 End_Time,
90 User_Time;
91 float Microseconds,
92 Dhrystones_Per_Second;
93
94 /* end of variables for time measurement */
95
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);
99 void Proc_4 (void);
100 void Proc_5 (void);
101
102
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);
107
main(argc,argv)108 int main (argc, argv)
109 int argc;
110 char *argv[];
111 /* main program, corresponds to procedures */
112 /* Main and Proc_0 in the Ada version */
113 {
114 int duration;
115 One_Fifty Int_1_Loc;
116 REG One_Fifty Int_2_Loc;
117 One_Fifty Int_3_Loc;
118 REG char Ch_Index;
119 Enumeration Enum_Loc;
120 Str_30 Str_1_Loc;
121 Str_30 Str_2_Loc;
122
123 /* Initializations */
124
125 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
126 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
127
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");
135
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. */
141
142 #ifdef PRATTLE
143 printf ("\n");
144 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
145 printf ("\n");
146 if (Reg)
147 {
148 printf ("Program compiled with 'register' attribute\n");
149 printf ("\n");
150 }
151 else
152 {
153 printf ("Program compiled without 'register' attribute\n");
154 printf ("\n");
155 }
156 printf ("Please give the number of runs through the benchmark: ");
157 {
158 int n;
159 scanf ("%d", &n);
160 Number_Of_Runs = n;
161 }
162 printf ("\n");
163
164 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
165 #endif /* PRATTLE */
166
167 if (argc != 2) {
168 fprintf(stderr, "Usage: %s duration\n", argv[0]);
169 exit(1);
170 }
171
172 duration = atoi(argv[1]);
173 Run_Index = 0;
174 wake_me(duration, report);
175
176 /***************/
177 /* Start timer */
178 /***************/
179
180 #ifdef SELF_TIMED
181 #ifdef TIMES
182 times (&time_info);
183 Begin_Time = (long) time_info.tms_utime;
184 #endif
185 #ifdef TIME
186 Begin_Time = time ( (long *) 0);
187 #endif
188 #endif /* SELF_TIMED */
189
190 for (Run_Index = 1; ; ++Run_Index)
191 {
192
193 Proc_5();
194 Proc_4();
195 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
196 Int_1_Loc = 2;
197 Int_2_Loc = 3;
198 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
199 Enum_Loc = Ident_2;
200 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
201 /* Bool_Glob == 1 */
202 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
203 {
204 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
205 /* Int_3_Loc == 7 */
206 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
207 /* Int_3_Loc == 7 */
208 Int_1_Loc += 1;
209 } /* while */
210 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
211 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
212 /* Int_Glob == 5 */
213 Proc_1 (Ptr_Glob);
214 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
215 /* loop body executed twice */
216 {
217 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
218 /* then, not executed */
219 {
220 Proc_6 (Ident_1, &Enum_Loc);
221 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
222 Int_2_Loc = Run_Index;
223 Int_Glob = Run_Index;
224 }
225 }
226 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
227 Int_2_Loc = Int_2_Loc * Int_1_Loc;
228 Int_1_Loc = Int_2_Loc / Int_3_Loc;
229 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
230 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
231 Proc_2 (&Int_1_Loc);
232 /* Int_1_Loc == 5 */
233
234 } /* loop "for Run_Index" */
235
236 /**************/
237 /* Stop timer */
238 /**************/
239 #ifdef SELF_TIMED
240 #ifdef TIMES
241 times (&time_info);
242 End_Time = (long) time_info.tms_utime;
243 #endif
244 #ifdef TIME
245 End_Time = time ( (long *) 0);
246 #endif
247 #endif /* SELF_TIMED */
248
249 /* BYTE version never executes this stuff */
250 #ifdef SELF_TIMED
251 printf ("Execution ends\n");
252 printf ("\n");
253 printf ("Final values of the variables used in the benchmark:\n");
254 printf ("\n");
255 printf ("Int_Glob: %d\n", Int_Glob);
256 printf (" should be: %d\n", 5);
257 printf ("Bool_Glob: %d\n", Bool_Glob);
258 printf (" should be: %d\n", 1);
259 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
260 printf (" should be: %c\n", 'A');
261 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
262 printf (" should be: %c\n", 'B');
263 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
264 printf (" should be: %d\n", 7);
265 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
266 printf (" should be: Number_Of_Runs + 10\n");
267 printf ("Ptr_Glob->\n");
268 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
269 printf (" should be: (implementation-dependent)\n");
270 printf (" Discr: %d\n", Ptr_Glob->Discr);
271 printf (" should be: %d\n", 0);
272 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
273 printf (" should be: %d\n", 2);
274 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
275 printf (" should be: %d\n", 17);
276 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
277 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
278 printf ("Next_Ptr_Glob->\n");
279 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
280 printf (" should be: (implementation-dependent), same as above\n");
281 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
282 printf (" should be: %d\n", 0);
283 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
284 printf (" should be: %d\n", 1);
285 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
286 printf (" should be: %d\n", 18);
287 printf (" Str_Comp: %s\n",
288 Next_Ptr_Glob->variant.var_1.Str_Comp);
289 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
290 printf ("Int_1_Loc: %d\n", Int_1_Loc);
291 printf (" should be: %d\n", 5);
292 printf ("Int_2_Loc: %d\n", Int_2_Loc);
293 printf (" should be: %d\n", 13);
294 printf ("Int_3_Loc: %d\n", Int_3_Loc);
295 printf (" should be: %d\n", 7);
296 printf ("Enum_Loc: %d\n", Enum_Loc);
297 printf (" should be: %d\n", 1);
298 printf ("Str_1_Loc: %s\n", Str_1_Loc);
299 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
300 printf ("Str_2_Loc: %s\n", Str_2_Loc);
301 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
302 printf ("\n");
303
304 User_Time = End_Time - Begin_Time;
305
306 if (User_Time < Too_Small_Time)
307 {
308 printf ("Measured time too small to obtain meaningful results\n");
309 printf ("Please increase number of runs\n");
310 printf ("\n");
311 }
312 else
313 {
314 #ifdef TIME
315 Microseconds = (float) User_Time * Mic_secs_Per_Second
316 / (float) Number_Of_Runs;
317 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
318 #else
319 Microseconds = (float) User_Time * Mic_secs_Per_Second
320 / ((float) HZ * ((float) Number_Of_Runs));
321 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
322 / (float) User_Time;
323 #endif
324 printf ("Microseconds for one run through Dhrystone: ");
325 printf ("%6.1f \n", Microseconds);
326 printf ("Dhrystones per Second: ");
327 printf ("%6.1f \n", Dhrystones_Per_Second);
328 printf ("\n");
329 }
330 #endif /* SELF_TIMED */
331 }
332
333
Proc_1(REG Rec_Pointer Ptr_Val_Par)334 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
335 /* executed once */
336 {
337 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
338 /* == Ptr_Glob_Next */
339 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
340 /* corresponds to "rename" in Ada, "with" in Pascal */
341
342 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
343 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
344 Next_Record->variant.var_1.Int_Comp
345 = Ptr_Val_Par->variant.var_1.Int_Comp;
346 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
347 Proc_3 (&Next_Record->Ptr_Comp);
348 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
349 == Ptr_Glob->Ptr_Comp */
350 if (Next_Record->Discr == Ident_1)
351 /* then, executed */
352 {
353 Next_Record->variant.var_1.Int_Comp = 6;
354 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
355 &Next_Record->variant.var_1.Enum_Comp);
356 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
357 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
358 &Next_Record->variant.var_1.Int_Comp);
359 }
360 else /* not executed */
361 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
362 } /* Proc_1 */
363
364
Proc_2(One_Fifty * Int_Par_Ref)365 void Proc_2 (One_Fifty *Int_Par_Ref)
366 /* executed once */
367 /* *Int_Par_Ref == 1, becomes 4 */
368 {
369 One_Fifty Int_Loc;
370 Enumeration Enum_Loc;
371
372 Enum_Loc = 0;
373
374 Int_Loc = *Int_Par_Ref + 10;
375 do /* executed once */
376 if (Ch_1_Glob == 'A')
377 /* then, executed */
378 {
379 Int_Loc -= 1;
380 *Int_Par_Ref = Int_Loc - Int_Glob;
381 Enum_Loc = Ident_1;
382 } /* if */
383 while (Enum_Loc != Ident_1); /* true */
384 } /* Proc_2 */
385
386
Proc_3(Rec_Pointer * Ptr_Ref_Par)387 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
388 /* executed once */
389 /* Ptr_Ref_Par becomes Ptr_Glob */
390 {
391 if (Ptr_Glob != Null)
392 /* then, executed */
393 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
394 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
395 } /* Proc_3 */
396
397
Proc_4(void)398 void Proc_4 (void) /* without parameters */
399 /* executed once */
400 {
401 Boolean Bool_Loc;
402
403 Bool_Loc = Ch_1_Glob == 'A';
404 Bool_Glob = Bool_Loc | Bool_Glob;
405 Ch_2_Glob = 'B';
406 } /* Proc_4 */
407
Proc_5(void)408 void Proc_5 (void) /* without parameters */
409 /*******/
410 /* executed once */
411 {
412 Ch_1_Glob = 'A';
413 Bool_Glob = false;
414 } /* Proc_5 */
415
416
417 /* Procedure for the assignment of structures, */
418 /* if the C compiler doesn't support this feature */
419 #ifdef NOSTRUCTASSIGN
memcpy(d,s,l)420 memcpy (d, s, l)
421 register char *d;
422 register char *s;
423 register int l;
424 {
425 while (l--) *d++ = *s++;
426 }
427 #endif
428
429
430