forget difference between big and small commands - obsolete with vm.
[minix.git] / test / benchmarks / unixbench-5.1.2 / src / dhry_1.c
blob14f9b8df9cd1b42163340ee275d7a4bab7584636
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
15 * to other versions.
17 * Modification Log:
18 * 10/22/97 - code cleanup to remove ANSI C compiler warnings
19 * Andy Kahn <kahn@zk3.dec.com>
21 * Adapted from:
23 * "DHRYSTONE" Benchmark Program
24 * -----------------------------
26 * Version: C, Version 2.1
28 * File: dhry_1.c (part 2 of 3)
30 * Date: May 25, 1988
32 * Author: Reinhold P. Weicker
34 ***************************************************************************/
35 char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include "dhry.h"
41 #include "timeit.c"
43 unsigned long Run_Index;
45 Enumeration Func_1(Capital_Letter, Capital_Letter);
47 void report(int sig)
49 fprintf(stderr,"COUNT|%ld|1|lps\n", Run_Index);
50 exit(0);
53 /* Global Variables: */
55 Rec_Pointer Ptr_Glob,
56 Next_Ptr_Glob;
57 int Int_Glob;
58 Boolean Bool_Glob;
59 char Ch_1_Glob,
60 Ch_2_Glob;
61 int Arr_1_Glob [50];
62 int Arr_2_Glob [50] [50];
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
74 /* variables for time measurement: */
76 #ifdef TIMES
77 struct tms time_info;
78 extern int times ();
79 /* see library function "times" */
80 #define Too_Small_Time 120
81 /* Measurements should last at least about 2 seconds */
82 #endif
83 #ifdef TIME
84 #define Too_Small_Time 2
85 /* Measurements should last at least 2 seconds */
86 #endif
88 long Begin_Time,
89 End_Time,
90 User_Time;
91 float Microseconds,
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);
99 void Proc_4 (void);
100 void Proc_5 (void);
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 */
112 int duration;
113 One_Fifty Int_1_Loc;
114 REG One_Fifty Int_2_Loc;
115 One_Fifty Int_3_Loc;
116 REG char Ch_Index;
117 Enumeration Enum_Loc;
118 Str_30 Str_1_Loc;
119 Str_30 Str_2_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. */
140 #ifdef PRATTLE
141 printf ("\n");
142 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
143 printf ("\n");
144 if (Reg)
146 printf ("Program compiled with 'register' attribute\n");
147 printf ("\n");
149 else
151 printf ("Program compiled without 'register' attribute\n");
152 printf ("\n");
154 printf ("Please give the number of runs through the benchmark: ");
156 int n;
157 scanf ("%d", &n);
158 Number_Of_Runs = n;
160 printf ("\n");
162 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
163 #endif /* PRATTLE */
165 if (argc != 2) {
166 fprintf(stderr, "Usage: %s duration\n", argv[0]);
167 exit(1);
170 duration = atoi(argv[1]);
171 Run_Index = 0;
172 wake_me(duration, report);
174 /***************/
175 /* Start timer */
176 /***************/
178 #ifdef SELF_TIMED
179 #ifdef TIMES
180 times (&time_info);
181 Begin_Time = (long) time_info.tms_utime;
182 #endif
183 #ifdef TIME
184 Begin_Time = time ( (long *) 0);
185 #endif
186 #endif /* SELF_TIMED */
188 for (Run_Index = 1; ; ++Run_Index)
191 Proc_5();
192 Proc_4();
193 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
194 Int_1_Loc = 2;
195 Int_2_Loc = 3;
196 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
197 Enum_Loc = Ident_2;
198 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
199 /* Bool_Glob == 1 */
200 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
202 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
203 /* Int_3_Loc == 7 */
204 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
205 /* Int_3_Loc == 7 */
206 Int_1_Loc += 1;
207 } /* while */
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);
210 /* Int_Glob == 5 */
211 Proc_1 (Ptr_Glob);
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 */
229 Proc_2 (&Int_1_Loc);
230 /* Int_1_Loc == 5 */
232 } /* loop "for Run_Index" */
234 /**************/
235 /* Stop timer */
236 /**************/
237 #ifdef SELF_TIMED
238 #ifdef TIMES
239 times (&time_info);
240 End_Time = (long) time_info.tms_utime;
241 #endif
242 #ifdef TIME
243 End_Time = time ( (long *) 0);
244 #endif
245 #endif /* SELF_TIMED */
247 /* BYTE version never executes this stuff */
248 #ifdef SELF_TIMED
249 printf ("Execution ends\n");
250 printf ("\n");
251 printf ("Final values of the variables used in the benchmark:\n");
252 printf ("\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");
300 printf ("\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");
308 printf ("\n");
310 else
312 #ifdef TIME
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;
316 #else
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)
320 / (float) User_Time;
321 #endif
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);
326 printf ("\n");
328 #endif /* SELF_TIMED */
332 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
333 /* executed once */
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)
349 /* then, executed */
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);
360 } /* Proc_1 */
363 void Proc_2 (One_Fifty *Int_Par_Ref)
364 /* executed once */
365 /* *Int_Par_Ref == 1, becomes 4 */
367 One_Fifty Int_Loc;
368 Enumeration Enum_Loc;
370 Enum_Loc = 0;
372 Int_Loc = *Int_Par_Ref + 10;
373 do /* executed once */
374 if (Ch_1_Glob == 'A')
375 /* then, executed */
377 Int_Loc -= 1;
378 *Int_Par_Ref = Int_Loc - Int_Glob;
379 Enum_Loc = Ident_1;
380 } /* if */
381 while (Enum_Loc != Ident_1); /* true */
382 } /* Proc_2 */
385 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
386 /* executed once */
387 /* Ptr_Ref_Par becomes Ptr_Glob */
389 if (Ptr_Glob != Null)
390 /* then, executed */
391 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
392 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
393 } /* Proc_3 */
396 void Proc_4 (void) /* without parameters */
397 /* executed once */
399 Boolean Bool_Loc;
401 Bool_Loc = Ch_1_Glob == 'A';
402 Bool_Glob = Bool_Loc | Bool_Glob;
403 Ch_2_Glob = 'B';
404 } /* Proc_4 */
406 void Proc_5 (void) /* without parameters */
407 /*******/
408 /* executed once */
410 Ch_1_Glob = 'A';
411 Bool_Glob = false;
412 } /* Proc_5 */
415 /* Procedure for the assignment of structures, */
416 /* if the C compiler doesn't support this feature */
417 #ifdef NOSTRUCTASSIGN
418 memcpy (d, s, l)
419 register char *d;
420 register char *s;
421 register int l;
423 while (l--) *d++ = *s++;
425 #endif