modified makefile to allow easier adjustment of build options for different targets...
[AROS-Contrib.git] / Misc / Bench / Dhrystone / dhry21a.c
blob95f6fbc22e054bdbfc776b90fcd1263316758186
1 /*
2 *************************************************************************
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
7 * Version: C, Version 2.1
9 * File: dhry_1.c (part 2 of 3)
11 * Date: May 25, 1988
13 * Author: Reinhold P. Weicker
15 *************************************************************************
18 #include <stdio.h>
19 #include "dhry.h"
21 /* Global Variables: */
23 Rec_Pointer Ptr_Glob,
24 Next_Ptr_Glob;
25 int Int_Glob;
26 Boolean Bool_Glob;
27 char Ch_1_Glob,
28 Ch_2_Glob;
29 int Arr_1_Glob [50];
30 int Arr_2_Glob [50] [50];
32 char Reg_Define[] = "Register option selected.";
34 #ifndef __AROS__
35 extern char *malloc ();
36 #endif
37 Enumeration Func_1 ();
38 /* forward declaration necessary since Enumeration may not simply be int */
41 #ifndef ROPT
42 #define REG
43 /* REG becomes defined as empty */
44 /* i.e. no register variables */
45 #else
46 #define REG register
47 #endif
49 void Proc_1(REG Rec_Pointer);
50 void Proc_2 (One_Fifty *);
51 void Proc_3 (Rec_Pointer *);
52 void Proc_4 (void);
53 void Proc_5 (void);
54 #ifdef NOSTRUCTASSIGN
55 void memcpy (register char *, register char *, register int);
56 #endif
58 extern Boolean Func_2 (Str_30, Str_30);
59 extern void Proc_6 (Enumeration, Enumeration *);
60 extern void Proc_7 (One_Fifty, One_Fifty, One_Fifty *);
61 extern void Proc_8 (Arr_1_Dim, Arr_2_Dim, int, int);
64 /* variables for time measurement: */
66 #define Too_Small_Time 2
67 /* Measurements should last at least 2 seconds */
69 double Begin_Time,
70 End_Time,
71 User_Time;
73 double Microseconds,
74 Dhrystones_Per_Second,
75 Vax_Mips;
77 /* end of variables for time measurement */
80 int
81 main (void)
82 /*****/
84 /* main program, corresponds to procedures */
85 /* Main and Proc_0 in the Ada version */
87 double dtime();
89 One_Fifty Int_1_Loc;
90 REG One_Fifty Int_2_Loc = 0;
91 One_Fifty Int_3_Loc;
92 REG char Ch_Index;
93 Enumeration Enum_Loc;
94 Str_30 Str_1_Loc;
95 Str_30 Str_2_Loc;
96 REG int Run_Index;
97 REG int Number_Of_Runs;
99 FILE *Ap;
101 /* Initializations */
102 #ifdef riscos
103 if ((Ap = fopen("dhry/res","a+")) == NULL)
104 #else
105 if ((Ap = fopen("dhry.res","a+")) == NULL)
106 #endif
108 printf("Can not open dhry.res\n\n");
109 exit(1);
112 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
113 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
115 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
116 Ptr_Glob->Discr = Ident_1;
117 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
118 Ptr_Glob->variant.var_1.Int_Comp = 40;
119 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
120 "DHRYSTONE PROGRAM, SOME STRING");
121 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
123 Arr_2_Glob [8][7] = 10;
124 /* Was missing in published program. Without this statement, */
125 /* Arr_2_Glob [8][7] would have an undefined value. */
126 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
127 /* overflow may occur for this array element. */
129 printf ("\n");
130 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
131 printf ("\n");
133 if (Reg)
135 printf ("Program compiled with 'register' attribute\n");
136 printf ("\n");
138 else
140 printf ("Program compiled without 'register' attribute\n");
141 printf ("\n");
144 printf ("Please give the number of runs through the benchmark: ");
145 fflush(stdout);
147 int n;
148 scanf ("%d", &n);
149 Number_Of_Runs = n;
151 printf ("\n");
153 printf ("Execution starts, %d runs through Dhrystone\n",Number_Of_Runs);
154 fflush(stdout);
155 /***************/
156 /* Start timer */
157 /***************/
159 Begin_Time = dtime();
161 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
164 Proc_5();
165 Proc_4();
166 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
167 Int_1_Loc = 2;
168 Int_2_Loc = 3;
169 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
170 Enum_Loc = Ident_2;
171 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
172 /* Bool_Glob == 1 */
173 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
175 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
176 /* Int_3_Loc == 7 */
177 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
178 /* Int_3_Loc == 7 */
179 Int_1_Loc += 1;
180 } /* while */
181 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
182 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
183 /* Int_Glob == 5 */
184 Proc_1 (Ptr_Glob);
185 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
186 /* loop body executed twice */
188 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
189 /* then, not executed */
191 Proc_6 (Ident_1, &Enum_Loc);
192 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
193 Int_2_Loc = Run_Index;
194 Int_Glob = Run_Index;
197 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
198 Int_2_Loc = Int_2_Loc * Int_1_Loc;
199 Int_1_Loc = Int_2_Loc / Int_3_Loc;
200 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
201 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
202 Proc_2 (&Int_1_Loc);
203 /* Int_1_Loc == 5 */
205 } /* loop "for Run_Index" */
207 /**************/
208 /* Stop timer */
209 /**************/
211 End_Time = dtime();
213 printf ("Execution ends\n");
214 printf ("\n");
215 printf ("Final values of the variables used in the benchmark:\n");
216 printf ("\n");
217 printf ("Int_Glob: %d\n", Int_Glob);
218 printf (" should be: %d\n", 5);
219 printf ("Bool_Glob: %d\n", Bool_Glob);
220 printf (" should be: %d\n", 1);
221 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
222 printf (" should be: %c\n", 'A');
223 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
224 printf (" should be: %c\n", 'B');
225 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
226 printf (" should be: %d\n", 7);
227 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
228 printf (" should be: Number_Of_Runs + 10\n");
229 printf ("Ptr_Glob->\n");
230 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
231 printf (" should be: (implementation-dependent)\n");
232 printf (" Discr: %d\n", Ptr_Glob->Discr);
233 printf (" should be: %d\n", 0);
234 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
235 printf (" should be: %d\n", 2);
236 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
237 printf (" should be: %d\n", 17);
238 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
239 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
240 printf ("Next_Ptr_Glob->\n");
241 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
242 printf (" should be: (implementation-dependent), same as above\n");
243 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
244 printf (" should be: %d\n", 0);
245 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
246 printf (" should be: %d\n", 1);
247 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
248 printf (" should be: %d\n", 18);
249 printf (" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
250 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
251 printf ("Int_1_Loc: %d\n", Int_1_Loc);
252 printf (" should be: %d\n", 5);
253 printf ("Int_2_Loc: %d\n", Int_2_Loc);
254 printf (" should be: %d\n", 13);
255 printf ("Int_3_Loc: %d\n", Int_3_Loc);
256 printf (" should be: %d\n", 7);
257 printf ("Enum_Loc: %d\n", Enum_Loc);
258 printf (" should be: %d\n", 1);
259 printf ("Str_1_Loc: %s\n", Str_1_Loc);
260 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
261 printf ("Str_2_Loc: %s\n", Str_2_Loc);
262 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
263 printf ("\n");
265 User_Time = End_Time - Begin_Time;
267 if (User_Time < Too_Small_Time)
269 printf ("Measured time too small to obtain meaningful results\n");
270 printf ("Please increase number of runs\n");
271 printf ("\n");
273 else
275 Microseconds = User_Time * Mic_secs_Per_Second
276 / (double) Number_Of_Runs;
277 Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
278 Vax_Mips = Dhrystones_Per_Second / 1757.0;
280 #ifdef ROPT
281 printf ("Register option selected? YES\n");
282 #else
283 printf ("Register option selected? NO\n");
284 strcpy(Reg_Define, "Register option not selected.");
285 #endif
286 printf ("Microseconds for one run through Dhrystone: ");
287 printf ("%7.1f \n", Microseconds);
288 printf ("Dhrystones per Second: ");
289 printf ("%10.1f \n", Dhrystones_Per_Second);
290 printf ("VAX MIPS rating = %10.3f \n",Vax_Mips);
291 printf ("\n");
293 fprintf(Ap,"\n");
294 fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n");
295 fprintf(Ap,"%s\n",Reg_Define);
296 fprintf(Ap,"Microseconds for one loop: %7.1f\n",Microseconds);
297 fprintf(Ap,"Dhrystones per second: %10.1f\n",Dhrystones_Per_Second);
298 fprintf(Ap,"VAX MIPS rating: %10.3f\n",Vax_Mips);
299 fclose(Ap);
303 return 0;
307 void
308 Proc_1 (REG Rec_Pointer Ptr_Val_Par)
309 /* executed once */
311 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
312 /* == Ptr_Glob_Next */
313 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
314 /* corresponds to "rename" in Ada, "with" in Pascal */
316 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
317 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
318 Next_Record->variant.var_1.Int_Comp
319 = Ptr_Val_Par->variant.var_1.Int_Comp;
320 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
321 Proc_3 (&Next_Record->Ptr_Comp);
322 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
323 == Ptr_Glob->Ptr_Comp */
324 if (Next_Record->Discr == Ident_1)
325 /* then, executed */
327 Next_Record->variant.var_1.Int_Comp = 6;
328 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
329 &Next_Record->variant.var_1.Enum_Comp);
330 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
331 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
332 &Next_Record->variant.var_1.Int_Comp);
334 else /* not executed */
335 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
336 } /* Proc_1 */
339 void
340 Proc_2 (One_Fifty *Int_Par_Ref)
341 /******************/
342 /* executed once */
343 /* *Int_Par_Ref == 1, becomes 4 */
345 One_Fifty Int_Loc;
346 Enumeration Enum_Loc = Ident_1;
348 Int_Loc = *Int_Par_Ref + 10;
349 do /* executed once */
350 if (Ch_1_Glob == 'A')
351 /* then, executed */
353 Int_Loc -= 1;
354 *Int_Par_Ref = Int_Loc - Int_Glob;
355 Enum_Loc = Ident_1;
356 } /* if */
357 while (Enum_Loc != Ident_1); /* true */
358 } /* Proc_2 */
361 void
362 Proc_3 (Rec_Pointer *Ptr_Ref_Par)
363 /******************/
364 /* executed once */
365 /* Ptr_Ref_Par becomes Ptr_Glob */
367 if (Ptr_Glob != Null)
368 /* then, executed */
369 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
370 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
371 } /* Proc_3 */
374 void
375 Proc_4 (void) /* without parameters */
376 /*******/
377 /* executed once */
379 Boolean Bool_Loc;
381 Bool_Loc = Ch_1_Glob == 'A';
382 Bool_Glob = Bool_Loc | Bool_Glob;
383 Ch_2_Glob = 'B';
384 } /* Proc_4 */
387 void
388 Proc_5 (void) /* without parameters */
389 /* executed once */
391 Ch_1_Glob = 'A';
392 Bool_Glob = false;
393 } /* Proc_5 */
396 /* Procedure for the assignment of structures, */
397 /* if the C compiler doesn't support this feature */
398 #ifdef NOSTRUCTASSIGN
399 void
400 memcpy (register char *d, register char *s, register int l)
401 /* register char *d; register char *s; register int l; */
403 while (l--) *d++ = *s++;
405 #endif