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