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 #pragma GCC optimize ("no-inline")
13 #include "dhrystone.h"
15 //--------------------------------------------------------------------------
18 // Set HOST_DEBUG to 1 if you are going to compile this for a host
19 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
20 // to 0 if you are compiling with the smips-gcc toolchain.
26 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
27 // function before starting stats. If you have instruction/data
28 // caches and you don't want to count the overhead of misses, then
29 // you will need to use preallocation.
35 // Set SET_STATS to 1 if you want to carve out the piece that actually
36 // does the computation.
43 # define debug_printf printf
45 void debug_printf(const char* str
, ...);
52 /* Global Variables: */
61 int Arr_2_Glob
[50] [50];
63 Enumeration
Func_1 ();
64 /* forward declaration necessary since Enumeration may not simply be int */
69 /* REG becomes defined as empty */
70 /* i.e. no register variables */
83 Dhrystones_Per_Second
;
85 /* end of variables for time measurement */
88 int main (int argc
, char** argv
)
90 /* main program, corresponds to procedures */
91 /* Main and Proc_0 in the Ada version */
94 REG One_Fifty Int_2_Loc
;
101 REG
int Number_Of_Runs
;
107 printf("Usage: %s [number of loops]\n", argv
[0]);
112 Number_Of_Runs
= atoi (argv
[1]);
114 else if (Number_Of_Runs
<= 0)
117 Number_Of_Runs
= NUMBER_OF_RUNS
;
120 /* Initializations */
122 Next_Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
123 Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
125 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
126 Ptr_Glob
->Discr
= Ident_1
;
127 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
128 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
129 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
130 "DHRYSTONE PROGRAM, SOME STRING");
131 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
133 Arr_2_Glob
[8][7] = 10;
134 /* Was missing in published program. Without this statement, */
135 /* Arr_2_Glob [8][7] would have an undefined value. */
136 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
137 /* overflow may occur for this array element. */
140 debug_printf("Dhrystone Benchmark, Version %s\n", Version
);
143 debug_printf("Program compiled with 'register' attribute\n");
147 debug_printf("Program compiled without 'register' attribute\n");
149 debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE
, HZ
);
154 debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs
);
163 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
168 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
171 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
173 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
175 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
177 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
179 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
183 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
184 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
187 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
188 /* loop body executed twice */
190 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
191 /* then, not executed */
193 Proc_6 (Ident_1
, &Enum_Loc
);
194 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
195 Int_2_Loc
= Run_Index
;
196 Int_Glob
= Run_Index
;
199 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
200 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
201 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
202 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
203 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
207 } /* loop "for Run_Index" */
216 User_Time
= End_Time
- Begin_Time
;
218 if (User_Time
< Too_Small_Time
)
220 printf("Measured time too small to obtain meaningful results\n");
221 Number_Of_Runs
= Number_Of_Runs
* 10;
226 debug_printf("Final values of the variables used in the benchmark:\n");
228 debug_printf("Int_Glob: %d\n", Int_Glob
);
229 debug_printf(" should be: %d\n", 5);
230 debug_printf("Bool_Glob: %d\n", Bool_Glob
);
231 debug_printf(" should be: %d\n", 1);
232 debug_printf("Ch_1_Glob: %c\n", Ch_1_Glob
);
233 debug_printf(" should be: %c\n", 'A');
234 debug_printf("Ch_2_Glob: %c\n", Ch_2_Glob
);
235 debug_printf(" should be: %c\n", 'B');
236 debug_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
237 debug_printf(" should be: %d\n", 7);
238 debug_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
239 debug_printf(" should be: Number_Of_Runs + 10\n");
240 debug_printf("Ptr_Glob->\n");
241 debug_printf(" Ptr_Comp: %d\n", (long) Ptr_Glob
->Ptr_Comp
);
242 debug_printf(" should be: (implementation-dependent)\n");
243 debug_printf(" Discr: %d\n", Ptr_Glob
->Discr
);
244 debug_printf(" should be: %d\n", 0);
245 debug_printf(" Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
246 debug_printf(" should be: %d\n", 2);
247 debug_printf(" Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
248 debug_printf(" should be: %d\n", 17);
249 debug_printf(" Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
250 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
251 debug_printf("Next_Ptr_Glob->\n");
252 debug_printf(" Ptr_Comp: %d\n", (long) Next_Ptr_Glob
->Ptr_Comp
);
253 debug_printf(" should be: (implementation-dependent), same as above\n");
254 debug_printf(" Discr: %d\n", Next_Ptr_Glob
->Discr
);
255 debug_printf(" should be: %d\n", 0);
256 debug_printf(" Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
257 debug_printf(" should be: %d\n", 1);
258 debug_printf(" Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
259 debug_printf(" should be: %d\n", 18);
260 debug_printf(" Str_Comp: %s\n",
261 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
262 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
263 debug_printf("Int_1_Loc: %d\n", Int_1_Loc
);
264 debug_printf(" should be: %d\n", 5);
265 debug_printf("Int_2_Loc: %d\n", Int_2_Loc
);
266 debug_printf(" should be: %d\n", 13);
267 debug_printf("Int_3_Loc: %d\n", Int_3_Loc
);
268 debug_printf(" should be: %d\n", 7);
269 debug_printf("Enum_Loc: %d\n", Enum_Loc
);
270 debug_printf(" should be: %d\n", 1);
271 debug_printf("Str_1_Loc: %s\n", Str_1_Loc
);
272 debug_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
273 debug_printf("Str_2_Loc: %s\n", Str_2_Loc
);
274 debug_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
278 Microseconds
= ((User_Time
/ Number_Of_Runs
) * Mic_secs_Per_Second
) / HZ
;
279 Dhrystones_Per_Second
= (HZ
* Number_Of_Runs
) / User_Time
;
281 printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds
);
282 printf("Dhrystones per Second: %ld\n", Dhrystones_Per_Second
);
291 REG Rec_Pointer Ptr_Val_Par
;
294 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
295 /* == Ptr_Glob_Next */
296 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
297 /* corresponds to "rename" in Ada, "with" in Pascal */
299 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
300 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
301 Next_Record
->variant
.var_1
.Int_Comp
302 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
303 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
304 Proc_3 (&Next_Record
->Ptr_Comp
);
305 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
306 == Ptr_Glob->Ptr_Comp */
307 if (Next_Record
->Discr
== Ident_1
)
310 Next_Record
->variant
.var_1
.Int_Comp
= 6;
311 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
312 &Next_Record
->variant
.var_1
.Enum_Comp
);
313 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
314 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
315 &Next_Record
->variant
.var_1
.Int_Comp
);
317 else /* not executed */
318 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
325 /* *Int_Par_Ref == 1, becomes 4 */
327 One_Fifty
*Int_Par_Ref
;
330 Enumeration Enum_Loc
;
332 Int_Loc
= *Int_Par_Ref
+ 10;
333 do /* executed once */
334 if (Ch_1_Glob
== 'A')
338 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
341 while (Enum_Loc
!= Ident_1
); /* true */
348 /* Ptr_Ref_Par becomes Ptr_Glob */
350 Rec_Pointer
*Ptr_Ref_Par
;
353 if (Ptr_Glob
!= Null
)
355 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
356 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
360 Proc_4 () /* without parameters */
366 Bool_Loc
= Ch_1_Glob
== 'A';
367 Bool_Glob
= Bool_Loc
| Bool_Glob
;
372 Proc_5 () /* without parameters */