1 /** Sanatised version of the dhrystone-2.1 test.
3 Modifications Michael Hope <michaelh@earthling.net>
5 This is derrived from the dhrystone-2.1.tar.gz tarball available
6 all over the net. I sourced it from the Red Hat src rpm.
9 * Made it more ANSI compliant.
10 * Changed any array function arguments to pointers to make my
12 * Removed malloc's for a couple of static arrays.
16 * The comment at the start of Func_1 about the input being
17 H, R on the first call is wrong - Func_1 is first called
18 from Func_2 where the input is R, Y. The test still succeeds.
20 I couldnt find a copyright in the original - the most relevent
24 I didn't write the DHRYSTONE benchmark. Rheinhold Weicker did. He has
25 certainly provided us with a useful tool for benchmarking, and is
30 (201) 389-8963 (9-17 EST)
31 (201) 542-3734 (7-9,17-24 EST)
32 ...!uunet!pcrat!rick (normal mail)
33 ...!uunet!pcrat!dry2 (results only)
37 /* Temporary definitions. Remove soon :) */
38 char *strcpy(char *dest, const char *src);
39 void *memcpy(void *dest, const char *src, int wLen);
40 int strcmp(const char *s1, const char *s2);
49 int Arr_2_Glob [50] [50];
51 /* Used instead of malloc() */
52 static Rec_Type _r[2];
54 void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
55 void Proc_2 (One_Fifty *Int_Par_Ref);
58 void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
59 void Proc_8 (int **Arr_1_Par_Ref, int **Arr_2_Par_Ref,
60 int Int_1_Par_Val, int Int_2_Par_Val);
61 void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
62 void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
63 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
64 Boolean Func_2 (char *Str_1_Par_Ref, char *Str_2_Par_Ref);
65 Boolean Func_3 (Enumeration Enum_Par_Val);
67 void printf(const char *format, ...);
73 REG One_Fifty Int_2_Loc;
75 REG Capital_Letter Ch_Index;
80 REG int Number_Of_Runs;
84 Next_Ptr_Glob = &_r[0];
87 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
88 Ptr_Glob->Discr = Ident_1;
89 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
90 Ptr_Glob->variant.var_1.Int_Comp = 40;
92 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
93 "DHRYSTONE PROGRAM, SOME STRING");
94 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
96 Arr_2_Glob [8][7] = 10;
97 /* Was missing in published program. Without this statement, */
98 /* Arr_2_Glob [8][7] would have an undefined value. */
99 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
100 /* overflow may occur for this array element. */
105 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) {
109 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
112 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
115 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
117 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
119 printf("m.1 Executes once.\n");
120 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
123 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
127 printf("m.2 Check above executed once.\n");
128 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
130 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
134 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
135 /* loop body executed twice */
138 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
139 /* then, not executed */
142 Proc_6 (Ident_1, &Enum_Loc);
143 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
144 Int_2_Loc = Run_Index;
145 Int_Glob = Run_Index;
148 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
149 Int_2_Loc = Int_2_Loc * Int_1_Loc;
150 Int_1_Loc = Int_2_Loc / Int_3_Loc;
151 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
152 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
156 printf("Looping.\n");
157 } /* loop "for Run_Index" */
161 printf ("Execution ends\n");
163 printf ("Final values of the variables used in the benchmark:\n");
165 printf ("Int_Glob: %d\n", Int_Glob);
166 printf (" should be: %d\n", 5);
167 printf ("Bool_Glob: %d\n", Bool_Glob);
168 printf (" should be: %d\n", 1);
169 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
170 printf (" should be: %c\n", 'A');
171 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
172 printf (" should be: %c\n", 'B');
173 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
174 printf (" should be: %d\n", 7);
175 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
176 printf (" should be: Number_Of_Runs + 10\n");
177 printf ("Ptr_Glob->\n");
178 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
179 printf (" should be: (implementation-dependent)\n");
180 printf (" Discr: %d\n", Ptr_Glob->Discr);
181 printf (" should be: %d\n", 0);
182 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
183 printf (" should be: %d\n", 2);
184 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
185 printf (" should be: %d\n", 17);
186 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
187 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
188 printf ("Next_Ptr_Glob->\n");
189 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
190 printf (" should be: (implementation-dependent), same as above\n");
191 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
192 printf (" should be: %d\n", 0);
193 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
194 printf (" should be: %d\n", 1);
195 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
196 printf (" should be: %d\n", 18);
197 printf (" Str_Comp: %s\n",
198 Next_Ptr_Glob->variant.var_1.Str_Comp);
199 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
200 printf ("Int_1_Loc: %d\n", Int_1_Loc);
201 printf (" should be: %d\n", 5);
202 printf ("Int_2_Loc: %d\n", Int_2_Loc);
203 printf (" should be: %d\n", 13);
204 printf ("Int_3_Loc: %d\n", Int_3_Loc);
205 printf (" should be: %d\n", 7);
206 printf ("Enum_Loc: %d\n", Enum_Loc);
207 printf (" should be: %d\n", 1);
208 printf ("Str_1_Loc: %s\n", Str_1_Loc);
209 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
210 printf ("Str_2_Loc: %s\n", Str_2_Loc);
211 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
216 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
219 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
220 /* == Ptr_Glob_Next */
221 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
222 /* corresponds to "rename" in Ada, "with" in Pascal */
224 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
225 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
226 Next_Record->variant.var_1.Int_Comp
227 = Ptr_Val_Par->variant.var_1.Int_Comp;
228 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
229 Proc_3 (&Next_Record->Ptr_Comp);
230 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
231 == Ptr_Glob->Ptr_Comp */
232 if (Next_Record->Discr == Ident_1)
235 Next_Record->variant.var_1.Int_Comp = 6;
236 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
237 &Next_Record->variant.var_1.Enum_Comp);
238 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
239 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
240 &Next_Record->variant.var_1.Int_Comp);
242 else /* not executed */
243 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
247 void Proc_2 (One_Fifty *Int_Par_Ref)
250 /* *Int_Par_Ref == 1, becomes 4 */
253 Enumeration Enum_Loc;
255 printf("-> Proc_2\n");
257 Int_Loc = *Int_Par_Ref + 10;
261 if (Ch_1_Glob == 'A')
266 *Int_Par_Ref = Int_Loc - Int_Glob;
270 } while (Enum_Loc != Ident_1); /* true */
271 printf("Proc_2 done.\n");
275 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
278 /* Ptr_Ref_Par becomes Ptr_Glob */
280 if (Ptr_Glob != Null)
282 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
283 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
286 void Proc_4 (void) /* without parameters */
292 printf("-> Proc_4\n");
293 Bool_Loc = Ch_1_Glob == 'A';
294 Bool_Glob = Bool_Loc | Bool_Glob;
296 printf("Expect Ch_1_Glob '%c' == 'A'\n", (char)Ch_1_Glob);
297 printf(" Ch_2_Glob '%c' == 'B'\n", (char)Ch_2_Glob);
298 printf(" Bool_Loc %d == 1\n", (unsigned)Bool_Loc);
299 printf(" Bool_Glob %d == 1\n", (unsigned)Bool_Glob);
303 void Proc_5 () /* without parameters */
311 void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
312 /*********************************/
314 /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
317 *Enum_Ref_Par = Enum_Val_Par;
318 if (! Func_3 (Enum_Val_Par))
319 /* then, not executed */
320 *Enum_Ref_Par = Ident_4;
321 switch (Enum_Val_Par)
324 *Enum_Ref_Par = Ident_1;
329 *Enum_Ref_Par = Ident_1;
330 else *Enum_Ref_Par = Ident_4;
332 case Ident_3: /* executed */
333 *Enum_Ref_Par = Ident_2;
337 *Enum_Ref_Par = Ident_3;
343 /*************************************************/
344 /* executed three times */
345 /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
346 /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
347 /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
348 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val)
350 Capital_Letter Ch_1_Loc;
351 Capital_Letter Ch_2_Loc;
353 printf("-> Func_1\n");
354 printf(" Inputs: Ch_1_Par_Val '%c' == { H, A, B }\n", (char)Ch_1_Par_Val);
355 printf(" Ch_2_Par_Val '%c' == { R, C, C }\n", (char)Ch_2_Par_Val);
357 Ch_1_Loc = Ch_1_Par_Val;
359 if (Ch_2_Loc != Ch_2_Par_Val) {
363 else /* not executed */
365 Ch_1_Glob = Ch_1_Loc;
370 Boolean Func_3 (Enumeration Enum_Par_Val)
371 /***************************/
373 /* Enum_Par_Val == Ident_3 */
375 Enumeration Enum_Loc;
377 Enum_Loc = Enum_Par_Val;
378 if (Enum_Loc == Ident_3)
381 else /* not executed */
385 void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref)
386 /**********************************************/
387 /* executed three times */
388 /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
389 /* Int_Par_Ref becomes 7 */
390 /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
391 /* Int_Par_Ref becomes 17 */
392 /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
393 /* Int_Par_Ref becomes 18 */
397 Int_Loc = Int_1_Par_Val + 2;
398 *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
401 /*void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
402 int Int_1_Par_Val, int Int_2_Par_Val)*/
403 void Proc_8 (int **Arr_1_Par_Ref, int **Arr_2_Par_Ref,
404 int Int_1_Par_Val, int Int_2_Par_Val)
406 REG One_Fifty Int_Index;
407 REG One_Fifty Int_Loc;
409 Int_Loc = Int_1_Par_Val + 5;
410 Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
411 Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
412 Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
413 for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
414 Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
415 Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
416 Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
420 /*********************************************************************/
422 /* Int_Par_Val_1 == 3 */
423 /* Int_Par_Val_2 == 7 */
424 Boolean Func_2 (char *Str_1_Par_Ref, char *Str_2_Par_Ref)
425 /*************************************************/
427 /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
428 /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
430 REG One_Thirty Int_Loc;
431 Capital_Letter Ch_Loc;
433 printf("-> Func_2\n");
434 printf(" Inputs Str_1_Par_Ref \"%s\" = \"DHRYSTONE PROGRAM, 1'ST STRING\"\n", Str_1_Par_Ref);
435 printf(" Str_2_Par_Ref \"%s\" = \"DHRYSTONE PROGRAM, 2'ND STRING\"\n", Str_2_Par_Ref);
439 while (Int_Loc <= 2) {
442 printf(" 2.1 Runs once Int_Loc %u = 2.\n", (unsigned)Int_Loc);
443 /* loop body executed once */
444 a = Str_1_Par_Ref[Int_Loc];
445 b = Str_2_Par_Ref[Int_Loc+1];
446 if (Func_1 (a, b) == Ident_1)
448 if (Func_1 (Str_1_Par_Ref[Int_Loc],
449 Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
453 printf(" 2.3 Then OK.\n");
458 printf(" 2.2 Error.\n");
461 if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
462 /* then, not executed */
465 /* then, not executed */
469 if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
470 /* then, not executed */