Remove smips/host-debugging cruft
[riscv-tests.git] / benchmarks / dhrystone / dhrystone_main.c
1 // See LICENSE for license details.
2
3 //**************************************************************************
4 // Dhrystone bencmark
5 //--------------------------------------------------------------------------
6 //
7 // This is the classic Dhrystone synthetic integer benchmark.
8 //
9
10 #pragma GCC optimize ("no-inline")
11
12 #include "dhrystone.h"
13
14 void debug_printf(const char* str, ...);
15
16 #include "util.h"
17
18 #include <alloca.h>
19
20 /* Global Variables: */
21
22 Rec_Pointer Ptr_Glob,
23 Next_Ptr_Glob;
24 int Int_Glob;
25 Boolean Bool_Glob;
26 char Ch_1_Glob,
27 Ch_2_Glob;
28 int Arr_1_Glob [50];
29 int Arr_2_Glob [50] [50];
30
31 Enumeration Func_1 ();
32 /* forward declaration necessary since Enumeration may not simply be int */
33
34 #ifndef REG
35 Boolean Reg = false;
36 #define REG
37 /* REG becomes defined as empty */
38 /* i.e. no register variables */
39 #else
40 Boolean Reg = true;
41 #undef REG
42 #define REG register
43 #endif
44
45 Boolean Done;
46
47 long Begin_Time,
48 End_Time,
49 User_Time;
50 long Microseconds,
51 Dhrystones_Per_Second;
52
53 /* end of variables for time measurement */
54
55
56 int main (int argc, char** argv)
57 /*****/
58 /* main program, corresponds to procedures */
59 /* Main and Proc_0 in the Ada version */
60 {
61 One_Fifty Int_1_Loc;
62 REG One_Fifty Int_2_Loc;
63 One_Fifty Int_3_Loc;
64 REG char Ch_Index;
65 Enumeration Enum_Loc;
66 Str_30 Str_1_Loc;
67 Str_30 Str_2_Loc;
68 REG int Run_Index;
69 REG int Number_Of_Runs;
70
71 /* Arguments */
72 Number_Of_Runs = NUMBER_OF_RUNS;
73
74 /* Initializations */
75
76 Next_Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type));
77 Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type));
78
79 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
80 Ptr_Glob->Discr = Ident_1;
81 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
82 Ptr_Glob->variant.var_1.Int_Comp = 40;
83 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
84 "DHRYSTONE PROGRAM, SOME STRING");
85 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
86
87 Arr_2_Glob [8][7] = 10;
88 /* Was missing in published program. Without this statement, */
89 /* Arr_2_Glob [8][7] would have an undefined value. */
90 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
91 /* overflow may occur for this array element. */
92
93 debug_printf("\n");
94 debug_printf("Dhrystone Benchmark, Version %s\n", Version);
95 if (Reg)
96 {
97 debug_printf("Program compiled with 'register' attribute\n");
98 }
99 else
100 {
101 debug_printf("Program compiled without 'register' attribute\n");
102 }
103 debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE, HZ);
104 debug_printf("\n");
105
106 Done = false;
107 while (!Done) {
108 debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs);
109
110 /***************/
111 /* Start timer */
112 /***************/
113
114 setStats(1);
115 Start_Timer();
116
117 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
118 {
119
120 Proc_5();
121 Proc_4();
122 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
123 Int_1_Loc = 2;
124 Int_2_Loc = 3;
125 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
126 Enum_Loc = Ident_2;
127 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
128 /* Bool_Glob == 1 */
129 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
130 {
131 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
132 /* Int_3_Loc == 7 */
133 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
134 /* Int_3_Loc == 7 */
135 Int_1_Loc += 1;
136 } /* while */
137 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
138 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
139 /* Int_Glob == 5 */
140 Proc_1 (Ptr_Glob);
141 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
142 /* loop body executed twice */
143 {
144 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
145 /* then, not executed */
146 {
147 Proc_6 (Ident_1, &Enum_Loc);
148 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
149 Int_2_Loc = Run_Index;
150 Int_Glob = Run_Index;
151 }
152 }
153 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
154 Int_2_Loc = Int_2_Loc * Int_1_Loc;
155 Int_1_Loc = Int_2_Loc / Int_3_Loc;
156 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
157 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
158 Proc_2 (&Int_1_Loc);
159 /* Int_1_Loc == 5 */
160
161 } /* loop "for Run_Index" */
162
163 /**************/
164 /* Stop timer */
165 /**************/
166
167 Stop_Timer();
168 setStats(0);
169
170 User_Time = End_Time - Begin_Time;
171
172 if (User_Time < Too_Small_Time)
173 {
174 printf("Measured time too small to obtain meaningful results\n");
175 Number_Of_Runs = Number_Of_Runs * 10;
176 printf("\n");
177 } else Done = true;
178 }
179
180 debug_printf("Final values of the variables used in the benchmark:\n");
181 debug_printf("\n");
182 debug_printf("Int_Glob: %d\n", Int_Glob);
183 debug_printf(" should be: %d\n", 5);
184 debug_printf("Bool_Glob: %d\n", Bool_Glob);
185 debug_printf(" should be: %d\n", 1);
186 debug_printf("Ch_1_Glob: %c\n", Ch_1_Glob);
187 debug_printf(" should be: %c\n", 'A');
188 debug_printf("Ch_2_Glob: %c\n", Ch_2_Glob);
189 debug_printf(" should be: %c\n", 'B');
190 debug_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
191 debug_printf(" should be: %d\n", 7);
192 debug_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
193 debug_printf(" should be: Number_Of_Runs + 10\n");
194 debug_printf("Ptr_Glob->\n");
195 debug_printf(" Ptr_Comp: %d\n", (long) Ptr_Glob->Ptr_Comp);
196 debug_printf(" should be: (implementation-dependent)\n");
197 debug_printf(" Discr: %d\n", Ptr_Glob->Discr);
198 debug_printf(" should be: %d\n", 0);
199 debug_printf(" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
200 debug_printf(" should be: %d\n", 2);
201 debug_printf(" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
202 debug_printf(" should be: %d\n", 17);
203 debug_printf(" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
204 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
205 debug_printf("Next_Ptr_Glob->\n");
206 debug_printf(" Ptr_Comp: %d\n", (long) Next_Ptr_Glob->Ptr_Comp);
207 debug_printf(" should be: (implementation-dependent), same as above\n");
208 debug_printf(" Discr: %d\n", Next_Ptr_Glob->Discr);
209 debug_printf(" should be: %d\n", 0);
210 debug_printf(" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
211 debug_printf(" should be: %d\n", 1);
212 debug_printf(" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
213 debug_printf(" should be: %d\n", 18);
214 debug_printf(" Str_Comp: %s\n",
215 Next_Ptr_Glob->variant.var_1.Str_Comp);
216 debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
217 debug_printf("Int_1_Loc: %d\n", Int_1_Loc);
218 debug_printf(" should be: %d\n", 5);
219 debug_printf("Int_2_Loc: %d\n", Int_2_Loc);
220 debug_printf(" should be: %d\n", 13);
221 debug_printf("Int_3_Loc: %d\n", Int_3_Loc);
222 debug_printf(" should be: %d\n", 7);
223 debug_printf("Enum_Loc: %d\n", Enum_Loc);
224 debug_printf(" should be: %d\n", 1);
225 debug_printf("Str_1_Loc: %s\n", Str_1_Loc);
226 debug_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
227 debug_printf("Str_2_Loc: %s\n", Str_2_Loc);
228 debug_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
229 debug_printf("\n");
230
231
232 Microseconds = ((User_Time / Number_Of_Runs) * Mic_secs_Per_Second) / HZ;
233 Dhrystones_Per_Second = (HZ * Number_Of_Runs) / User_Time;
234
235 printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds);
236 printf("Dhrystones per Second: %ld\n", Dhrystones_Per_Second);
237
238 return 0;
239 }
240
241
242 Proc_1 (Ptr_Val_Par)
243 /******************/
244
245 REG Rec_Pointer Ptr_Val_Par;
246 /* executed once */
247 {
248 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
249 /* == Ptr_Glob_Next */
250 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
251 /* corresponds to "rename" in Ada, "with" in Pascal */
252
253 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
254 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
255 Next_Record->variant.var_1.Int_Comp
256 = Ptr_Val_Par->variant.var_1.Int_Comp;
257 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
258 Proc_3 (&Next_Record->Ptr_Comp);
259 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
260 == Ptr_Glob->Ptr_Comp */
261 if (Next_Record->Discr == Ident_1)
262 /* then, executed */
263 {
264 Next_Record->variant.var_1.Int_Comp = 6;
265 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
266 &Next_Record->variant.var_1.Enum_Comp);
267 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
268 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
269 &Next_Record->variant.var_1.Int_Comp);
270 }
271 else /* not executed */
272 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
273 } /* Proc_1 */
274
275
276 Proc_2 (Int_Par_Ref)
277 /******************/
278 /* executed once */
279 /* *Int_Par_Ref == 1, becomes 4 */
280
281 One_Fifty *Int_Par_Ref;
282 {
283 One_Fifty Int_Loc;
284 Enumeration Enum_Loc;
285
286 Int_Loc = *Int_Par_Ref + 10;
287 do /* executed once */
288 if (Ch_1_Glob == 'A')
289 /* then, executed */
290 {
291 Int_Loc -= 1;
292 *Int_Par_Ref = Int_Loc - Int_Glob;
293 Enum_Loc = Ident_1;
294 } /* if */
295 while (Enum_Loc != Ident_1); /* true */
296 } /* Proc_2 */
297
298
299 Proc_3 (Ptr_Ref_Par)
300 /******************/
301 /* executed once */
302 /* Ptr_Ref_Par becomes Ptr_Glob */
303
304 Rec_Pointer *Ptr_Ref_Par;
305
306 {
307 if (Ptr_Glob != Null)
308 /* then, executed */
309 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
310 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
311 } /* Proc_3 */
312
313
314 Proc_4 () /* without parameters */
315 /*******/
316 /* executed once */
317 {
318 Boolean Bool_Loc;
319
320 Bool_Loc = Ch_1_Glob == 'A';
321 Bool_Glob = Bool_Loc | Bool_Glob;
322 Ch_2_Glob = 'B';
323 } /* Proc_4 */
324
325
326 Proc_5 () /* without parameters */
327 /*******/
328 /* executed once */
329 {
330 Ch_1_Glob = 'A';
331 Bool_Glob = false;
332 } /* Proc_5 */