1 // See LICENSE for license details.
3 //**************************************************************************
5 //--------------------------------------------------------------------------
7 // This is the classic Dhrystone synthetic integer benchmark.
8 // You should not change anything except the HOST_DEBUG and
9 // PREALLOCATE macros for your timing run.
11 #include "dhrystone.h"
13 //--------------------------------------------------------------------------
16 // Set HOST_DEBUG to 1 if you are going to compile this for a host
17 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
18 // to 0 if you are compiling with the smips-gcc toolchain.
24 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
25 // function before starting stats. If you have instruction/data
26 // caches and you don't want to count the overhead of misses, then
27 // you will need to use preallocation.
33 // Set SET_STATS to 1 if you want to carve out the piece that actually
34 // does the computation.
41 # define do_fprintf fprintf
43 int __attribute__((noinline
)) do_fprintf(FILE* f
, const char* str
, ...)
53 /* Global Variables: */
62 int Arr_2_Glob
[50] [50];
67 /* REG becomes defined as empty */
68 /* i.e. no register variables */
81 Dhrystones_Per_Second
;
83 /* end of variables for time measurement */
86 int main (int argc
, char** argv
)
88 /* main program, corresponds to procedures */
89 /* Main and Proc_0 in the Ada version */
92 REG One_Fifty Int_2_Loc
;
99 REG
int Number_Of_Runs
;
105 do_fprintf (stdout
, "Usage: %s [number of loops]\n", argv
[0]);
110 Number_Of_Runs
= atoi (argv
[1]);
114 Number_Of_Runs
= NUMBER_OF_RUNS
;
116 if (Number_Of_Runs
<= 0)
118 Number_Of_Runs
= NUMBER_OF_RUNS
;
121 /* Initializations */
123 Next_Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
124 Ptr_Glob
= (Rec_Pointer
) alloca (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. */
141 do_fprintf (stdout
, "\n");
142 do_fprintf (stdout
, "Dhrystone Benchmark, Version %s\n", Version
);
145 do_fprintf (stdout
, "Program compiled with 'register' attribute\n");
149 do_fprintf (stdout
, "Program compiled without 'register' attribute\n");
151 do_fprintf (stdout
, "Using %s, HZ=%d\n", CLOCK_TYPE
, HZ
);
152 do_fprintf (stdout
, "\n");
158 do_fprintf (stdout
, "Trying %d runs through Dhrystone:\n", Number_Of_Runs
);
168 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
173 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
176 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
178 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
180 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
182 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
184 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
188 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
189 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
192 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
193 /* loop body executed twice */
195 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
196 /* then, not executed */
198 Proc_6 (Ident_1
, &Enum_Loc
);
199 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
200 Int_2_Loc
= Run_Index
;
201 Int_Glob
= Run_Index
;
204 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
205 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
206 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
207 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
208 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
212 } /* loop "for Run_Index" */
221 User_Time
= End_Time
- Begin_Time
;
223 if (User_Time
< Too_Small_Time
)
225 do_fprintf (stdout
, "Measured time too small to obtain meaningful results\n");
226 Number_Of_Runs
= Number_Of_Runs
* 10;
227 do_fprintf (stdout
, "\n");
231 do_fprintf (stderr
, "Final values of the variables used in the benchmark:\n");
232 do_fprintf (stderr
, "\n");
233 do_fprintf (stderr
, "Int_Glob: %d\n", Int_Glob
);
234 do_fprintf (stderr
, " should be: %d\n", 5);
235 do_fprintf (stderr
, "Bool_Glob: %d\n", Bool_Glob
);
236 do_fprintf (stderr
, " should be: %d\n", 1);
237 do_fprintf (stderr
, "Ch_1_Glob: %c\n", Ch_1_Glob
);
238 do_fprintf (stderr
, " should be: %c\n", 'A');
239 do_fprintf (stderr
, "Ch_2_Glob: %c\n", Ch_2_Glob
);
240 do_fprintf (stderr
, " should be: %c\n", 'B');
241 do_fprintf (stderr
, "Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
242 do_fprintf (stderr
, " should be: %d\n", 7);
243 do_fprintf (stderr
, "Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
244 do_fprintf (stderr
, " should be: Number_Of_Runs + 10\n");
245 do_fprintf (stderr
, "Ptr_Glob->\n");
246 do_fprintf (stderr
, " Ptr_Comp: %d\n", (long) Ptr_Glob
->Ptr_Comp
);
247 do_fprintf (stderr
, " should be: (implementation-dependent)\n");
248 do_fprintf (stderr
, " Discr: %d\n", Ptr_Glob
->Discr
);
249 do_fprintf (stderr
, " should be: %d\n", 0);
250 do_fprintf (stderr
, " Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
251 do_fprintf (stderr
, " should be: %d\n", 2);
252 do_fprintf (stderr
, " Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
253 do_fprintf (stderr
, " should be: %d\n", 17);
254 do_fprintf (stderr
, " Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
255 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, SOME STRING\n");
256 do_fprintf (stderr
, "Next_Ptr_Glob->\n");
257 do_fprintf (stderr
, " Ptr_Comp: %d\n", (long) Next_Ptr_Glob
->Ptr_Comp
);
258 do_fprintf (stderr
, " should be: (implementation-dependent), same as above\n");
259 do_fprintf (stderr
, " Discr: %d\n", Next_Ptr_Glob
->Discr
);
260 do_fprintf (stderr
, " should be: %d\n", 0);
261 do_fprintf (stderr
, " Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
262 do_fprintf (stderr
, " should be: %d\n", 1);
263 do_fprintf (stderr
, " Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
264 do_fprintf (stderr
, " should be: %d\n", 18);
265 do_fprintf (stderr
, " Str_Comp: %s\n",
266 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
267 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, SOME STRING\n");
268 do_fprintf (stderr
, "Int_1_Loc: %d\n", Int_1_Loc
);
269 do_fprintf (stderr
, " should be: %d\n", 5);
270 do_fprintf (stderr
, "Int_2_Loc: %d\n", Int_2_Loc
);
271 do_fprintf (stderr
, " should be: %d\n", 13);
272 do_fprintf (stderr
, "Int_3_Loc: %d\n", Int_3_Loc
);
273 do_fprintf (stderr
, " should be: %d\n", 7);
274 do_fprintf (stderr
, "Enum_Loc: %d\n", Enum_Loc
);
275 do_fprintf (stderr
, " should be: %d\n", 1);
276 do_fprintf (stderr
, "Str_1_Loc: %s\n", Str_1_Loc
);
277 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
278 do_fprintf (stderr
, "Str_2_Loc: %s\n", Str_2_Loc
);
279 do_fprintf (stderr
, " should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
280 do_fprintf (stderr
, "\n");
284 Microseconds
= (float) User_Time
* Mic_secs_Per_Second
285 / ((float) HZ
* ((float) Number_Of_Runs
));
286 Dhrystones_Per_Second
= ((float) HZ
* (float) Number_Of_Runs
)
289 do_fprintf (stdout
, "Microseconds for one run through Dhrystone: ");
290 do_fprintf (stdout
, "%10.1f \n", Microseconds
);
291 do_fprintf (stdout
, "Dhrystones per Second: ");
292 do_fprintf (stdout
, "%10.0f \n", Dhrystones_Per_Second
);
293 do_fprintf (stdout
, "\n");
300 void Proc_1(Rec_Pointer Ptr_Val_Par
)
304 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
305 /* == Ptr_Glob_Next */
306 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
307 /* corresponds to "rename" in Ada, "with" in Pascal */
309 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
310 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
311 Next_Record
->variant
.var_1
.Int_Comp
312 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
313 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
314 Proc_3 (&Next_Record
->Ptr_Comp
);
315 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
316 == Ptr_Glob->Ptr_Comp */
317 if (Next_Record
->Discr
== Ident_1
)
320 Next_Record
->variant
.var_1
.Int_Comp
= 6;
321 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
322 &Next_Record
->variant
.var_1
.Enum_Comp
);
323 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
324 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
325 &Next_Record
->variant
.var_1
.Int_Comp
);
327 else /* not executed */
328 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
332 void Proc_2(int* Int_Par_Ref
)
335 /* *Int_Par_Ref == 1, becomes 4 */
338 Enumeration Enum_Loc
;
340 Int_Loc
= *Int_Par_Ref
+ 10;
341 do /* executed once */
342 if (Ch_1_Glob
== 'A')
346 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
349 while (Enum_Loc
!= Ident_1
); /* true */
353 void Proc_3(Rec_Pointer
* Ptr_Ref_Par
)
356 /* Ptr_Ref_Par becomes Ptr_Glob */
358 if (Ptr_Glob
!= Null
)
360 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
361 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
371 Bool_Loc
= Ch_1_Glob
== 'A';
372 Bool_Glob
= Bool_Loc
| Bool_Glob
;