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