1 // PERMUTE_ARGS:
2 // REQUIRED_ARGS: -release -O -g -inline
3 // DISABLED: freebsd
4 
5 /*
6  *************************************************************************
7  *
8  *                   "DHRYSTONE" Benchmark Program
9  *                   -----------------------------
10  *
11  *  Version:    C, Version 2.1
12  *
13  *  File:       dhry.h (part 1 of 3)
14  *
15  *  Date:       May 25, 1988
16  *
17  *  Author:     Reinhold P. Weicker
18  *              Siemens Nixdorf Inf. Syst.
19  *              STM OS 32
20  *              Otto-Hahn-Ring 6
21  *              W-8000 Muenchen 83
22  *              Germany
23  *                      Phone:    [+49]-89-636-42436
24  *                                (8-17 Central European Time)
25  *                      UUCP:     weicker@ztivax.uucp@unido.uucp
26  *                      Internet: weicker@ztivax.siemens.com
27  *
28  *              Original Version (in Ada) published in
29  *              "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
30  *              pp. 1013 - 1030, together with the statistics
31  *              on which the distribution of statements etc. is based.
32  *
33  *              In this C version, the following C library functions are
34  *              used:
35  *              - strcpy, strcmp (inside the measurement loop)
36  *              - printf, scanf (outside the measurement loop)
37  *
38  *  Collection of Results:
39  *              Reinhold Weicker (address see above) and
40  *
41  *              Rick Richardson
42  *              PC Research. Inc.
43  *              94 Apple Orchard Drive
44  *              Tinton Falls, NJ 07724
45  *                      Phone:  (201) 834-1378 (9-17 EST)
46  *                      UUCP:   ...!uunet!pcrat!rick
47  *
48  *      Please send results to Rick Richardson and/or Reinhold Weicker.
49  *      Complete information should be given on hardware and software
50  *      used. Hardware information includes: Machine type, CPU, type and
51  *      size of caches; for microprocessors: clock frequency, memory speed
52  *      (number of wait states). Software information includes: Compiler
53  *      (and runtime library) manufacturer and version, compilation
54  *      switches, OS version. The Operating System version may give an
55  *      indication about the compiler; Dhrystone itself performs no OS
56  *      calls in the measurement loop.
57  *
58  *      The complete output generated by the program should be mailed
59  *      such that at least some checks for correctness can be made.
60  *
61  *************************************************************************
62  *
63  *  History:    This version C/2.1 has been made for two reasons:
64  *
65  *              1) There is an obvious need for a common C version of
66  *              Dhrystone, since C is at present the most popular system
67  *              programming language for the class of processors
68  *              (microcomputers, minicomputers) where Dhrystone is used
69  *              most. There should be, as far as possible, only one C
70  *              version of Dhrystone such that results can be compared
71  *              without restrictions. In the past, the C versions
72  *              distributed by Rick Richardson (Version 1.1) and by
73  *              Reinhold Weicker had small (though not significant)
74  *              differences.
75  *
76  *              2) As far as it is possible without changes to the
77  *              Dhrystone statistics, optimizing compilers should be
78  *              prevented from removing significant statements.
79  *
80  *              This C version has been developed in cooperation with
81  *              Rick Richardson (Tinton Falls, NJ), it incorporates many
82  *              ideas from the "Version 1.1" distributed previously by
83  *              him over the UNIX network Usenet.
84  *              I also thank Chaim Benedelac (National Semiconductor),
85  *              David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
86  *              Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
87  *              for their help with comments on earlier versions of the
88  *              benchmark.
89  *
90  *  Changes:    In the initialization part, this version follows mostly
91  *              Rick Richardson's version distributed via Usenet, not the
92  *              version distributed earlier via floppy disk by Reinhold
93  *              Weicker. As a concession to older compilers, names have
94  *              been made unique within the first 8 characters. Inside the
95  *              measurement loop, this version follows the version
96  *              previously distributed by Reinhold Weicker.
97  *
98  *              At several places in the benchmark, code has been added,
99  *              but within the measurement loop only in branches that
100  *              are not executed. The intention is that optimizing
101  *              compilers should be prevented from moving code out of the
102  *              measurement loop, or from removing code altogether. Since
103  *              the statements that are executed within the measurement
104  *              loop have NOT been changed, the numbers defining the
105  *              "Dhrystone distribution" (distribution of statements,
106  *              operand types and locality) still hold. Except for
107  *              sophisticated optimizing compilers, execution times for
108  *              this version should be the same as for previous versions.
109  *
110  *              Since it has proven difficult to subtract the time for the
111  *              measurement loop overhead in a correct way, the loop check
112  *              has been made a part of the benchmark. This does have
113  *              an impact - though a very minor one - on the distribution
114  *              statistics which have been updated for this version.
115  *
116  *              All changes within the measurement loop are described
117  *              and discussed in the companion paper "Rationale for
118  *              Dhrystone version 2".
119  *
120  *              Because of the self-imposed limitation that the order and
121  *              distribution of the executed statements should not be
122  *              changed, there are still cases where optimizing compilers
123  *              may not generate code for some statements. To a certain
124  *              degree, this is unavoidable for small synthetic
125  *              benchmarks. Users of the benchmark are advised to check
126  *              code listings whether code is generated for all statements
127  *              of Dhrystone.
128  *
129  *              Version 2.1 is identical to version 2.0 distributed via
130  *              the UNIX network Usenet in March 1988 except that it
131  *              corrects some minor deficiencies that were found by users
132  *              of version 2.0. The only change within the measurement
133  *              loop is that a non-executed "else" part was added to the
134  *              "if" statement in Func_3, and a non-executed "else" part
135  *              removed from Proc_3.
136  *
137  *************************************************************************
138  *
139  * Defines:     The following "Defines" are possible:
140  *              -DROPT         (default: Not defined)
141  *                      As an approximation to what an average C
142  *                      programmer might do, the "register" storage class
143  *                      is applied (if enabled by -DROPT)
144  *                      - for local variables, if they are used
145  *                        (dynamically) five or more times
146  *                      - for parameters if they are used (dynamically)
147  *                        six or more times
148  *                      Note that an optimal "register" strategy is
149  *                      compiler-dependent, and that "register"
150  *                      declarations do not necessarily lead to faster
151  *                      execution.
152  *              -DNOSTRUCTASSIGN        (default: Not defined)
153  *                      Define if the C compiler does not support
154  *                      assignment of structures.
155  *              -DNOENUMS               (default: Not defined)
156  *                      Define if the C compiler does not support
157  *                      enumeration types.
158  *
159  *************************************************************************
160  *
161  *  Compilation model and measurement (IMPORTANT):
162  *
163  *  This C version of Dhrystone consists of three files:
164  *  - dhry.h (this file, containing global definitions and comments)
165  *  - dhry_1.c (containing the code corresponding to Ada package Pack_1)
166  *  - dhry_2.c (containing the code corresponding to Ada package Pack_2)
167  *
168  *  The following "ground rules" apply for measurements:
169  *  - Separate compilation
170  *  - No procedure merging
171  *  - Otherwise, compiler optimizations are allowed but should be
172  *    indicated
173  *  - Default results are those without register declarations
174  *  See the companion paper "Rationale for Dhrystone Version 2" for a more
175  *  detailed discussion of these ground rules.
176  *
177  *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
178  *  models ("small", "medium", "large" etc.) should be given if possible,
179  *  together with a definition of these models for the compiler system
180  *  used.
181  *
182  *************************************************************************
183  *
184  *  Dhrystone (C version) statistics:
185  *
186  *  [Comment from the first distribution, updated for version 2.
187  *   Note that because of language differences, the numbers are slightly
188  *   different from the Ada version.]
189  *
190  *  The following program contains statements of a high level programming
191  *  language (here: C) in a distribution considered representative:
192  *
193  *    assignments                  52 (51.0 %)
194  *    control statements           33 (32.4 %)
195  *    procedure, function calls    17 (16.7 %)
196  *
197  *  103 statements are dynamically executed. The program is balanced with
198  *  respect to the three aspects:
199  *
200  *    - statement type
201  *    - operand type
202  *    - operand locality
203  *         operand global, local, parameter, or constant.
204  *
205  *  The combination of these three aspects is balanced only approximately.
206  *
207  *  1. Statement Type:
208  *  -----------------             number
209  *
210  *     V1 = V2                     9
211  *       (incl. V1 = F(..)
212  *     V = Constant               12
213  *     Assignment,                 7
214  *       with array element
215  *     Assignment,                 6
216  *       with record component
217  *                                --
218  *                                34       34
219  *
220  *     X = Y +|-|"&&"|"|" Z        5
221  *     X = Y +|-|"==" Constant     6
222  *     X = X +|- 1                 3
223  *     X = Y *|/ Z                 2
224  *     X = Expression,             1
225  *           two operators
226  *     X = Expression,             1
227  *           three operators
228  *                                --
229  *                                18       18
230  *
231  *     if ....                    14
232  *       with "else"      7
233  *       without "else"   7
234  *           executed        3
235  *           not executed    4
236  *     for ...                     7  |  counted every time
237  *     while ...                   4  |  the loop condition
238  *     do ... while                1  |  is evaluated
239  *     switch ...                  1
240  *     break                       1
241  *     declaration with            1
242  *       initialization
243  *                                --
244  *                                34       34
245  *
246  *     P (...)  procedure call    11
247  *       user procedure      10
248  *       library procedure    1
249  *     X = F (...)
250  *             function  call      6
251  *       user function        5
252  *       library function     1
253  *                                --
254  *                                17       17
255  *                                        ---
256  *                                        103
257  *
258  *    The average number of parameters in procedure or function calls
259  *    is 1.82 (not counting the function values as implicit parameters).
260  *
261  *
262  *  2. Operators
263  *  ------------
264  *                          number    approximate
265  *                                    percentage
266  *
267  *    Arithmetic             32          50.8
268  *
269  *       +                     21          33.3
270  *       -                      7          11.1
271  *       *                      3           4.8
272  *       / (int div)            1           1.6
273  *
274  *    Comparison             27           42.8
275  *
276  *       ==                     9           14.3
277  *       /=                     4            6.3
278  *       >                      1            1.6
279  *       <                      3            4.8
280  *       >=                     1            1.6
281  *       <=                     9           14.3
282  *
283  *    Logic                   4            6.3
284  *
285  *       && (AND-THEN)          1            1.6
286  *       |  (OR)                1            1.6
287  *       !  (NOT)               2            3.2
288  *
289  *                           --          -----
290  *                           63          100.1
291  *
292  *
293  *  3. Operand Type (counted once per operand reference):
294  *  ---------------
295  *                          number    approximate
296  *                                    percentage
297  *
298  *     Integer               175        72.3 %
299  *     Character              45        18.6 %
300  *     Pointer                12         5.0 %
301  *     String30                6         2.5 %
302  *     Array                   2         0.8 %
303  *     Record                  2         0.8 %
304  *                           ---       -------
305  *                           242       100.0 %
306  *
307  *  When there is an access path leading to the final operand (e.g. a
308  *  record component), only the final data type on the access path is
309  *  counted.
310  *
311  *
312  *  4. Operand Locality:
313  *  -------------------
314  *                                number    approximate
315  *                                          percentage
316  *
317  *     local variable              114        47.1 %
318  *     global variable              22         9.1 %
319  *     parameter                    45        18.6 %
320  *        value                        23         9.5 %
321  *        reference                    22         9.1 %
322  *     function result               6         2.5 %
323  *     constant                     55        22.7 %
324  *                                 ---       -------
325  *                                 242       100.0 %
326  *
327  *
328  *  The program does not compute anything meaningful, but it is
329  *  syntactically and semantically correct. All variables have a value
330  *  assigned to them before they are used as a source operand.
331  *
332  *  There has been no explicit effort to account for the effects of a
333  *  cache, or to balance the use of long or short displacements for code
334  *  or data.
335  *
336  *************************************************************************
337  */
338 
339 import core.stdc.stdio;
340 import core.stdc.string;
341 import core.stdc.stdlib;
342 import std.string;
343 
344 
345 /* Compiler and system dependent definitions: */
346 
347 const double Mic_secs_Per_Second = 1000000.0;
348                 /* Berkeley UNIX C returns process times in seconds/HZ */
349 
350 enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
351 alias int Enumeration;
352         /* for boolean and enumeration types in Ada, Pascal */
353 
354 /* General definitions: */
355 
356 const int StrLen = 30;
357 
358 alias int     One_Thirty;
359 alias int     One_Fifty;
360 alias char    Capital_Letter;
361 alias bool    Boolean;
362 alias char    Str_30 [StrLen];
363 alias int     Arr_1_Dim [50];
364 alias int     Arr_2_Dim [50] [50];
365 
366 struct record
367 {
368     record *Ptr_Comp;
369     Enumeration    Discr;
370     union V {
371           struct V1 {
372                   Enumeration Enum_Comp;
373                   int         Int_Comp;
374                   char        Str_Comp [StrLen];
375                   }
376           V1 var_1;
377           struct V2 {
378                   Enumeration E_Comp_2;
379                   char        Str_2_Comp [StrLen];
380                   }
381           V2 var_2;
382           struct V3 {
383                   char        Ch_1_Comp;
384                   char        Ch_2_Comp;
385                   }
386           V3 var_3;
387           }
388     V variant;
389 }
390 
391 alias record Rec_Type;
392 alias record *Rec_Pointer;
393 
394 
395 /* Global Variables: */
396 
397 Rec_Pointer     Ptr_Glob,
398                 Next_Ptr_Glob;
399 int             Int_Glob;
400 Boolean         Bool_Glob;
401 char            Ch_1_Glob,
402                 Ch_2_Glob;
403 int             Arr_1_Glob [50];
404 int             Arr_2_Glob [50] [50];
405 
406 char[StrLen] Reg_Define = "Register option selected.";
407 
408 /* variables for time measurement: */
409 
410 const int Too_Small_Time = 2;
411                 /* Measurements should last at least 2 seconds */
412 
413 double          Begin_Time,
414                 End_Time,
415                 User_Time;
416 
417 double          Microseconds,
418                 Dhrystones_Per_Second,
419                 Vax_Mips;
420 
421 /* end of variables for time measurement */
422 
423 
main()424 void main ()
425 /*****/
426 
427   /* main program, corresponds to procedures        */
428   /* Main and Proc_0 in the Ada version             */
429 {
430         One_Fifty       Int_1_Loc;
431         One_Fifty       Int_2_Loc;
432         One_Fifty       Int_3_Loc;
433         char            Ch_Index;
434         Enumeration     Enum_Loc;
435         Str_30          Str_1_Loc;
436         Str_30          Str_2_Loc;
437         int             Run_Index;
438         int             Number_Of_Runs;
439 
440 /+
441         FILE            *Ap;
442 
443   /* Initializations */
444 
445   if ((Ap = fopen("dhry.res","a+")) == null)
446     {
447        printf("Can not open dhry.res\n\n");
448        exit(1);
449     }
450 +/
451 
452   Next_Ptr_Glob = cast(Rec_Pointer) malloc (Rec_Type.sizeof);
453   Ptr_Glob = cast(Rec_Pointer) malloc (Rec_Type.sizeof);
454 
455   Ptr_Glob.Ptr_Comp                    = Next_Ptr_Glob;
456   Ptr_Glob.Discr                       = Ident_1;
457   Ptr_Glob.variant.var_1.Enum_Comp     = Ident_3;
458   Ptr_Glob.variant.var_1.Int_Comp      = 40;
459 //  strcpy (Ptr_Glob.variant.var_1.Str_Comp,
460 //          "DHRYSTONE PROGRAM, SOME STRING");
461 //  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
462   Ptr_Glob.variant.var_1.Str_Comp[] = "DHRYSTONE PROGRAM, SOME STRING";
463   Str_1_Loc[] = "DHRYSTONE PROGRAM, 1'ST STRING";
464 
465   Arr_2_Glob [8][7] = 10;
466         /* Was missing in published program. Without this statement,    */
467         /* Arr_2_Glob [8][7] would have an undefined value.             */
468         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
469         /* overflow may occur for this array element.                   */
470 
471   printf ("\n");
472   printf ("Dhrystone Benchmark, Version 2.1 (Language: D)\n");
473   printf ("\n");
474   printf ("Please give the number of runs through the benchmark: ");
475   {
476     int n;
477     //scanf ("%d", &n);
478     n = 10000000;
479     Number_Of_Runs = n;
480   }
481   printf ("\n");
482 
483   printf ("Execution starts, %d runs through Dhrystone\n",Number_Of_Runs);
484 
485   /***************/
486   /* Start timer */
487   /***************/
488 
489   Begin_Time = dtime();
490 
491   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
492   {
493 
494     Proc_5();
495     Proc_4();
496       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
497     Int_1_Loc = 2;
498     Int_2_Loc = 3;
499     //strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
500     Str_2_Loc[] = "DHRYSTONE PROGRAM, 2'ND STRING";
501     Enum_Loc = Ident_2;
502     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
503       /* Bool_Glob == 1 */
504     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
505     {
506       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
507         /* Int_3_Loc == 7 */
508       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
509         /* Int_3_Loc == 7 */
510       Int_1_Loc += 1;
511     } /* while */
512       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
513     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
514       /* Int_Glob == 5 */
515     Proc_1 (Ptr_Glob);
516     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
517                              /* loop body executed twice */
518     {
519       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
520           /* then, not executed */
521         {
522         Proc_6 (Ident_1, &Enum_Loc);
523         //strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
524         Str_2_Loc[] = "DHRYSTONE PROGRAM, 3'RD STRING";
525         Int_2_Loc = Run_Index;
526         Int_Glob = Run_Index;
527         }
528     }
529       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
530     Int_2_Loc = Int_2_Loc * Int_1_Loc;
531     Int_1_Loc = Int_2_Loc / Int_3_Loc;
532     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
533       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
534     Proc_2 (&Int_1_Loc);
535       /* Int_1_Loc == 5 */
536 
537   } /* loop "for Run_Index" */
538 
539   /**************/
540   /* Stop timer */
541   /**************/
542 
543   End_Time = dtime();
544 
545   printf ("Execution ends\n");
546   printf ("\n");
547   printf ("Final values of the variables used in the benchmark:\n");
548   printf ("\n");
549   printf ("Int_Glob:            %d\n", Int_Glob);
550   printf ("        should be:   %d\n", 5);
551   printf ("Bool_Glob:           %d\n", Bool_Glob);
552   printf ("        should be:   %d\n", 1);
553   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
554   printf ("        should be:   %c\n", cast(int)'A');
555   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
556   printf ("        should be:   %c\n", cast(int)'B');
557   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
558   printf ("        should be:   %d\n", 7);
559   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
560   printf ("        should be:   Number_Of_Runs + 10\n");
561   printf ("Ptr_Glob.\n");
562   printf ("  Ptr_Comp:          %d\n", cast(int) Ptr_Glob.Ptr_Comp);
563   printf ("        should be:   (implementation-dependent)\n");
564   printf ("  Discr:             %d\n", Ptr_Glob.Discr);
565   printf ("        should be:   %d\n", 0);
566   printf ("  Enum_Comp:         %d\n", Ptr_Glob.variant.var_1.Enum_Comp);
567   printf ("        should be:   %d\n", 2);
568   printf ("  Int_Comp:          %d\n", Ptr_Glob.variant.var_1.Int_Comp);
569   printf ("        should be:   %d\n", 17);
570   printf ("  Str_Comp:          %.*s\n", Ptr_Glob.variant.var_1.Str_Comp.length, Ptr_Glob.variant.var_1.Str_Comp.ptr);
571   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
572   printf ("Next_Ptr_Glob.\n");
573   printf ("  Ptr_Comp:          %d\n", cast(int) Next_Ptr_Glob.Ptr_Comp);
574   printf ("        should be:   (implementation-dependent), same as above\n");
575   printf ("  Discr:             %d\n", Next_Ptr_Glob.Discr);
576   printf ("        should be:   %d\n", 0);
577   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob.variant.var_1.Enum_Comp);
578   printf ("        should be:   %d\n", 1);
579   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob.variant.var_1.Int_Comp);
580   printf ("        should be:   %d\n", 18);
581   printf ("  Str_Comp:          %.*s\n", Next_Ptr_Glob.variant.var_1.Str_Comp.length, Next_Ptr_Glob.variant.var_1.Str_Comp.ptr);
582   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
583   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
584   printf ("        should be:   %d\n", 5);
585   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
586   printf ("        should be:   %d\n", 13);
587   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
588   printf ("        should be:   %d\n", 7);
589   printf ("Enum_Loc:            %d\n", Enum_Loc);
590   printf ("        should be:   %d\n", 1);
591   printf ("Str_1_Loc:           %.*s\n", Str_1_Loc.length, Str_1_Loc.ptr);
592   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
593   printf ("Str_2_Loc:           %.*s\n", Str_2_Loc.length, Str_2_Loc.ptr);
594   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
595   printf ("\n");
596 
597   User_Time = End_Time - Begin_Time;
598 
599   if (User_Time < Too_Small_Time)
600   {
601     printf ("Measured time too small to obtain meaningful results\n");
602     printf ("Please increase number of runs\n");
603     printf ("\n");
604   }
605   else
606   {
607     Microseconds = User_Time * Mic_secs_Per_Second
608                         / cast(double) Number_Of_Runs;
609     Dhrystones_Per_Second = cast(double) Number_Of_Runs / User_Time;
610     Vax_Mips = Dhrystones_Per_Second / 1757.0;
611 
612     printf ("Register option selected?  NO\n");
613     strcpy(Reg_Define.ptr, "Register option not selected.");
614     printf ("Microseconds for one run through Dhrystone: ");
615     printf ("%7.1lf \n", Microseconds);
616     printf ("Dhrystones per Second:                      ");
617     printf ("%10.1lf \n", Dhrystones_Per_Second);
618     printf ("VAX MIPS rating = %10.3lf \n",Vax_Mips);
619     printf ("\n");
620 
621    /+
622   fprintf(Ap,"\n");
623   fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: D)\n");
624   fprintf(Ap,"%.*s\n",Reg_Define.length, Reg_Define.ptr);
625   fprintf(Ap,"Microseconds for one loop: %7.1lf\n",Microseconds);
626   fprintf(Ap,"Dhrystones per second: %10.1lf\n",Dhrystones_Per_Second);
627   fprintf(Ap,"VAX MIPS rating: %10.3lf\n",Vax_Mips);
628   fclose(Ap);
629   +/
630 
631   }
632 
633 }
634 
Proc_1(Rec_Pointer Ptr_Val_Par)635 void Proc_1 (Rec_Pointer Ptr_Val_Par)
636 /******************/
637 
638     /* executed once */
639 {
640       Rec_Pointer Next_Record = Ptr_Val_Par.Ptr_Comp;
641                                         /* == Ptr_Glob_Next */
642   /* Local variable, initialized with Ptr_Val_Par.Ptr_Comp,    */
643   /* corresponds to "rename" in Ada, "with" in Pascal           */
644 
645   *Ptr_Val_Par.Ptr_Comp = *Ptr_Glob;
646   Ptr_Val_Par.variant.var_1.Int_Comp = 5;
647   Next_Record.variant.var_1.Int_Comp
648         = Ptr_Val_Par.variant.var_1.Int_Comp;
649   Next_Record.Ptr_Comp = Ptr_Val_Par.Ptr_Comp;
650   Proc_3 (&Next_Record.Ptr_Comp);
651     /* Ptr_Val_Par.Ptr_Comp.Ptr_Comp
652                         == Ptr_Glob.Ptr_Comp */
653   if (Next_Record.Discr == Ident_1)
654     /* then, executed */
655   {
656     Next_Record.variant.var_1.Int_Comp = 6;
657     Proc_6 (Ptr_Val_Par.variant.var_1.Enum_Comp,
658            &Next_Record.variant.var_1.Enum_Comp);
659     Next_Record.Ptr_Comp = Ptr_Glob.Ptr_Comp;
660     Proc_7 (Next_Record.variant.var_1.Int_Comp, 10,
661            &Next_Record.variant.var_1.Int_Comp);
662   }
663   else /* not executed */
664     *Ptr_Val_Par = *Ptr_Val_Par.Ptr_Comp;
665 } /* Proc_1 */
666 
Proc_2(One_Fifty * Int_Par_Ref)667 void Proc_2 (One_Fifty *Int_Par_Ref)
668 /******************/
669     /* executed once */
670     /* *Int_Par_Ref == 1, becomes 4 */
671 {
672   One_Fifty  Int_Loc;
673   Enumeration   Enum_Loc;
674 
675   Int_Loc = *Int_Par_Ref + 10;
676   do /* executed once */
677     if (Ch_1_Glob == 'A')
678       /* then, executed */
679     {
680       Int_Loc -= 1;
681       *Int_Par_Ref = Int_Loc - Int_Glob;
682       Enum_Loc = Ident_1;
683     } /* if */
684   while (Enum_Loc != Ident_1); /* true */
685 } /* Proc_2 */
686 
687 
Proc_3(Rec_Pointer * Ptr_Ref_Par)688 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
689 /******************/
690     /* executed once */
691     /* Ptr_Ref_Par becomes Ptr_Glob */
692 
693 {
694   if (Ptr_Glob !=    null)
695     /* then, executed */
696     *Ptr_Ref_Par = Ptr_Glob.Ptr_Comp;
697   Proc_7 (10, Int_Glob, &Ptr_Glob.variant.var_1.Int_Comp);
698 } /* Proc_3 */
699 
Proc_4()700 void Proc_4 () /* without parameters */
701 /*******/
702     /* executed once */
703 {
704   Boolean Bool_Loc;
705 
706   Bool_Loc = Ch_1_Glob == 'A';
707   Bool_Glob = Bool_Loc | Bool_Glob;
708   Ch_2_Glob = 'B';
709 } /* Proc_4 */
710 
711 
Proc_5()712 void Proc_5 () /* without parameters */
713 /*******/
714     /* executed once */
715 {
716   Ch_1_Glob = 'A';
717   Bool_Glob = false;
718 } /* Proc_5 */
719 
720 
Proc_6(Enumeration Enum_Val_Par,Enumeration * Enum_Ref_Par)721 void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
722 /*********************************/
723     /* executed once */
724     /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
725 {
726   *Enum_Ref_Par = Enum_Val_Par;
727   if (! Func_3 (Enum_Val_Par))
728     /* then, not executed */
729     *Enum_Ref_Par = Ident_4;
730   final switch (Enum_Val_Par)
731   {
732     case Ident_1:
733       *Enum_Ref_Par = Ident_1;
734       break;
735     case Ident_2:
736       if (Int_Glob > 100)
737         /* then */
738       *Enum_Ref_Par = Ident_1;
739       else *Enum_Ref_Par = Ident_4;
740       break;
741     case Ident_3: /* executed */
742       *Enum_Ref_Par = Ident_2;
743       break;
744     case Ident_4: break;
745     case Ident_5:
746       *Enum_Ref_Par = Ident_3;
747       break;
748   } /* switch */
749 } /* Proc_6 */
750 
751 
Proc_7(One_Fifty Int_1_Par_Val,One_Fifty Int_2_Par_Val,One_Fifty * Int_Par_Ref)752 void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref)
753 /**********************************************/
754     /* executed three times                                      */
755     /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
756     /*                  Int_Par_Ref becomes 7                    */
757     /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
758     /*                  Int_Par_Ref becomes 17                   */
759     /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
760     /*                  Int_Par_Ref becomes 18                   */
761 {
762   One_Fifty Int_Loc;
763 
764   Int_Loc = Int_1_Par_Val + 2;
765   *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
766 } /* Proc_7 */
767 
768 
Proc_8(ref Arr_1_Dim Arr_1_Par_Ref,ref Arr_2_Dim Arr_2_Par_Ref,int Int_1_Par_Val,int Int_2_Par_Val)769 void Proc_8 (ref Arr_1_Dim Arr_1_Par_Ref, ref Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val)
770 /*********************************************************************/
771     /* executed once      */
772     /* Int_Par_Val_1 == 3 */
773     /* Int_Par_Val_2 == 7 */
774 {
775       One_Fifty Int_Index;
776       One_Fifty Int_Loc;
777 
778   Int_Loc = Int_1_Par_Val + 5;
779   Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
780   Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
781   Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
782   for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
783     Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
784   Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
785   Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
786   Int_Glob = 5;
787 } /* Proc_8 */
788 
789 
Func_1(Capital_Letter Ch_1_Par_Val,Capital_Letter Ch_2_Par_Val)790 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val)
791 /*************************************************/
792     /* executed three times                                         */
793     /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
794     /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
795     /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
796 {
797   Capital_Letter        Ch_1_Loc;
798   Capital_Letter        Ch_2_Loc;
799 
800   Ch_1_Loc = Ch_1_Par_Val;
801   Ch_2_Loc = Ch_1_Loc;
802   if (Ch_2_Loc != Ch_2_Par_Val)
803     /* then, executed */
804     return (Ident_1);
805   else  /* not executed */
806   {
807     Ch_1_Glob = Ch_1_Loc;
808     return (Ident_2);
809    }
810 } /* Func_1 */
811 
812 
Func_2(Str_30 Str_1_Par_Ref,Str_30 Str_2_Par_Ref)813 Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref)
814 /*************************************************/
815     /* executed once */
816     /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
817     /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
818 {
819       One_Thirty        Int_Loc;
820       Capital_Letter    Ch_Loc;
821 
822   Int_Loc = 2;
823   while (Int_Loc <= 2) /* loop body executed once */
824     if (Func_1 (Str_1_Par_Ref[Int_Loc],
825                 Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
826       /* then, executed */
827     {
828       Ch_Loc = 'A';
829       Int_Loc += 1;
830     } /* if, while */
831   if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
832     /* then, not executed */
833     Int_Loc = 7;
834   if (Ch_Loc == 'R')
835     /* then, not executed */
836     return (true);
837   else /* executed */
838   {
839     //if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
840     //if (memcmp (Str_1_Par_Ref, Str_2_Par_Ref, 30) > 0)
841     if (Str_1_Par_Ref > Str_2_Par_Ref)
842       /* then, not executed */
843     {
844       Int_Loc += 7;
845       Int_Glob = Int_Loc;
846       return (true);
847     }
848     else /* executed */
849       return (false);
850   } /* if Ch_Loc */
851 } /* Func_2 */
852 
853 
Func_3(Enumeration Enum_Par_Val)854 Boolean Func_3 (Enumeration Enum_Par_Val)
855 /***************************/
856     /* executed once        */
857     /* Enum_Par_Val == Ident_3 */
858 {
859   Enumeration Enum_Loc;
860 
861   Enum_Loc = Enum_Par_Val;
862   if (Enum_Loc == Ident_3)
863     /* then, executed */
864     return (true);
865   else /* not executed */
866     return (false);
867 } /* Func_3 */
868 
version(Windows)869 version (Windows)
870 {
871     import core.sys.windows.windows;
872 
873     double dtime()
874     {
875      double q;
876 
877      q = cast(double)GetTickCount() * 1.0e-03;
878 
879      return q;
880     }
881 }
882 
version(linux)883 version (linux)
884 {
885     import core.stdc.time;
886 
887     double dtime()
888     {
889      double q;
890 
891      q = cast(double)time(null);
892 
893      return q;
894     }
895 }
896 
version(OSX)897 version (OSX)   // supplied by Anders F Bjorklund
898 {
899     import core.sys.posix.sys.time;
900 
901     double dtime()
902     {
903      double q;
904      timeval tv;
905 
906      gettimeofday(&tv,null);
907      q = cast(double)tv.tv_sec + cast(double)tv.tv_usec * 1.0e-6;
908 
909      return q;
910     }
911 }
912 
version(NetBSD)913 version (NetBSD)
914 {
915     import core.sys.posix.sys.time;
916 
917     double dtime()
918     {
919      double q;
920      timeval tv;
921 
922      gettimeofday(&tv,null);
923      q = cast(double)tv.tv_sec + cast(double)tv.tv_usec * 1.0e-6;
924 
925      return q;
926     }
927 }
928