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
, ...)
55 /* Global Variables: */
64 int Arr_2_Glob
[50] [50];
66 extern char *malloc ();
67 Enumeration
Func_1 ();
68 /* forward declaration necessary since Enumeration may not simply be int */
73 /* REG becomes defined as empty */
74 /* i.e. no register variables */
87 Dhrystones_Per_Second
;
89 /* end of variables for time measurement */
92 int main (int argc
, char** argv
)
94 /* main program, corresponds to procedures */
95 /* Main and Proc_0 in the Ada version */
98 REG One_Fifty Int_2_Loc
;
101 Enumeration Enum_Loc
;
105 REG
int Number_Of_Runs
;
111 printf("Usage: %s [number of loops]\n", argv
[0]);
116 Number_Of_Runs
= atoi (argv
[1]);
118 else if (Number_Of_Runs
<= 0)
121 Number_Of_Runs
= NUMBER_OF_RUNS
;
124 /* Initializations */
126 Next_Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
127 Ptr_Glob
= (Rec_Pointer
) alloca (sizeof (Rec_Type
));
129 Ptr_Glob
->Ptr_Comp
= Next_Ptr_Glob
;
130 Ptr_Glob
->Discr
= Ident_1
;
131 Ptr_Glob
->variant
.var_1
.Enum_Comp
= Ident_3
;
132 Ptr_Glob
->variant
.var_1
.Int_Comp
= 40;
133 strcpy (Ptr_Glob
->variant
.var_1
.Str_Comp
,
134 "DHRYSTONE PROGRAM, SOME STRING");
135 strcpy (Str_1_Loc
, "DHRYSTONE PROGRAM, 1'ST STRING");
137 Arr_2_Glob
[8][7] = 10;
138 /* Was missing in published program. Without this statement, */
139 /* Arr_2_Glob [8][7] would have an undefined value. */
140 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
141 /* overflow may occur for this array element. */
144 debug_printf("Dhrystone Benchmark, Version %s\n", Version
);
147 debug_printf("Program compiled with 'register' attribute\n");
151 debug_printf("Program compiled without 'register' attribute\n");
153 debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE
, HZ
);
158 debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs
);
167 for (Run_Index
= 1; Run_Index
<= Number_Of_Runs
; ++Run_Index
)
172 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
175 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 2'ND STRING");
177 Bool_Glob
= ! Func_2 (Str_1_Loc
, Str_2_Loc
);
179 while (Int_1_Loc
< Int_2_Loc
) /* loop body executed once */
181 Int_3_Loc
= 5 * Int_1_Loc
- Int_2_Loc
;
183 Proc_7 (Int_1_Loc
, Int_2_Loc
, &Int_3_Loc
);
187 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
188 Proc_8 (Arr_1_Glob
, Arr_2_Glob
, Int_1_Loc
, Int_3_Loc
);
191 for (Ch_Index
= 'A'; Ch_Index
<= Ch_2_Glob
; ++Ch_Index
)
192 /* loop body executed twice */
194 if (Enum_Loc
== Func_1 (Ch_Index
, 'C'))
195 /* then, not executed */
197 Proc_6 (Ident_1
, &Enum_Loc
);
198 strcpy (Str_2_Loc
, "DHRYSTONE PROGRAM, 3'RD STRING");
199 Int_2_Loc
= Run_Index
;
200 Int_Glob
= Run_Index
;
203 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
204 Int_2_Loc
= Int_2_Loc
* Int_1_Loc
;
205 Int_1_Loc
= Int_2_Loc
/ Int_3_Loc
;
206 Int_2_Loc
= 7 * (Int_2_Loc
- Int_3_Loc
) - Int_1_Loc
;
207 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
211 } /* loop "for Run_Index" */
220 User_Time
= End_Time
- Begin_Time
;
222 if (User_Time
< Too_Small_Time
)
224 printf("Measured time too small to obtain meaningful results\n");
225 Number_Of_Runs
= Number_Of_Runs
* 10;
230 debug_printf("Final values of the variables used in the benchmark:\n");
232 debug_printf("Int_Glob: %d\n", Int_Glob
);
233 debug_printf(" should be: %d\n", 5);
234 debug_printf("Bool_Glob: %d\n", Bool_Glob
);
235 debug_printf(" should be: %d\n", 1);
236 debug_printf("Ch_1_Glob: %c\n", Ch_1_Glob
);
237 debug_printf(" should be: %c\n", 'A');
238 debug_printf("Ch_2_Glob: %c\n", Ch_2_Glob
);
239 debug_printf(" should be: %c\n", 'B');
240 debug_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob
[8]);
241 debug_printf(" should be: %d\n", 7);
242 debug_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob
[8][7]);
243 debug_printf(" should be: Number_Of_Runs + 10\n");
244 debug_printf("Ptr_Glob->\n");
245 debug_printf(" Ptr_Comp: %d\n", (long) Ptr_Glob
->Ptr_Comp
);
246 debug_printf(" should be: (implementation-dependent)\n");
247 debug_printf(" Discr: %d\n", Ptr_Glob
->Discr
);
248 debug_printf(" should be: %d\n", 0);
249 debug_printf(" Enum_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Enum_Comp
);
250 debug_printf(" should be: %d\n", 2);
251 debug_printf(" Int_Comp: %d\n", Ptr_Glob
->variant
.var_1
.Int_Comp
);
252 debug_printf(" should be: %d\n", 17);
253 debug_printf(" Str_Comp: %s\n", Ptr_Glob
->variant
.var_1
.Str_Comp
);
254 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
255 debug_printf("Next_Ptr_Glob->\n");
256 debug_printf(" Ptr_Comp: %d\n", (long) Next_Ptr_Glob
->Ptr_Comp
);
257 debug_printf(" should be: (implementation-dependent), same as above\n");
258 debug_printf(" Discr: %d\n", Next_Ptr_Glob
->Discr
);
259 debug_printf(" should be: %d\n", 0);
260 debug_printf(" Enum_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Enum_Comp
);
261 debug_printf(" should be: %d\n", 1);
262 debug_printf(" Int_Comp: %d\n", Next_Ptr_Glob
->variant
.var_1
.Int_Comp
);
263 debug_printf(" should be: %d\n", 18);
264 debug_printf(" Str_Comp: %s\n",
265 Next_Ptr_Glob
->variant
.var_1
.Str_Comp
);
266 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
267 debug_printf("Int_1_Loc: %d\n", Int_1_Loc
);
268 debug_printf(" should be: %d\n", 5);
269 debug_printf("Int_2_Loc: %d\n", Int_2_Loc
);
270 debug_printf(" should be: %d\n", 13);
271 debug_printf("Int_3_Loc: %d\n", Int_3_Loc
);
272 debug_printf(" should be: %d\n", 7);
273 debug_printf("Enum_Loc: %d\n", Enum_Loc
);
274 debug_printf(" should be: %d\n", 1);
275 debug_printf("Str_1_Loc: %s\n", Str_1_Loc
);
276 debug_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
277 debug_printf("Str_2_Loc: %s\n", Str_2_Loc
);
278 debug_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
282 Microseconds
= ((User_Time
/ Number_Of_Runs
) * Mic_secs_Per_Second
) / HZ
;
283 Dhrystones_Per_Second
= (HZ
* Number_Of_Runs
) / User_Time
;
285 printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds
);
286 printf("Dhrystones per Second: %ld\n", Dhrystones_Per_Second
);
295 REG Rec_Pointer Ptr_Val_Par
;
298 REG Rec_Pointer Next_Record
= Ptr_Val_Par
->Ptr_Comp
;
299 /* == Ptr_Glob_Next */
300 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
301 /* corresponds to "rename" in Ada, "with" in Pascal */
303 structassign (*Ptr_Val_Par
->Ptr_Comp
, *Ptr_Glob
);
304 Ptr_Val_Par
->variant
.var_1
.Int_Comp
= 5;
305 Next_Record
->variant
.var_1
.Int_Comp
306 = Ptr_Val_Par
->variant
.var_1
.Int_Comp
;
307 Next_Record
->Ptr_Comp
= Ptr_Val_Par
->Ptr_Comp
;
308 Proc_3 (&Next_Record
->Ptr_Comp
);
309 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
310 == Ptr_Glob->Ptr_Comp */
311 if (Next_Record
->Discr
== Ident_1
)
314 Next_Record
->variant
.var_1
.Int_Comp
= 6;
315 Proc_6 (Ptr_Val_Par
->variant
.var_1
.Enum_Comp
,
316 &Next_Record
->variant
.var_1
.Enum_Comp
);
317 Next_Record
->Ptr_Comp
= Ptr_Glob
->Ptr_Comp
;
318 Proc_7 (Next_Record
->variant
.var_1
.Int_Comp
, 10,
319 &Next_Record
->variant
.var_1
.Int_Comp
);
321 else /* not executed */
322 structassign (*Ptr_Val_Par
, *Ptr_Val_Par
->Ptr_Comp
);
329 /* *Int_Par_Ref == 1, becomes 4 */
331 One_Fifty
*Int_Par_Ref
;
334 Enumeration Enum_Loc
;
336 Int_Loc
= *Int_Par_Ref
+ 10;
337 do /* executed once */
338 if (Ch_1_Glob
== 'A')
342 *Int_Par_Ref
= Int_Loc
- Int_Glob
;
345 while (Enum_Loc
!= Ident_1
); /* true */
352 /* Ptr_Ref_Par becomes Ptr_Glob */
354 Rec_Pointer
*Ptr_Ref_Par
;
357 if (Ptr_Glob
!= Null
)
359 *Ptr_Ref_Par
= Ptr_Glob
->Ptr_Comp
;
360 Proc_7 (10, Int_Glob
, &Ptr_Glob
->variant
.var_1
.Int_Comp
);
364 Proc_4 () /* without parameters */
370 Bool_Loc
= Ch_1_Glob
== 'A';
371 Bool_Glob
= Bool_Loc
| Bool_Glob
;
376 Proc_5 () /* without parameters */