1 //**************************************************************************
3 //--------------------------------------------------------------------------
5 // This is the classic Dhrystone synthetic integer benchmark.
6 // You should not change anything except the HOST_DEBUG and
7 // PREALLOCATE macros for your timing run.
11 //--------------------------------------------------------------------------
14 // Set HOST_DEBUG to 1 if you are going to compile this for a host
15 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
16 // to 0 if you are compiling with the smips-gcc toolchain.
22 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
23 // function before starting stats. If you have instruction/data
24 // caches and you don't want to count the overhead of misses, then
25 // you will need to use preallocation.
31 // Set SET_STATS to 1 if you want to carve out the piece that actually
32 // does the computation.
39 # define do_fprintf fprintf
41 int __attribute__((noinline
)) do_fprintf(FILE* f
, const char* str
, ...)
51 /* Global Variables: */
60 int Arr_2_Glob
[50] [50];
65 /* REG becomes defined as empty */
66 /* i.e. no register variables */
79 Dhrystones_Per_Second
;
81 /* end of variables for time measurement */
84 int main (int argc
, char** argv
)
86 /* main program, corresponds to procedures */
87 /* Main and Proc_0 in the Ada version */
90 REG One_Fifty Int_2_Loc
;
97 REG
int Number_Of_Runs
;
103 do_fprintf (stdout
, "Usage: %s [number of loops]\n", argv
[0]);
108 Number_Of_Runs
= atoi (argv
[1]);
112 Number_Of_Runs
= NUMBER_OF_RUNS
;
114 if (Number_Of_Runs
<= 0)
116 Number_Of_Runs
= NUMBER_OF_RUNS
;
119 /* Initializations */
121 Next_Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
122 Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
124 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
125 Ptr_Glob
->Discr
= Ident_1
;
126 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
127 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
128 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
129 "DHRYSTONE PROGRAM, SOME STRING");
130 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
132 Arr_2_Glob
[8][7] = 10;
133 /* Was missing in published program. Without this statement, */
134 /* Arr_2_Glob [8][7] would have an undefined value. */
135 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
136 /* overflow may occur for this array element. */
139 do_fprintf (stdout
, "\n");
140 do_fprintf (stdout
, "Dhrystone Benchmark, Version %s\n", Version
);
143 do_fprintf (stdout
, "Program compiled with 'register' attribute\n");
147 do_fprintf (stdout
, "Program compiled without 'register' attribute\n");
149 do_fprintf (stdout
, "Using %s, HZ=%d\n", CLOCK_TYPE
, HZ
);
150 do_fprintf (stdout
, "\n");
156 do_fprintf (stdout
, "Trying %d runs through Dhrystone:\n", Number_Of_Runs
);
166 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
171 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
174 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
176 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
178 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
180 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
182 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
186 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
187 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
190 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
191 /* loop body executed twice */
193 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
194 /* then, not executed */
196 Proc_6 (Ident_1
, &Enum_Loc
);
197 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
198 Int_2_Loc
= Run_Index
;
199 Int_Glob
= Run_Index
;
202 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
203 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
204 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
205 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
206 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
210 } /* loop "for Run_Index" */
219 User_Time
= End_Time
- Begin_Time
;
221 if (User_Time
< Too_Small_Time
)
223 do_fprintf (stdout
, "Measured time too small to obtain meaningful results\n");
224 Number_Of_Runs
= Number_Of_Runs
* 10;
225 do_fprintf (stdout
, "\n");
229 do_fprintf (stderr
, "Final values of the variables used in the benchmark:\n");
230 do_fprintf (stderr
, "\n");
231 do_fprintf (stderr
, "Int_Glob: %d\n", Int_Glob
);
232 do_fprintf (stderr
, " should be: %d\n", 5);
233 do_fprintf (stderr
, "Bool_Glob: %d\n", Bool_Glob
);
234 do_fprintf (stderr
, " should be: %d\n", 1);
235 do_fprintf (stderr
, "Ch_1_Glob: %c\n", Ch_1_Glob
);
236 do_fprintf (stderr
, " should be: %c\n", 'A');
237 do_fprintf (stderr
, "Ch_2_Glob: %c\n", Ch_2_Glob
);
238 do_fprintf (stderr
, " should be: %c\n", 'B');
239 do_fprintf (stderr
, "Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
240 do_fprintf (stderr
, " should be: %d\n", 7);
241 do_fprintf (stderr
, "Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
242 do_fprintf (stderr
, " should be: Number_Of_Runs + 10\n");
243 do_fprintf (stderr
, "Ptr_Glob->\n");
244 do_fprintf (stderr
, " Ptr_Comp: %d\n", (long) Ptr_Glob
->Ptr_Comp
);
245 do_fprintf (stderr
, " should be: (implementation-dependent)\n");
246 do_fprintf (stderr
, " Discr: %d\n", Ptr_Glob
->Discr
);
247 do_fprintf (stderr
, " should be: %d\n", 0);
248 do_fprintf (stderr
, " Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
249 do_fprintf (stderr
, " should be: %d\n", 2);
250 do_fprintf (stderr
, " Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
251 do_fprintf (stderr
, " should be: %d\n", 17);
252 do_fprintf (stderr
, " Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
253 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, SOME STRING\n");
254 do_fprintf (stderr
, "Next_Ptr_Glob->\n");
255 do_fprintf (stderr
, " Ptr_Comp: %d\n", (long) Next_Ptr_Glob
->Ptr_Comp
);
256 do_fprintf (stderr
, " should be: (implementation-dependent), same as above\n");
257 do_fprintf (stderr
, " Discr: %d\n", Next_Ptr_Glob
->Discr
);
258 do_fprintf (stderr
, " should be: %d\n", 0);
259 do_fprintf (stderr
, " Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
260 do_fprintf (stderr
, " should be: %d\n", 1);
261 do_fprintf (stderr
, " Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
262 do_fprintf (stderr
, " should be: %d\n", 18);
263 do_fprintf (stderr
, " Str_Comp: %s\n",
264 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
265 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, SOME STRING\n");
266 do_fprintf (stderr
, "Int_1_Loc: %d\n", Int_1_Loc
);
267 do_fprintf (stderr
, " should be: %d\n", 5);
268 do_fprintf (stderr
, "Int_2_Loc: %d\n", Int_2_Loc
);
269 do_fprintf (stderr
, " should be: %d\n", 13);
270 do_fprintf (stderr
, "Int_3_Loc: %d\n", Int_3_Loc
);
271 do_fprintf (stderr
, " should be: %d\n", 7);
272 do_fprintf (stderr
, "Enum_Loc: %d\n", Enum_Loc
);
273 do_fprintf (stderr
, " should be: %d\n", 1);
274 do_fprintf (stderr
, "Str_1_Loc: %s\n", Str_1_Loc
);
275 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
276 do_fprintf (stderr
, "Str_2_Loc: %s\n", Str_2_Loc
);
277 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
278 do_fprintf (stderr
, "\n");
282 Microseconds
= (float) User_Time
* Mic_secs_Per_Second
283 / ((float) HZ
* ((float) Number_Of_Runs
));
284 Dhrystones_Per_Second
= ((float) HZ
* (float) Number_Of_Runs
)
287 do_fprintf (stdout
, "Microseconds for one run through Dhrystone: ");
288 do_fprintf (stdout
, "%10.1f \n", Microseconds
);
289 do_fprintf (stdout
, "Dhrystones per Second: ");
290 do_fprintf (stdout
, "%10.0f \n", Dhrystones_Per_Second
);
291 do_fprintf (stdout
, "\n");
298 void Proc_1(Rec_Pointer Ptr_Val_Par
)
302 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
303 /* == Ptr_Glob_Next */
304 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
305 /* corresponds to "rename" in Ada, "with" in Pascal */
307 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
308 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
309 Next_Record
->variant
.var_1
.Int_Comp
310 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
311 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
312 Proc_3 (&Next_Record
->Ptr_Comp
);
313 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
314 == Ptr_Glob->Ptr_Comp */
315 if (Next_Record
->Discr
== Ident_1
)
318 Next_Record
->variant
.var_1
.Int_Comp
= 6;
319 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
320 &Next_Record
->variant
.var_1
.Enum_Comp
);
321 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
322 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
323 &Next_Record
->variant
.var_1
.Int_Comp
);
325 else /* not executed */
326 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
330 void Proc_2(int* Int_Par_Ref
)
333 /* *Int_Par_Ref == 1, becomes 4 */
336 Enumeration Enum_Loc
;
338 Int_Loc
= *Int_Par_Ref
+ 10;
339 do /* executed once */
340 if (Ch_1_Glob
== 'A')
344 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
347 while (Enum_Loc
!= Ident_1
); /* true */
351 void Proc_3(Rec_Pointer
* Ptr_Ref_Par
)
354 /* Ptr_Ref_Par becomes Ptr_Glob */
356 if (Ptr_Glob
!= Null
)
358 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
359 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
369 Bool_Loc
= Ch_1_Glob
== 'A';
370 Bool_Glob
= Bool_Loc
| Bool_Glob
;