1 /*****************************************************************************
2  *  The BYTE UNIX Benchmarks - Release 3
3  *          Module: dhry.h   SID: 3.4 5/15/91 19:30:21
4  *
5  *****************************************************************************
6  * Bug reports, patches, comments, suggestions should be sent to:
7  *
8  *	Ben Smith, Rick Grehan or Tom Yager
9  *	ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
10  *
11  *****************************************************************************
12  *  Modification Log:
13  *  addapted from:
14  *
15  *
16  *                   "DHRYSTONE" Benchmark Program
17  *                   -----------------------------
18  *
19  *  Version:    C, Version 2.1
20  *
21  *  File:       dhry.h (part 1 of 3)
22  *
23  *  Date:       May 25, 1988
24  *
25  *  Author:     Reinhold P. Weicker
26  *                      Siemens AG, AUT E 51
27  *                      Postfach 3220
28  *                      8520 Erlangen
29  *                      Germany (West)
30  *                              Phone:  [+49]-9131-7-20330
31  *                                      (8-17 Central European Time)
32  *                              Usenet: ..!mcvax!unido!estevax!weicker
33  *
34  *              Original Version (in Ada) published in
35  *              "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
36  *              pp. 1013 - 1030, together with the statistics
37  *              on which the distribution of statements etc. is based.
38  *
39  *              In this C version, the following C library functions are used:
40  *              - strcpy, strcmp (inside the measurement loop)
41  *              - printf, scanf (outside the measurement loop)
42  *              In addition, Berkeley UNIX system calls "times ()" or "time ()"
43  *              are used for execution time measurement. For measurements
44  *              on other systems, these calls have to be changed.
45  *
46  *  Collection of Results:
47  *              Reinhold Weicker (address see above) and
48  *
49  *              Rick Richardson
50  *              PC Research. Inc.
51  *              94 Apple Orchard Drive
52  *              Tinton Falls, NJ 07724
53  *                      Phone:  (201) 834-1378 (9-17 EST)
54  *                      Usenet: ...!seismo!uunet!pcrat!rick
55  *
56  *      Please send results to Rick Richardson and/or Reinhold Weicker.
57  *      Complete information should be given on hardware and software used.
58  *      Hardware information includes: Machine type, CPU, type and size
59  *      of caches; for microprocessors: clock frequency, memory speed
60  *      (number of wait states).
61  *      Software information includes: Compiler (and runtime library)
62  *      manufacturer and version, compilation switches, OS version.
63  *      The Operating System version may give an indication about the
64  *      compiler; Dhrystone itself performs no OS calls in the measurement loop.
65  *
66  *      The complete output generated by the program should be mailed
67  *      such that at least some checks for correctness can be made.
68  *
69  ***************************************************************************
70  *
71  *  History:    This version C/2.1 has been made for two reasons:
72  *
73  *              1) There is an obvious need for a common C version of
74  *              Dhrystone, since C is at present the most popular system
75  *              programming language for the class of processors
76  *              (microcomputers, minicomputers) where Dhrystone is used most.
77  *              There should be, as far as possible, only one C version of
78  *              Dhrystone such that results can be compared without
79  *              restrictions. In the past, the C versions distributed
80  *              by Rick Richardson (Version 1.1) and by Reinhold Weicker
81  *              had small (though not significant) differences.
82  *
83  *              2) As far as it is possible without changes to the Dhrystone
84  *              statistics, optimizing compilers should be prevented from
85  *              removing significant statements.
86  *
87  *              This C version has been developed in cooperation with
88  *              Rick Richardson (Tinton Falls, NJ), it incorporates many
89  *              ideas from the "Version 1.1" distributed previously by
90  *              him over the UNIX network Usenet.
91  *              I also thank Chaim Benedelac (National Semiconductor),
92  *              David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
93  *              Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
94  *              for their help with comments on earlier versions of the
95  *              benchmark.
96  *
97  *  Changes:    In the initialization part, this version follows mostly
98  *              Rick Richardson's version distributed via Usenet, not the
99  *              version distributed earlier via floppy disk by Reinhold Weicker.
100  *              As a concession to older compilers, names have been made
101  *              unique within the first 8 characters.
102  *              Inside the measurement loop, this version follows the
103  *              version previously distributed by Reinhold Weicker.
104  *
105  *              At several places in the benchmark, code has been added,
106  *              but within the measurement loop only in branches that
107  *              are not executed. The intention is that optimizing compilers
108  *              should be prevented from moving code out of the measurement
109  *              loop, or from removing code altogether. Since the statements
110  *              that are executed within the measurement loop have NOT been
111  *              changed, the numbers defining the "Dhrystone distribution"
112  *              (distribution of statements, operand types and locality)
113  *              still hold. Except for sophisticated optimizing compilers,
114  *              execution times for this version should be the same as
115  *              for previous versions.
116  *
117  *              Since it has proven difficult to subtract the time for the
118  *              measurement loop overhead in a correct way, the loop check
119  *              has been made a part of the benchmark. This does have
120  *              an impact - though a very minor one - on the distribution
121  *              statistics which have been updated for this version.
122  *
123  *              All changes within the measurement loop are described
124  *              and discussed in the companion paper "Rationale for
125  *              Dhrystone version 2".
126  *
127  *              Because of the self-imposed limitation that the order and
128  *              distribution of the executed statements should not be
129  *              changed, there are still cases where optimizing compilers
130  *              may not generate code for some statements. To a certain
131  *              degree, this is unavoidable for small synthetic benchmarks.
132  *              Users of the benchmark are advised to check code listings
133  *              whether code is generated for all statements of Dhrystone.
134  *
135  *              Version 2.1 is identical to version 2.0 distributed via
136  *              the UNIX network Usenet in March 1988 except that it corrects
137  *              some minor deficiencies that were found by users of version 2.0.
138  *              The only change within the measurement loop is that a
139  *              non-executed "else" part was added to the "if" statement in
140  *              Func_3, and a non-executed "else" part removed from Proc_3.
141  *
142  ***************************************************************************
143  *
144  * Defines:     The following "Defines" are possible:
145  *              -DREG=register          (default: Not defined)
146  *                      As an approximation to what an average C programmer
147  *                      might do, the "register" storage class is applied
148  *                      (if enabled by -DREG=register)
149  *                      - for local variables, if they are used (dynamically)
150  *                        five or more times
151  *                      - for parameters if they are used (dynamically)
152  *                        six or more times
153  *                      Note that an optimal "register" strategy is
154  *                      compiler-dependent, and that "register" declarations
155  *                      do not necessarily lead to faster execution.
156  *              -DNOSTRUCTASSIGN        (default: Not defined)
157  *                      Define if the C compiler does not support
158  *                      assignment of structures.
159  *              -DNOENUMS               (default: Not defined)
160  *                      Define if the C compiler does not support
161  *                      enumeration types.
162  *              -DTIMES                 (default)
163  *              -DTIME
164  *                      The "times" function of UNIX (returning process times)
165  *                      or the "time" function (returning wallclock time)
166  *                      is used for measurement.
167  *                      For single user machines, "time ()" is adequate. For
168  *                      multi-user machines where you cannot get single-user
169  *                      access, use the "times ()" function. If you have
170  *                      neither, use a stopwatch in the dead of night.
171  *                      "printf"s are provided marking the points "Start Timer"
172  *                      and "Stop Timer". DO NOT use the UNIX "time(1)"
173  *                      command, as this will measure the total time to
174  *                      run this program, which will (erroneously) include
175  *                      the time to allocate storage (malloc) and to perform
176  *                      the initialization.
177  *              -DHZ=nnn
178  *                      In Berkeley UNIX, the function "times" returns process
179  *                      time in 1/HZ seconds, with HZ = 60 for most systems.
180  *                      CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
181  *                      A VALUE.
182  *
183  ***************************************************************************
184  *
185  *  Compilation model and measurement (IMPORTANT):
186  *
187  *  This C version of Dhrystone consists of three files:
188  *  - dhry.h (this file, containing global definitions and comments)
189  *  - dhry_1.c (containing the code corresponding to Ada package Pack_1)
190  *  - dhry_2.c (containing the code corresponding to Ada package Pack_2)
191  *
192  *  The following "ground rules" apply for measurements:
193  *  - Separate compilation
194  *  - No procedure merging
195  *  - Otherwise, compiler optimizations are allowed but should be indicated
196  *  - Default results are those without register declarations
197  *  See the companion paper "Rationale for Dhrystone Version 2" for a more
198  *  detailed discussion of these ground rules.
199  *
200  *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
201  *  models ("small", "medium", "large" etc.) should be given if possible,
202  *  together with a definition of these models for the compiler system used.
203  *
204  **************************************************************************
205  *
206  *  Dhrystone (C version) statistics:
207  *
208  *  [Comment from the first distribution, updated for version 2.
209  *   Note that because of language differences, the numbers are slightly
210  *   different from the Ada version.]
211  *
212  *  The following program contains statements of a high level programming
213  *  language (here: C) in a distribution considered representative:
214  *
215  *    assignments                  52 (51.0 %)
216  *    control statements           33 (32.4 %)
217  *    procedure, function calls    17 (16.7 %)
218  *
219  *  103 statements are dynamically executed. The program is balanced with
220  *  respect to the three aspects:
221  *
222  *    - statement type
223  *    - operand type
224  *    - operand locality
225  *         operand global, local, parameter, or constant.
226  *
227  *  The combination of these three aspects is balanced only approximately.
228  *
229  *  1. Statement Type:
230  *  -----------------             number
231  *
232  *     V1 = V2                     9
233  *       (incl. V1 = F(..)
234  *     V = Constant               12
235  *     Assignment,                 7
236  *       with array element
237  *     Assignment,                 6
238  *       with record component
239  *                                --
240  *                                34       34
241  *
242  *     X = Y +|-|"&&"|"|" Z        5
243  *     X = Y +|-|"==" Constant     6
244  *     X = X +|- 1                 3
245  *     X = Y *|/ Z                 2
246  *     X = Expression,             1
247  *           two operators
248  *     X = Expression,             1
249  *           three operators
250  *                                --
251  *                                18       18
252  *
253  *     if ....                    14
254  *       with "else"      7
255  *       without "else"   7
256  *           executed        3
257  *           not executed    4
258  *     for ...                     7  |  counted every time
259  *     while ...                   4  |  the loop condition
260  *     do ... while                1  |  is evaluated
261  *     switch ...                  1
262  *     break                       1
263  *     declaration with            1
264  *       initialization
265  *                                --
266  *                                34       34
267  *
268  *     P (...)  procedure call    11
269  *       user procedure      10
270  *       library procedure    1
271  *     X = F (...)
272  *             function  call      6
273  *       user function        5
274  *       library function     1
275  *                                --
276  *                                17       17
277  *                                        ---
278  *                                        103
279  *
280  *    The average number of parameters in procedure or function calls
281  *    is 1.82 (not counting the function values as implicit parameters).
282  *
283  *
284  *  2. Operators
285  *  ------------
286  *                          number    approximate
287  *                                    percentage
288  *
289  *    Arithmetic             32          50.8
290  *
291  *       +                     21          33.3
292  *       -                      7          11.1
293  *       *                      3           4.8
294  *       / (int div)            1           1.6
295  *
296  *    Comparison             27           42.8
297  *
298  *       ==                     9           14.3
299  *       /=                     4            6.3
300  *       >                      1            1.6
301  *       <                      3            4.8
302  *       >=                     1            1.6
303  *       <=                     9           14.3
304  *
305  *    Logic                   4            6.3
306  *
307  *       && (AND-THEN)          1            1.6
308  *       |  (OR)                1            1.6
309  *       !  (NOT)               2            3.2
310  *
311  *                           --          -----
312  *                           63          100.1
313  *
314  *
315  *  3. Operand Type (counted once per operand reference):
316  *  ---------------
317  *                          number    approximate
318  *                                    percentage
319  *
320  *     Integer               175        72.3 %
321  *     Character              45        18.6 %
322  *     Pointer                12         5.0 %
323  *     String30                6         2.5 %
324  *     Array                   2         0.8 %
325  *     Record                  2         0.8 %
326  *                           ---       -------
327  *                           242       100.0 %
328  *
329  *  When there is an access path leading to the final operand (e.g. a record
330  *  component), only the final data type on the access path is counted.
331  *
332  *
333  *  4. Operand Locality:
334  *  -------------------
335  *                                number    approximate
336  *                                          percentage
337  *
338  *     local variable              114        47.1 %
339  *     global variable              22         9.1 %
340  *     parameter                    45        18.6 %
341  *        value                        23         9.5 %
342  *        reference                    22         9.1 %
343  *     function result               6         2.5 %
344  *     constant                     55        22.7 %
345  *                                 ---       -------
346  *                                 242       100.0 %
347  *
348  *
349  *  The program does not compute anything meaningful, but it is syntactically
350  *  and semantically correct. All variables have a value assigned to them
351  *  before they are used as a source operand.
352  *
353  *  There has been no explicit effort to account for the effects of a
354  *  cache, or to balance the use of long or short displacements for code or
355  *  data.
356  *
357  ***************************************************************************
358  */
359 
360 
361 /* Compiler and system dependent definitions: */
362 
363 #ifndef TIME
364 #define TIMES
365 #endif
366                 /* Use times(2) time function unless    */
367                 /* explicitly defined otherwise         */
368 
369 #ifdef TIMES
370 #include <sys/types.h>
371 #include <sys/times.h>
372                 /* for "times" */
373 #endif
374 
375 #define Mic_secs_Per_Second     1000000.0
376                 /* Berkeley UNIX C returns process times in seconds/HZ */
377 
378 #ifdef  NOSTRUCTASSIGN
379 #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
380 #else
381 #define structassign(d, s)      d = s
382 #endif
383 
384 #ifdef  NOENUM
385 #define Ident_1 0
386 #define Ident_2 1
387 #define Ident_3 2
388 #define Ident_4 3
389 #define Ident_5 4
390   typedef int   Enumeration;
391 #else
392   typedef       enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
393                 Enumeration;
394 #endif
395         /* for boolean and enumeration types in Ada, Pascal */
396 
397 /* General definitions: */
398 
399 #include <stdio.h>
400                 /* for strcpy, strcmp */
401 
402 #define Null 0
403                 /* Value of a Null pointer */
404 #define true  1
405 #define false 0
406 
407 typedef int     One_Thirty;
408 typedef int     One_Fifty;
409 typedef char    Capital_Letter;
410 typedef int     Boolean;
411 typedef char    Str_30 [31];
412 typedef int     Arr_1_Dim [50];
413 typedef int     Arr_2_Dim [50] [50];
414 
415 typedef struct record
416     {
417     struct record *Ptr_Comp;
418     Enumeration    Discr;
419     union {
420           struct {
421                   Enumeration Enum_Comp;
422                   int         Int_Comp;
423                   char        Str_Comp [31];
424                   } var_1;
425           struct {
426                   Enumeration E_Comp_2;
427                   char        Str_2_Comp [31];
428                   } var_2;
429           struct {
430                   char        Ch_1_Comp;
431                   char        Ch_2_Comp;
432                   } var_3;
433           } variant;
434       } Rec_Type, *Rec_Pointer;
435 
436