Handle peeling for alignment with masking
[official-gcc.git] / gcc / testsuite / gcc.misc-tests / dhry.c
blobae29a693654ebc2fbebbcbf5bdd6a5db54b0c774
1 /*
2 ****************************************************************************
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
6 *
7 * Version: C, Version 2.1
8 *
9 * File: dhry_1.c (part 2 of 3)
11 * Date: May 25, 1988
13 * Author: Reinhold P. Weicker
15 ****************************************************************************
18 #include "dhry.h"
20 /* Global Variables: */
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];
31 extern char *malloc ();
32 Enumeration Func_1 ();
33 /* forward declaration necessary since Enumeration may not simply be int */
35 #ifndef REG
36 Boolean Reg = false;
37 #define REG
38 /* REG becomes defined as empty */
39 /* i.e. no register variables */
40 #else
41 Boolean Reg = true;
42 #endif
44 /* variables for time measurement: */
47 #ifdef TIMES
48 struct tms time_info;
49 extern int times ();
50 #endif
51 */
53 #ifdef TIME
54 extern long time();
55 #endif
57 #define Too_Small_Time 2
58 /* Measurements should last at least 2 seconds */
60 long Begin_Time,
61 End_Time,
62 User_Time;
63 float Microseconds,
64 Dhrystones_Per_Second;
66 /* end of variables for time measurement */
69 main ()
70 /*****/
72 /* main program, corresponds to procedures */
73 /* Main and Proc_0 in the Ada version */
75 One_Fifty Int_1_Loc;
76 REG One_Fifty Int_2_Loc;
77 One_Fifty Int_3_Loc;
78 REG char Ch_Index;
79 Enumeration Enum_Loc;
80 Str_30 Str_1_Loc;
81 Str_30 Str_2_Loc;
82 REG int Run_Index;
83 REG int Number_Of_Runs;
85 /* Initializations */
87 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
88 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
90 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
91 Ptr_Glob->Discr = Ident_1;
92 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
93 Ptr_Glob->variant.var_1.Int_Comp = 40;
94 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
95 "DHRYSTONE PROGRAM, SOME STRING");
96 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
98 Arr_2_Glob [8][7] = 10;
99 /* Was missing in published program. Without this statement, */
100 /* Arr_2_Glob [8][7] would have an undefined value. */
101 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
102 /* overflow may occur for this array element. */
105 printf ("\n");
106 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
107 printf ("\n");
109 if (Reg)
112 printf ("Program compiled with 'register' attribute\n");
113 printf ("\n");
116 else
119 printf ("Program compiled without 'register' attribute\n");
120 printf ("\n");
124 printf ("Please give the number of runs through the benchmark: ");
127 int n;
129 scanf ("%d", &n);
131 Number_Of_Runs = n=1000;
134 printf ("\n");
136 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
139 /***************/
140 /* Start timer */
141 /***************/
144 #ifdef TIMES
145 times (&time_info);
146 Begin_Time = (long) time_info.tms_utime;
147 #endif
148 #ifdef TIME
149 Begin_Time = time ( (long *) 0);
150 #endif
153 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
156 Proc_5();
157 Proc_4();
158 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
159 Int_1_Loc = 2;
160 Int_2_Loc = 3;
161 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
162 Enum_Loc = Ident_2;
163 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
164 /* Bool_Glob == 1 */
165 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
167 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
168 /* Int_3_Loc == 7 */
169 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
170 /* Int_3_Loc == 7 */
171 Int_1_Loc += 1;
172 } /* while */
173 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
174 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
175 /* Int_Glob == 5 */
176 Proc_1 (Ptr_Glob);
177 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
178 /* loop body executed twice */
180 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
181 /* then, not executed */
183 Proc_6 (Ident_1, &Enum_Loc);
184 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
185 Int_2_Loc = Run_Index;
186 Int_Glob = Run_Index;
189 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
190 Int_2_Loc = Int_2_Loc * Int_1_Loc;
191 Int_1_Loc = Int_2_Loc / Int_3_Loc;
192 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
193 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
194 Proc_2 (&Int_1_Loc);
195 /* Int_1_Loc == 5 */
197 } /* loop "for Run_Index" */
199 /**************/
200 /* Stop timer */
201 /**************/
204 #ifdef TIMES
205 times (&time_info);
206 End_Time = (long) time_info.tms_utime;
207 #endif
208 #ifdef TIME
209 End_Time = time ( (long *) 0);
210 #endif
214 printf ("Execution ends\n");
215 printf ("\n");
216 printf ("Final values of the variables used in the benchmark:\n");
217 printf ("\n");
218 printf ("Int_Glob: %d\n", Int_Glob);
219 printf (" should be: %d\n", 5);
220 printf ("Bool_Glob: %d\n", Bool_Glob);
221 printf (" should be: %d\n", 1);
222 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
223 printf (" should be: %c\n", 'A');
224 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
225 printf (" should be: %c\n", 'B');
226 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
227 printf (" should be: %d\n", 7);
228 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
229 printf (" should be: Number_Of_Runs + 10\n");
230 printf ("Ptr_Glob->\n");
231 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
232 printf (" should be: (implementation-dependent)\n");
233 printf (" Discr: %d\n", Ptr_Glob->Discr);
234 printf (" should be: %d\n", 0);
235 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
236 printf (" should be: %d\n", 2);
237 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
238 printf (" should be: %d\n", 17);
239 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
240 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
241 printf ("Next_Ptr_Glob->\n");
242 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
243 printf (" should be: (implementation-dependent), same as above\n");
244 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
245 printf (" should be: %d\n", 0);
246 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
247 printf (" should be: %d\n", 1);
248 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
249 printf (" should be: %d\n", 18);
250 printf (" Str_Comp: %s\n",
251 Next_Ptr_Glob->variant.var_1.Str_Comp);
252 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
253 printf ("Int_1_Loc: %d\n", Int_1_Loc);
254 printf (" should be: %d\n", 5);
255 printf ("Int_2_Loc: %d\n", Int_2_Loc);
256 printf (" should be: %d\n", 13);
257 printf ("Int_3_Loc: %d\n", Int_3_Loc);
258 printf (" should be: %d\n", 7);
259 printf ("Enum_Loc: %d\n", Enum_Loc);
260 printf (" should be: %d\n", 1);
261 printf ("Str_1_Loc: %s\n", Str_1_Loc);
262 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
263 printf ("Str_2_Loc: %s\n", Str_2_Loc);
264 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
265 printf ("\n");
268 User_Time = End_Time - Begin_Time;
270 if (User_Time < Too_Small_Time)
273 printf ("Measured time too small to obtain meaningful results\n");
274 printf ("Please increase number of runs\n");
275 printf ("\n");
278 else
280 #ifdef TIME
282 Microseconds = (float) User_Time * Mic_secs_Per_Second
283 / (float) Number_Of_Runs;
284 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
286 #else
288 Microseconds = (float) User_Time * Mic_secs_Per_Second
289 / ((float) HZ * ((float) Number_Of_Runs));
290 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
291 / (float) User_Time;
293 #endif
295 printf ("Microseconds for one run through Dhrystone: ");
296 printf ("%6.1f \n", Microseconds);
297 printf ("Dhrystones per Second: ");
298 printf ("%6.1f \n", Dhrystones_Per_Second);
299 printf ("\n");
303 exit (0);
307 Proc_1 (Ptr_Val_Par)
308 /******************/
310 REG Rec_Pointer Ptr_Val_Par;
311 /* executed once */
313 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
314 /* == Ptr_Glob_Next */
315 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
316 /* corresponds to "rename" in Ada, "with" in Pascal */
318 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
319 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
320 Next_Record->variant.var_1.Int_Comp
321 = Ptr_Val_Par->variant.var_1.Int_Comp;
322 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
323 Proc_3 (&Next_Record->Ptr_Comp);
324 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
325 == Ptr_Glob->Ptr_Comp */
326 if (Next_Record->Discr == Ident_1)
327 /* then, executed */
329 Next_Record->variant.var_1.Int_Comp = 6;
330 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
331 &Next_Record->variant.var_1.Enum_Comp);
332 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
333 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
334 &Next_Record->variant.var_1.Int_Comp);
336 else /* not executed */
337 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
338 } /* Proc_1 */
341 Proc_2 (Int_Par_Ref)
342 /******************/
343 /* executed once */
344 /* *Int_Par_Ref == 1, becomes 4 */
346 One_Fifty *Int_Par_Ref;
348 One_Fifty Int_Loc;
349 Enumeration Enum_Loc;
351 Int_Loc = *Int_Par_Ref + 10;
352 do /* executed once */
353 if (Ch_1_Glob == 'A')
354 /* then, executed */
356 Int_Loc -= 1;
357 *Int_Par_Ref = Int_Loc - Int_Glob;
358 Enum_Loc = Ident_1;
359 } /* if */
360 while (Enum_Loc != Ident_1); /* true */
361 } /* Proc_2 */
364 Proc_3 (Ptr_Ref_Par)
365 /******************/
366 /* executed once */
367 /* Ptr_Ref_Par becomes Ptr_Glob */
369 Rec_Pointer *Ptr_Ref_Par;
372 if (Ptr_Glob != Null)
373 /* then, executed */
374 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
375 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
376 } /* Proc_3 */
379 Proc_4 () /* without parameters */
380 /*******/
381 /* executed once */
383 Boolean Bool_Loc;
385 Bool_Loc = Ch_1_Glob == 'A';
386 Bool_Glob = Bool_Loc | Bool_Glob;
387 Ch_2_Glob = 'B';
388 } /* Proc_4 */
391 Proc_5 () /* without parameters */
392 /*******/
393 /* executed once */
395 Ch_1_Glob = 'A';
396 Bool_Glob = false;
397 } /* Proc_5 */
400 /* Procedure for the assignment of structures, */
401 /* if the C compiler doesn't support this feature */
402 #ifdef NOSTRUCTASSIGN
403 memcpy (d, s, l)
404 register char *d;
405 register char *s;
406 register int l;
408 while (l--) *d++ = *s++;
410 #endif
414 ****************************************************************************
416 * "DHRYSTONE" Benchmark Program
417 * -----------------------------
419 * Version: C, Version 2.1
421 * File: dhry_2.c (part 3 of 3)
423 * Date: May 25, 1988
425 * Author: Reinhold P. Weicker
427 ****************************************************************************
430 #ifndef REG
431 #define REG
432 /* REG becomes defined as empty */
433 /* i.e. no register variables */
434 #endif
436 extern int Int_Glob;
437 extern char Ch_1_Glob;
440 Proc_6 (Enum_Val_Par, Enum_Ref_Par)
441 /*********************************/
442 /* executed once */
443 /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
445 Enumeration Enum_Val_Par;
446 Enumeration *Enum_Ref_Par;
448 *Enum_Ref_Par = Enum_Val_Par;
449 if (! Func_3 (Enum_Val_Par))
450 /* then, not executed */
451 *Enum_Ref_Par = Ident_4;
452 switch (Enum_Val_Par)
454 case Ident_1:
455 *Enum_Ref_Par = Ident_1;
456 break;
457 case Ident_2:
458 if (Int_Glob > 100)
459 /* then */
460 *Enum_Ref_Par = Ident_1;
461 else *Enum_Ref_Par = Ident_4;
462 break;
463 case Ident_3: /* executed */
464 *Enum_Ref_Par = Ident_2;
465 break;
466 case Ident_4: break;
467 case Ident_5:
468 *Enum_Ref_Par = Ident_3;
469 break;
470 } /* switch */
471 } /* Proc_6 */
474 Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
475 /**********************************************/
476 /* executed three times */
477 /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
478 /* Int_Par_Ref becomes 7 */
479 /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
480 /* Int_Par_Ref becomes 17 */
481 /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
482 /* Int_Par_Ref becomes 18 */
483 One_Fifty Int_1_Par_Val;
484 One_Fifty Int_2_Par_Val;
485 One_Fifty *Int_Par_Ref;
487 One_Fifty Int_Loc;
489 Int_Loc = Int_1_Par_Val + 2;
490 *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
491 } /* Proc_7 */
494 Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
495 /*********************************************************************/
496 /* executed once */
497 /* Int_Par_Val_1 == 3 */
498 /* Int_Par_Val_2 == 7 */
499 Arr_1_Dim Arr_1_Par_Ref;
500 Arr_2_Dim Arr_2_Par_Ref;
501 int Int_1_Par_Val;
502 int Int_2_Par_Val;
504 REG One_Fifty Int_Index;
505 REG One_Fifty Int_Loc;
507 Int_Loc = Int_1_Par_Val + 5;
508 Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
509 Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
510 Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
511 for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
512 Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
513 Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
514 Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
515 Int_Glob = 5;
516 } /* Proc_8 */
519 Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
520 /*************************************************/
521 /* executed three times */
522 /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
523 /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
524 /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
526 Capital_Letter Ch_1_Par_Val;
527 Capital_Letter Ch_2_Par_Val;
529 Capital_Letter Ch_1_Loc;
530 Capital_Letter Ch_2_Loc;
532 Ch_1_Loc = Ch_1_Par_Val;
533 Ch_2_Loc = Ch_1_Loc;
534 if (Ch_2_Loc != Ch_2_Par_Val)
535 /* then, executed */
536 return (Ident_1);
537 else /* not executed */
539 Ch_1_Glob = Ch_1_Loc;
540 return (Ident_2);
542 } /* Func_1 */
545 Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
546 /*************************************************/
547 /* executed once */
548 /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
549 /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
551 Str_30 Str_1_Par_Ref;
552 Str_30 Str_2_Par_Ref;
554 REG One_Thirty Int_Loc;
555 Capital_Letter Ch_Loc;
557 Int_Loc = 2;
558 while (Int_Loc <= 2) /* loop body executed once */
559 if (Func_1 (Str_1_Par_Ref[Int_Loc],
560 Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
561 /* then, executed */
563 Ch_Loc = 'A';
564 Int_Loc += 1;
565 } /* if, while */
566 if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
567 /* then, not executed */
568 Int_Loc = 7;
569 if (Ch_Loc == 'R')
570 /* then, not executed */
571 return (true);
572 else /* executed */
574 if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
575 /* then, not executed */
577 Int_Loc += 7;
578 Int_Glob = Int_Loc;
579 return (true);
581 else /* executed */
582 return (false);
583 } /* if Ch_Loc */
584 } /* Func_2 */
587 Boolean Func_3 (Enum_Par_Val)
588 /***************************/
589 /* executed once */
590 /* Enum_Par_Val == Ident_3 */
591 Enumeration Enum_Par_Val;
593 Enumeration Enum_Loc;
595 Enum_Loc = Enum_Par_Val;
596 if (Enum_Loc == Ident_3)
597 /* then, executed */
598 return (true);
599 else /* not executed */
600 return (false);
601 } /* Func_3 */