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 extern char *malloc ();
64 Enumeration
Func_1 ();
65 /* forward declaration necessary since Enumeration may not simply be int */
70 /* REG becomes defined as empty */
71 /* i.e. no register variables */
84 Dhrystones_Per_Second
;
86 /* end of variables for time measurement */
89 int main (int argc
, char** argv
)
91 /* main program, corresponds to procedures */
92 /* Main and Proc_0 in the Ada version */
95 REG One_Fifty Int_2_Loc
;
102 REG
int Number_Of_Runs
;
108 printf("Usage: %s [number of loops]\n", argv
[0]);
113 Number_Of_Runs
= atoi (argv
[1]);
115 else 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 debug_printf("Dhrystone Benchmark, Version %s\n", Version
);
144 debug_printf("Program compiled with 'register' attribute\n");
148 debug_printf("Program compiled without 'register' attribute\n");
150 debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE
, HZ
);
155 debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs
);
164 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
169 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
172 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
174 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
176 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
178 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
180 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
184 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
185 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
188 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
189 /* loop body executed twice */
191 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
192 /* then, not executed */
194 Proc_6 (Ident_1
, &Enum_Loc
);
195 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
196 Int_2_Loc
= Run_Index
;
197 Int_Glob
= Run_Index
;
200 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
201 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
202 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
203 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
204 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
208 } /* loop "for Run_Index" */
217 User_Time
= End_Time
- Begin_Time
;
219 if (User_Time
< Too_Small_Time
)
221 printf("Measured time too small to obtain meaningful results\n");
222 Number_Of_Runs
= Number_Of_Runs
* 10;
227 debug_printf("Final values of the variables used in the benchmark:\n");
229 debug_printf("Int_Glob: %d\n", Int_Glob
);
230 debug_printf(" should be: %d\n", 5);
231 debug_printf("Bool_Glob: %d\n", Bool_Glob
);
232 debug_printf(" should be: %d\n", 1);
233 debug_printf("Ch_1_Glob: %c\n", Ch_1_Glob
);
234 debug_printf(" should be: %c\n", 'A');
235 debug_printf("Ch_2_Glob: %c\n", Ch_2_Glob
);
236 debug_printf(" should be: %c\n", 'B');
237 debug_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
238 debug_printf(" should be: %d\n", 7);
239 debug_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
240 debug_printf(" should be: Number_Of_Runs + 10\n");
241 debug_printf("Ptr_Glob->\n");
242 debug_printf(" Ptr_Comp: %d\n", (long) Ptr_Glob
->Ptr_Comp
);
243 debug_printf(" should be: (implementation-dependent)\n");
244 debug_printf(" Discr: %d\n", Ptr_Glob
->Discr
);
245 debug_printf(" should be: %d\n", 0);
246 debug_printf(" Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
247 debug_printf(" should be: %d\n", 2);
248 debug_printf(" Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
249 debug_printf(" should be: %d\n", 17);
250 debug_printf(" Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
251 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
252 debug_printf("Next_Ptr_Glob->\n");
253 debug_printf(" Ptr_Comp: %d\n", (long) Next_Ptr_Glob
->Ptr_Comp
);
254 debug_printf(" should be: (implementation-dependent), same as above\n");
255 debug_printf(" Discr: %d\n", Next_Ptr_Glob
->Discr
);
256 debug_printf(" should be: %d\n", 0);
257 debug_printf(" Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
258 debug_printf(" should be: %d\n", 1);
259 debug_printf(" Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
260 debug_printf(" should be: %d\n", 18);
261 debug_printf(" Str_Comp: %s\n",
262 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
263 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
264 debug_printf("Int_1_Loc: %d\n", Int_1_Loc
);
265 debug_printf(" should be: %d\n", 5);
266 debug_printf("Int_2_Loc: %d\n", Int_2_Loc
);
267 debug_printf(" should be: %d\n", 13);
268 debug_printf("Int_3_Loc: %d\n", Int_3_Loc
);
269 debug_printf(" should be: %d\n", 7);
270 debug_printf("Enum_Loc: %d\n", Enum_Loc
);
271 debug_printf(" should be: %d\n", 1);
272 debug_printf("Str_1_Loc: %s\n", Str_1_Loc
);
273 debug_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
274 debug_printf("Str_2_Loc: %s\n", Str_2_Loc
);
275 debug_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
279 Microseconds
= ((User_Time
/ Number_Of_Runs
) * Mic_secs_Per_Second
) / HZ
;
280 Dhrystones_Per_Second
= (HZ
* Number_Of_Runs
) / User_Time
;
282 printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds
);
283 printf("Dhrystones per Second: %ld\n", Dhrystones_Per_Second
);
292 REG Rec_Pointer Ptr_Val_Par
;
295 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
296 /* == Ptr_Glob_Next */
297 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
298 /* corresponds to "rename" in Ada, "with" in Pascal */
300 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
301 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
302 Next_Record
->variant
.var_1
.Int_Comp
303 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
304 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
305 Proc_3 (&Next_Record
->Ptr_Comp
);
306 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
307 == Ptr_Glob->Ptr_Comp */
308 if (Next_Record
->Discr
== Ident_1
)
311 Next_Record
->variant
.var_1
.Int_Comp
= 6;
312 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
313 &Next_Record
->variant
.var_1
.Enum_Comp
);
314 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
315 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
316 &Next_Record
->variant
.var_1
.Int_Comp
);
318 else /* not executed */
319 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
326 /* *Int_Par_Ref == 1, becomes 4 */
328 One_Fifty
*Int_Par_Ref
;
331 Enumeration Enum_Loc
;
333 Int_Loc
= *Int_Par_Ref
+ 10;
334 do /* executed once */
335 if (Ch_1_Glob
== 'A')
339 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
342 while (Enum_Loc
!= Ident_1
); /* true */
349 /* Ptr_Ref_Par becomes Ptr_Glob */
351 Rec_Pointer
*Ptr_Ref_Par
;
354 if (Ptr_Glob
!= Null
)
356 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
357 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
361 Proc_4 () /* without parameters */
367 Bool_Loc
= Ch_1_Glob
== 'A';
368 Bool_Glob
= Bool_Loc
| Bool_Glob
;
373 Proc_5 () /* without parameters */