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