xref: /openbmc/linux/lib/dhry.h (revision 83794367)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /*
3  ****************************************************************************
4  *
5  *                   "DHRYSTONE" Benchmark Program
6  *                   -----------------------------
7  *
8  *  Version:    C, Version 2.1
9  *
10  *  File:       dhry.h (part 1 of 3)
11  *
12  *  Date:       May 25, 1988
13  *
14  *  Author:     Reinhold P. Weicker
15  *                      Siemens AG, AUT E 51
16  *                      Postfach 3220
17  *                      8520 Erlangen
18  *                      Germany (West)
19  *                              Phone:  [+49]-9131-7-20330
20  *                                      (8-17 Central European Time)
21  *                              Usenet: ..!mcsun!unido!estevax!weicker
22  *
23  *              Original Version (in Ada) published in
24  *              "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
25  *              pp. 1013 - 1030, together with the statistics
26  *              on which the distribution of statements etc. is based.
27  *
28  *              In this C version, the following C library functions are used:
29  *              - strcpy, strcmp (inside the measurement loop)
30  *              - printf, scanf (outside the measurement loop)
31  *              In addition, Berkeley UNIX system calls "times ()" or "time ()"
32  *              are used for execution time measurement. For measurements
33  *              on other systems, these calls have to be changed.
34  *
35  *  Collection of Results:
36  *              Reinhold Weicker (address see above) and
37  *
38  *              Rick Richardson
39  *              PC Research. Inc.
40  *              94 Apple Orchard Drive
41  *              Tinton Falls, NJ 07724
42  *                      Phone:  (201) 389-8963 (9-17 EST)
43  *                      Usenet: ...!uunet!pcrat!rick
44  *
45  *      Please send results to Rick Richardson and/or Reinhold Weicker.
46  *      Complete information should be given on hardware and software used.
47  *      Hardware information includes: Machine type, CPU, type and size
48  *      of caches; for microprocessors: clock frequency, memory speed
49  *      (number of wait states).
50  *      Software information includes: Compiler (and runtime library)
51  *      manufacturer and version, compilation switches, OS version.
52  *      The Operating System version may give an indication about the
53  *      compiler; Dhrystone itself performs no OS calls in the measurement loop.
54  *
55  *      The complete output generated by the program should be mailed
56  *      such that at least some checks for correctness can be made.
57  *
58  ***************************************************************************
59  *
60  *  History:    This version C/2.1 has been made for two reasons:
61  *
62  *              1) There is an obvious need for a common C version of
63  *              Dhrystone, since C is at present the most popular system
64  *              programming language for the class of processors
65  *              (microcomputers, minicomputers) where Dhrystone is used most.
66  *              There should be, as far as possible, only one C version of
67  *              Dhrystone such that results can be compared without
68  *              restrictions. In the past, the C versions distributed
69  *              by Rick Richardson (Version 1.1) and by Reinhold Weicker
70  *              had small (though not significant) differences.
71  *
72  *              2) As far as it is possible without changes to the Dhrystone
73  *              statistics, optimizing compilers should be prevented from
74  *              removing significant statements.
75  *
76  *              This C version has been developed in cooperation with
77  *              Rick Richardson (Tinton Falls, NJ), it incorporates many
78  *              ideas from the "Version 1.1" distributed previously by
79  *              him over the UNIX network Usenet.
80  *              I also thank Chaim Benedelac (National Semiconductor),
81  *              David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
82  *              Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
83  *              for their help with comments on earlier versions of the
84  *              benchmark.
85  *
86  *  Changes:    In the initialization part, this version follows mostly
87  *              Rick Richardson's version distributed via Usenet, not the
88  *              version distributed earlier via floppy disk by Reinhold Weicker.
89  *              As a concession to older compilers, names have been made
90  *              unique within the first 8 characters.
91  *              Inside the measurement loop, this version follows the
92  *              version previously distributed by Reinhold Weicker.
93  *
94  *              At several places in the benchmark, code has been added,
95  *              but within the measurement loop only in branches that
96  *              are not executed. The intention is that optimizing compilers
97  *              should be prevented from moving code out of the measurement
98  *              loop, or from removing code altogether. Since the statements
99  *              that are executed within the measurement loop have NOT been
100  *              changed, the numbers defining the "Dhrystone distribution"
101  *              (distribution of statements, operand types and locality)
102  *              still hold. Except for sophisticated optimizing compilers,
103  *              execution times for this version should be the same as
104  *              for previous versions.
105  *
106  *              Since it has proven difficult to subtract the time for the
107  *              measurement loop overhead in a correct way, the loop check
108  *              has been made a part of the benchmark. This does have
109  *              an impact - though a very minor one - on the distribution
110  *              statistics which have been updated for this version.
111  *
112  *              All changes within the measurement loop are described
113  *              and discussed in the companion paper "Rationale for
114  *              Dhrystone version 2".
115  *
116  *              Because of the self-imposed limitation that the order and
117  *              distribution of the executed statements should not be
118  *              changed, there are still cases where optimizing compilers
119  *              may not generate code for some statements. To a certain
120  *              degree, this is unavoidable for small synthetic benchmarks.
121  *              Users of the benchmark are advised to check code listings
122  *              whether code is generated for all statements of Dhrystone.
123  *
124  *              Version 2.1 is identical to version 2.0 distributed via
125  *              the UNIX network Usenet in March 1988 except that it corrects
126  *              some minor deficiencies that were found by users of version 2.0.
127  *              The only change within the measurement loop is that a
128  *              non-executed "else" part was added to the "if" statement in
129  *              Func_3, and a non-executed "else" part removed from Proc_3.
130  *
131  ***************************************************************************
132  *
133  *  Compilation model and measurement (IMPORTANT):
134  *
135  *  This C version of Dhrystone consists of three files:
136  *  - dhry.h (this file, containing global definitions and comments)
137  *  - dhry_1.c (containing the code corresponding to Ada package Pack_1)
138  *  - dhry_2.c (containing the code corresponding to Ada package Pack_2)
139  *
140  *  The following "ground rules" apply for measurements:
141  *  - Separate compilation
142  *  - No procedure merging
143  *  - Otherwise, compiler optimizations are allowed but should be indicated
144  *  - Default results are those without register declarations
145  *  See the companion paper "Rationale for Dhrystone Version 2" for a more
146  *  detailed discussion of these ground rules.
147  *
148  *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
149  *  models ("small", "medium", "large" etc.) should be given if possible,
150  *  together with a definition of these models for the compiler system used.
151  *
152  **************************************************************************
153  *
154  *  Dhrystone (C version) statistics:
155  *
156  *  [Comment from the first distribution, updated for version 2.
157  *   Note that because of language differences, the numbers are slightly
158  *   different from the Ada version.]
159  *
160  *  The following program contains statements of a high level programming
161  *  language (here: C) in a distribution considered representative:
162  *
163  *    assignments                  52 (51.0 %)
164  *    control statements           33 (32.4 %)
165  *    procedure, function calls    17 (16.7 %)
166  *
167  *  103 statements are dynamically executed. The program is balanced with
168  *  respect to the three aspects:
169  *
170  *    - statement type
171  *    - operand type
172  *    - operand locality
173  *         operand global, local, parameter, or constant.
174  *
175  *  The combination of these three aspects is balanced only approximately.
176  *
177  *  1. Statement Type:
178  *  -----------------             number
179  *
180  *     V1 = V2                     9
181  *       (incl. V1 = F(..)
182  *     V = Constant               12
183  *     Assignment,                 7
184  *       with array element
185  *     Assignment,                 6
186  *       with record component
187  *                                --
188  *                                34       34
189  *
190  *     X = Y +|-|"&&"|"|" Z        5
191  *     X = Y +|-|"==" Constant     6
192  *     X = X +|- 1                 3
193  *     X = Y *|/ Z                 2
194  *     X = Expression,             1
195  *           two operators
196  *     X = Expression,             1
197  *           three operators
198  *                                --
199  *                                18       18
200  *
201  *     if ....                    14
202  *       with "else"      7
203  *       without "else"   7
204  *           executed        3
205  *           not executed    4
206  *     for ...                     7  |  counted every time
207  *     while ...                   4  |  the loop condition
208  *     do ... while                1  |  is evaluated
209  *     switch ...                  1
210  *     break                       1
211  *     declaration with            1
212  *       initialization
213  *                                --
214  *                                34       34
215  *
216  *     P (...)  procedure call    11
217  *       user procedure      10
218  *       library procedure    1
219  *     X = F (...)
220  *             function  call      6
221  *       user function        5
222  *       library function     1
223  *                                --
224  *                                17       17
225  *                                        ---
226  *                                        103
227  *
228  *    The average number of parameters in procedure or function calls
229  *    is 1.82 (not counting the function values as implicit parameters).
230  *
231  *
232  *  2. Operators
233  *  ------------
234  *                          number    approximate
235  *                                    percentage
236  *
237  *    Arithmetic             32          50.8
238  *
239  *       +                     21          33.3
240  *       -                      7          11.1
241  *       *                      3           4.8
242  *       / (int div)            1           1.6
243  *
244  *    Comparison             27           42.8
245  *
246  *       ==                     9           14.3
247  *       /=                     4            6.3
248  *       >                      1            1.6
249  *       <                      3            4.8
250  *       >=                     1            1.6
251  *       <=                     9           14.3
252  *
253  *    Logic                   4            6.3
254  *
255  *       && (AND-THEN)          1            1.6
256  *       |  (OR)                1            1.6
257  *       !  (NOT)               2            3.2
258  *
259  *                           --          -----
260  *                           63          100.1
261  *
262  *
263  *  3. Operand Type (counted once per operand reference):
264  *  ---------------
265  *                          number    approximate
266  *                                    percentage
267  *
268  *     Integer               175        72.3 %
269  *     Character              45        18.6 %
270  *     Pointer                12         5.0 %
271  *     String30                6         2.5 %
272  *     Array                   2         0.8 %
273  *     Record                  2         0.8 %
274  *                           ---       -------
275  *                           242       100.0 %
276  *
277  *  When there is an access path leading to the final operand (e.g. a record
278  *  component), only the final data type on the access path is counted.
279  *
280  *
281  *  4. Operand Locality:
282  *  -------------------
283  *                                number    approximate
284  *                                          percentage
285  *
286  *     local variable              114        47.1 %
287  *     global variable              22         9.1 %
288  *     parameter                    45        18.6 %
289  *        value                        23         9.5 %
290  *        reference                    22         9.1 %
291  *     function result               6         2.5 %
292  *     constant                     55        22.7 %
293  *                                 ---       -------
294  *                                 242       100.0 %
295  *
296  *
297  *  The program does not compute anything meaningful, but it is syntactically
298  *  and semantically correct. All variables have a value assigned to them
299  *  before they are used as a source operand.
300  *
301  *  There has been no explicit effort to account for the effects of a
302  *  cache, or to balance the use of long or short displacements for code or
303  *  data.
304  *
305  ***************************************************************************
306  */
307 
308 typedef enum {
309 	Ident_1,
310 	Ident_2,
311 	Ident_3,
312 	Ident_4,
313 	Ident_5
314 } Enumeration;	/* for boolean and enumeration types in Ada, Pascal */
315 
316 /* General definitions: */
317 
318 typedef int One_Thirty;
319 typedef int One_Fifty;
320 typedef char Capital_Letter;
321 typedef int Boolean;
322 typedef char Str_30[31];
323 typedef int Arr_1_Dim[50];
324 typedef int Arr_2_Dim[50][50];
325 
326 typedef struct record {
327 	struct record *Ptr_Comp;
328 	Enumeration    Discr;
329 	union {
330 		struct {
331 			Enumeration Enum_Comp;
332 			int Int_Comp;
333 			char Str_Comp[31];
334 		} var_1;
335 		struct {
336 			Enumeration E_Comp_2;
337 			char Str_2_Comp[31];
338 		} var_2;
339 		struct {
340 			char Ch_1_Comp;
341 			char Ch_2_Comp;
342 		} var_3;
343 	} variant;
344 } Rec_Type, *Rec_Pointer;
345 
346 
347 extern int Int_Glob;
348 extern char Ch_1_Glob;
349 
350 void Proc_6(Enumeration  Enum_Val_Par, Enumeration *Enum_Ref_Par);
351 void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
352 	    One_Fifty *Int_Par_Ref);
353 void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
354 	    int Int_1_Par_Val, int Int_2_Par_Val);
355 Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
356 Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
357 
358 int dhry(int n);
359